Beginner question: Wilson Grids
in
Programming Questions
•
2 years ago
Hi there processing people,
DISCLAIMER:
I'm totally new to processing and programming in general, just started with the processing handbook a week ago.
My problem is a question of understanding. More specifically the Wilson Grids example (Synthesis 1, p152).
- size(600, 600);
- background(255);
- int sqNum = 12;
- int sqSize = width/sqNum;
- int halfSize = sqSize/2;
for (int y = halfSize; y < width; y = y+sqSize) {- for (int x = halfSize; x < height; x = x + sqSize) {
- rect(x-halfSize+2, y-halfSize+2, sqSize-4, sqSize-4);
- }
- }
This is the first part of the example.
What I'm trying to get my head around is the idea behind offsetting x and y and the setting it back when drawing the rectangles, instead of just drawing the rectangles from (0,0) like this:
- for (int y = 0; y < width; y = y+sqSize) {
- for (int x = 0; x < height; x = x+sqSize) {
- rect(x+2, y+2, sqSize-4, sqSize-4);
- }
- }
I'm guessing there is a perfectly good reason for doing it the other way, I'm just not smart enough to figure out why...
HELP!
1