Hey everyone,
I am working on a project for university and there is one thing in p5js where I don't know how to do it.
I want to move two rectangles from the same place to two different places. (Because I like to move later lots of rectangles I want to create a loop and put the x and y values in a array.
Thank you
Annika
This is my js-code in p5js:
var demos = {x:300, y:-30};
var placeX = [0,200];
var placeY = [10,300];
var i = 0;
Yeah. It's faster, easier to read, and less error-prone. In the first loop it might seem pointless, until you want to add another tween and have to type boxes again. In the second loop, it's more apparent.
// harder to read, and easier to make a mistake
for (var i = 0; i < boxes.length; i++) {
rect(boxes[i].x, boxes[i].y, boxes[i].width, boxes[i].height);
}