We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi I have this code where I create random rectangles every frame, I need that at least one random rect turns, one per color, red, yellow, blue & black (the ideal would be to limit them from at least 1 to max. 3). The rest should be white.
void setup() { size (600, 600); strokeWeight (10); strokeCap (SQUARE); rectMode(CORNERS); frameRate(1); } float x; float larg; float alt; float y; int i; int j; int o=20; //no. of vertical rects int v=30; //no. of horizontal rects
void draw () {
background(255); alt=0; stroke(20);
for (i=0; i<=5; i++) {
y=random(alt, height);
larg=0;
if (i==o)
y=600;
for (j=1; j<=v; j++) {
x=random(larg, width);
if (j==v)
x=600;
rect(larg, alt, x, y);
larg=x;
}
alt=y;
} }
Comments
here
Man, awesome, thanks a lot! Can I control the number of rects to be filled?
at the moment it's random
but you just can increase a counter every time you use a color and only invoke the color lines in the code when counter < 5 or so