What made my for loop point all the lines to the centre?

edited September 2016 in Questions about Code

This isn't really a problem i'm having but i'd just like to understand better what's going on. Following the instructions in the book, i embedded two for loops into each other and gave them parametres that point the lines to centre, here's the code:

background(0); fill(255); stroke(102); for (int y = 20; y <= height-20; y += 10) { for (int x = 20; x <= width-20; x += 10) { ellipse(x, y, 4, 4); line(x, y, 240, 60);

Can someone please explain to me what causes the loops to point those lines from the ellipses to the centre specifically? Would just like know, thanks in advance!



  • The loops create x and y variables that increment in a grid around the screen.

    Then the line(x, y, 240, 60) line draws a line from each x and y position to the position 240,60 which is in the middle of your screen. Try changing the size of your window to see this. Or draw a red ellipse at 240,60. Or change that 240,60 to mouseX, mouseY.

  • Of course, why didn't i think of that before, thanks :)

Sign In or Register to comment.