I am trying to draw a lane through the use of nested loop, where i can control the lanes through use of “final int”, I have pretty much tried everything but didn’t result as i would like to be.
I am trying to draw a lane through the use of nested loop, where i can control the lanes through use of “final int”, I have pretty much tried everything but didn’t result as i would like to be.
The y-coordinate of every line is same regardles of the stage of the loops.
So only lines with y= height/2/ROAD_LANE will be drawn.
Does this resolve your issue?
final int ROAD_LANE = 4;
void setup() {
size(800,300);
}
void draw() {
lane();
}
//This is my nested loop to draw lanes across the window, but want them to create five of them rather than 1.
void lane () {
stroke(255);
strokeWeight(3);
for (int lineX = 0; lineX < width ; lineX += 100) {
for(int j = 0; j <= height; j+=height/ROAD_LANE) {
line(lineX, j, lineX+50, j);
}
}
}
Thank you soo much it certainly does help, but how do i make sure it stays in top of the first half of the screen.
You can change the maximum value of j (y-coordinate to) height/2
final int ROAD_LANE = 4;
void setup() {
size(800,300);
}
void draw() {
lane();
}
//This is my nested loop to draw lanes across the window, but want them to create five of them rather than 1.
void lane () {
stroke(255);
strokeWeight(3);
for (int lineX = 0; lineX < width ; lineX += 100) {
for(int j = 0; j <= height/2; j+=height/ROAD_LANE/2) {
line(lineX, j, lineX+50, j);
}
}
}
Thanks, it worked, really appreciate it.