Hi does anyone know how to do rows of squares using functions?
This is what I have so far:
void setup()
{
size(500,500);
background(255);
}
void draw()
{
background(255);
stroke(5);
int x = 10;
int y = 10;
int w = 10;
int h = 10;
for (int i = 0; i < 12; i++)
{
fill(distance(int(random(150, 255)), int(random(0, 30)),
int(random(0, 30)), 0));
rect(x,y,w,h);
x=x+w;
}
}
@Sky give you a good start,
but again, you use the word “pixel art”
and want make random fill color for each rectangle
( what leads to 60 times different color ( flickering ) per second
unless you do it in setup
or if do it in draw must switch to
noLoop();
or make a array for all rectangles with a memory of the color.
)
add i wanted to stay more close to your code but
needed to
// https://discourse.processing.org/t/functions-problem-rows-of-squares/7231
int x = 10;
int y = 10;
int w = 10;
int h = 10;
int many = 144;
int grid = 12;
void setup() {
size(500, 500);
stroke(0, 0, 200); // border line blue
strokeWeight(0.2); // border line width
noLoop();
}
void draw() {
background(255);
for (int i = 0; i < many; i++) {
fill(random(150, 255), random(150, 255), random(150, 255), 255);
// rect(x+i*w, y, w, h); // for one row only
rect(x+(i%grid)*w, y+(floor(i/grid))*h, w, h); // for grid
}
}