Reputation: 815
I have this piece of code, and i am wondering how to make a loop that will draw these lines... Every 50 pixels on the x-axis... I am curious as to how this can be done and would like to use a loop rather than manually drawing each line! The following is the code for the lines... Please any help would be much appreciated!
//set sidewalk
fill(255,255,255);
rect(0,490,500,10);
line(50,490,50,500);
line(100,490,100,500);
line(150,490,150,500);
line(200,490,200,500);
line(250,490,250,500);
line(300,490,300,500);
line(350,490,350,500);
line(400,490,400,500);
line(450,490,450,500);
Upvotes: 1
Views: 3522
Reputation: 432
If your interest lies in Visualization, another good source for learning Processing is Visualizing Data by Ben Fry.
And all the examples in this book comes with the Processing itself. Selecting File -> Examples..., then you can choose which example to see and to play with.
Upvotes: 1
Reputation: 2051
Daniel Shiffman does a really good job of explaining how to do this in his book Learning Processing. You might want to look at example 6-1, 6-2 and 6-3 available on the companion site to the book as they lead up to how this problem is being solved. Shiffman shows this with a while loop and shows a similar code snippet with example 6-6 with it in a for loop similar to the previous answer.
Upvotes: 2
Reputation: 96
fill(255,255,255);
rect(0,490,500,10);
for (int i = 50; i <= 450; i+=50) {
line(i,490,i,500);
}
maybe this way.
Upvotes: 5