Line Loop bouncing

Can you please post your current entire code every time you post?

Please describe the effect you want to achieve.

1 Like

You can see here every line seems to be modifing its speed continously, but what I was looking for it is every line with a different speed, I mean, some lines advancing faster than other lines and passing them

float[] lineX = new float[100];
color[] cols = {color( 255, 0, 00 ), color( 255, 255, 0 ), color( 0, 255, 0 ),
                color( 0, 255, 255 ), color( 0, 0, 255 ), color( 255, 0, 255 )};

void setup() {
  size(800, 1000);
  strokeWeight(5);
  
  for (int i = 0; i < lineX.length; i++) {
    lineX[i] = random(width);
  }
 
}

void draw() {
  background(255);
  
  /*
  
  for (int j = 0; j<width; j=j+10){
    stroke(cols[j%6]);
    line(j,0,j,height);
  } 
  */
  

  for (int i = 0; i < lineX.length; i=i+1) {
    //float lineY = height * i / lineX.length;
    line(lineX[i], 0, lineX[i], height);
    stroke(cols[i%6]);
    lineX[i] = lineX[i]+=random(0,1);

    if (lineX[i] > width) {
      lineX[i] = 0;
    }
  }
  
}
1 Like

You could put all the code inside the draw() function inside of a “if (frameCount % 10 == 0) { }” clause to make it run 10 times slower etc …

Create an array to store speed for each line:

int [] speed = new int [100];

Initialize it with some speeds:

speed[i] = (int) random(10);

And then use the speed for that line to increment it:

lineX[i] = lineX[i] + speed[i];

This worked for me!

Have fun!

:)

1 Like