We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Relatively new to Processing. Can't figure out why the code below doesn't work. It DOES work if I remove the "void setup();" command before and after size. I gather it messes with the "for" loop, but don't understand why. Thanks.
void setup(); { size(200,200); } // With a for loops for (int x = 0; x < width; x+=10) { for (int y = 0; y < height; y+=10) { noStroke(); fill(random(255)); rect(x,y,10,10); } }
Answers
https://forum.Processing.org/two/discussion/8045/how-to-format-code-and-text
There's a huge diff. between declare/implement a function & then use/invoke it!
In Processing is expected that we declare & implement functions setup() & draw():
https://Processing.org/tutorials/gettingstarted/
http://hello.Processing.org/
Thanks, but still don't see why the code does work without the setup() function but does not work when setup is included. Here's the code again:
void setup() { size(200,200); } // With a for loops for (int x = 0; x < width; x+=10) { for (int y = 0; y < height; y+=10) { noStroke(); fill(random(255)); rect(x,y,10,10); } }
When you have the setup() function there, Processing assumes you want to use the setup() and draw() functions. But your loops aren't in any function, and that is a problem. You could put them inside setup().
Once we declare any function, Processing stops accepting code outside functions.
Got it. Thx.