Gradual Movement within a For Loop
in
Programming Questions
•
7 months ago
Hi, I was trying to create a sketch where a point moves over to another random point. I've used lerp and a for loop but this is all done instantly. How do I make the movement gradual whilst still using a for loop. I'm stumped, especially working out a way of doing this to all the points simultaneously.
Cheers
- int dotAmount = 5;
- PVector[] dotList = new PVector[dotAmount];
- PVector[] oldDotList = new PVector[dotAmount];
- float distance;
- void setup()
- {
- size(800, 600);
- background(255);
- stroke(0);
- strokeWeight(3);
- createDotList();
- newDotList();
- dotMorph();
- }
- void createDotList()
- {
- for (int i = 0; i < dotAmount; i++) {
- float randomX = random(0, 800);
- float randomY = random(0, 600);
- dotList[i] = new PVector (randomX, randomY);
- point(dotList[i].x, dotList[i].y);
- }
- arrayCopy(dotList, oldDotList);
- }
- void newDotList()
- {
- for (int i = 0; i < dotAmount; i++) {
- float randomX = random(0, 800);
- float randomY = random(0, 600);
- dotList[i] = new PVector (randomX, randomY);
- }
- println(oldDotList[1]);
- println(dotList[1]);
- }
- void dotMorph()
- {
- for (int z = 0; z <= 10; z++) {
- float pointX = lerp(dotList[1].x, oldDotList[1].x, z/10.0);
- float pointY = lerp(dotList[1].y, oldDotList[1].y, z/10.0);
- println(pointX);
- point(pointX, pointY);
- }
- }
1