I have created an array of objects using a class call Triangle. How can I translate each of these objects so that they all spin independently on their own axis? So far I have gotten them all to rotate correctly but the are all at x=0 and y=0. Everytime I try and translate they only spin around the origin.
Here is the code:
let triangles = [];
let angle = 0;
let speed = 0.001;
let x;
let y;
function setup() {
createCanvas(400, 400);
for (let i = 0; i < 10; i++) {
x = 0;
y = 0;
let s = random(20,50);
triangles[i] = new Triangle(x, y, s);
}
}
function draw() {
background(0);
for (let i = 0; i < triangles.length; i++) {
triangles[i].show();
triangles[i].move();
}
}
Rotation is pretty Messed up in processing…ok, technically it‘s how it should be, But it is annoying and someone should have added a simpler and direct method… like a transform method! Ok, now to how to fix your code. You have to translate the object before rotating it. If you want to rotate it around x=50, y=100, then do
This works in a pretty specific way, and i don‘t wanna say something wrong… It‘s like the Transformations are done in a newly created Layer and pop deleted the Layer, But the changes stay.