# Help - Cant figure this out

**URL:** <https://discourse.processing.org/t/help-cant-figure-this-out/18291>\
**Category:** Coding Questions\
**Created:** [March 2, 2020, 1:06am UTC](https://discourse.processing.org/t/help-cant-figure-this-out/18291 "2020-03-02T01:06:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![GKBeginner](https://avatars.discourse-cdn.com/v4/letter/g/5fc32e/32.png) [@GKBeginner](https://discourse.processing.org/u/GKBeginner)\
**Post date:** [March 2, 2020, 1:06am UTC](https://discourse.processing.org/t/help-cant-figure-this-out/18291/1 "2020-03-02T01:06:23Z")

</div>

This is supposed to produce vertical lines of varying colors and lengths and I can only get it to produce lines of the same color and length. I have looked at it over and over and I can’t figure out what I am doing wrong.

```auto
float randomZ;

void setup()
{
size(400,400);
background(250,250,0);
}

void draw()
{
strokeWeight(3);
stroke(random(0,85), random(86,170), random(171,256)); 
int x=0;
int y=0;
randomZ=random(50,width); 

for(x=0; x<=width; x+=20){
  for(randomZ=50; randomZ<height; randomZ++){
    line(x,y,x,randomZ);
  }
}
}

```

---

<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 2, 2020, 5:50am UTC](https://discourse.processing.org/t/help-cant-figure-this-out/18291/2 "2020-03-02T05:50:44Z")

</div>

```auto

float randomZ;

void setup() {
  size(400, 400);
  background(250, 250, 0);
  frameRate(4);
}

void draw() {
  background(250, 250, 0);
  strokeWeight(3);
  stroke(random(0, 85), random(86, 170), random(171, 256));
  int x=0;
  int y=0;

  for (x=0; x<=width; x+=20) {
    randomZ=random(50, width);
    // for (randomZ=50; randomZ<height; randomZ++) {
    line(x, y, x, randomZ);
    // }
  }
}

```

---

<div class="post-metadata">

**Author:** ![ctrembla](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@ctrembla](https://discourse.processing.org/u/ctrembla)\
**Post date:** [March 2, 2020, 6:10am UTC](https://discourse.processing.org/t/help-cant-figure-this-out/18291/3 "2020-03-02T06:10:00Z")

</div>

This is just a rough fixing of the code, but if move fill && randomZ to the for loop you get different colors & then you also need background in draw too. Try this out to see if like.

```auto
float randomZ;

void setup()
{
size(400,400);

}
void draw(){
  background(0);
  strokeWeight(3);
  int x=0;
  int y=0;
  for(x=0; x<=width; x+=20){
      randomZ=random(50,width);
      stroke(random(0,86), random(86,255), random(0,255));
      line(x,y,x,randomZ);
  }
}

```

---

<div class="post-metadata">

**Author:** ![GKBeginner](https://avatars.discourse-cdn.com/v4/letter/g/5fc32e/32.png) [@GKBeginner](https://discourse.processing.org/u/GKBeginner)\
**Post date:** [March 2, 2020, 7:01am UTC](https://discourse.processing.org/t/help-cant-figure-this-out/18291/4 "2020-03-02T07:01:40Z")

</div>

Thank you so much! I really appreciate your help.

---

<div class="post-metadata">

**Author:** ![GKBeginner](https://avatars.discourse-cdn.com/v4/letter/g/5fc32e/32.png) [@GKBeginner](https://discourse.processing.org/u/GKBeginner)\
**Post date:** [March 2, 2020, 7:02am UTC](https://discourse.processing.org/t/help-cant-figure-this-out/18291/5 "2020-03-02T07:02:27Z")

</div>

Thank you so much! I really appreciate your help!
