We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello!
I'm trying to make a board of squares on square grid with random colors and dimensions ranging from int 10-30. I've made this happen, but I want to try to do it with functions instead of the conditionals themselves, but I can't figure out how to do that. Also I want the row and column of the square I press to change colors randomly when I click on it. Any help is much appreciated guys!
Thanks,
Chris Bosh
Here's what I have so far:
int n = int(random(10,30));
int z = int(random(10,30));
void setup() {
size(n*z,n*z);
background(255);
for(int x = 0; x < width; x = x + z) {
for(int y = 0; y < height; y = y + z) {
noStroke();
fill(random(255),random(255),random(255));
rect(x,y,z,n);
}
}
Answers
Lotsa grid online examples:
http://studio.processingtogether.com/sp/pad/export/ro.98-pSvW97Q-RE/latest
http://studio.processingtogether.com/sp/pad/export/ro.9ABG0RKl9D2Bx/latest
http://studio.processingtogether.com/sp/pad/export/ro.93MhRWK35nIP8/latest
http://studio.processingtogether.com/sp/pad/export/ro.9L5jAtga7SpyF/latest
http://studio.processingtogether.com/sp/pad/export/ro.9A9O52aqsIjdx/latest
"I've made this happen"
Not with the code you show, at least... :-) You change the fill color, but doesn't draw anything. And I don't see any conditional in this code either.
"when I click on it"
Not sure where you are stuck. Do you know the mousePressed() function, for example?
Lol sorry I missed the rect line when I pasted it in, my bad! Yes I'm familiar with the mouse pressed function, but doesn't have to work in conjunction with a draw() section? And wouldn't that mean the setup() I have would be gone after the first frame?
Here is similar post
blyk's sketch is very elegant
to dig more into classes and oop, see
http://processing.org/tutorials/objects/
please
other approach
Another approach would be to calculate the cell's positions on the fly in mousepressed... but then you need a 2D grid to store the colors...