We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I wanted to set the number of rectangles equal to the variable i, however it will not. Is there any way to do this? I want to stop making rectangles at 75 with out using the void draw() and if loop. I would like it to be all in the for loop. Is that possible?
void setup(){
size(800,800);
background(255);
frameRate(3000);
}
void rect(){
float i;
for(i = 0;i < 75; i++)
{
float r,l,f,s;
r = random(10,150);
l = random(10, 800);
f = random(10,800);
s = random(10,150);
frameRate(20);
fill(140);
if(r<50){
fill(2,245,32);
}
if(s<50){
fill(255,26,252);
}
rect(r,s,f,l);
rectMode(CENTER);
}
}
Answers
Dear lolnyancats,
please don't say void, it is a function
void is just what it returns (could also be int or boolean)
please don't say if-loop, it's not a loop since it doesn't repeat anything
It's an if-clause
please don't name your function rect because that is the in-build command.
Better name it drawRects() or so
usage
if you want to use the function you need to call it in setup():
otherwise it won't get executed.
Good luck!
Greetings, Chrisir ;-)
Hey Chrisir thanks so much! I see you on here quite a bit. Thanks for helping me again!
you are welcome!
It's nice that you take the time to say thanks!
also
can be written as
for(int i = 0;i < 75; i++)
without float i;
also
in the long run it might not be wise to try to live without draw()....
also
you can format your code ctrl-t in the ide (for indent)
The frameRate() call in the function (even more in the loop!) is useless. Its value is applied until you call it with another value.
Idem for rectMode(): you can call it only once in setup(). Beside, it should be called before you call rect().