# Line Loop bouncing

**URL:** <https://discourse.processing.org/t/line-loop-bouncing/44090>\
**Category:** Coding Questions\
**Created:** [March 12, 2024, 9:19pm UTC](https://discourse.processing.org/t/line-loop-bouncing/44090 "2024-03-12T21:19:32Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 14, 2024, 8:02am UTC](https://discourse.processing.org/t/line-loop-bouncing/44090/21 "2024-03-14T08:02:39Z")

</div>

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

Please describe the effect you want to achieve.

---

<div class="post-metadata">

**Author:** ![humano](https://avatars.discourse-cdn.com/v4/letter/h/dbc845/32.png) [@humano](https://discourse.processing.org/u/humano)\
**Post date:** [March 14, 2024, 12:14pm UTC](https://discourse.processing.org/t/line-loop-bouncing/44090/22 "2024-03-14T12:14:01Z")

</div>

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

```auto
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;
    }
  }
  
}

```

---

<div class="post-metadata">

**Author:** ![Reid](https://avatars.discourse-cdn.com/v4/letter/r/439d5e/32.png) [@Reid](https://discourse.processing.org/u/Reid)\
**Post date:** [March 15, 2024, 9:41pm UTC](https://discourse.processing.org/t/line-loop-bouncing/44090/23 "2024-03-15T21:41:51Z")

</div>

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 …

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [March 15, 2024, 10:38pm UTC](https://discourse.processing.org/t/line-loop-bouncing/44090/24 "2024-03-15T22:38:20Z")

</div>

> [@humano](#):
>
> some lines advancing faster than other lines and passing them

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!

`:)`

[Previous page](https://discourse.processing.org/t/line-loop-bouncing/44090.md?page=1)
