We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hell guys, is there a way to fill all the circles with different color? I've tried a few solutions but the colors keep blinking, they don't stay fixed as I want:
int circleW=15;
int circleH=15;
int theSpace=circleW/3;
int redColor = int(random(10,255));
int greenColor= int(random(50,255));
int blueColor = int(random(200,255));
void setup() {
size(600, 400);
frameRate(30);
smooth();
noStroke();
ellipseMode(CORNER);
}
void draw() {
background(0);
for (int i = 0; i < width-circleW/2; i = i+(circleW+theSpace)) {
fill(redColor,greenColor,blueColor);
ellipse(i, height/2, circleW, circleH);
}
}
Answers
add noLoop(); to the end of setup()
this stops draw from being executed again and again. the flashing you're seeing is the circles being continually redrawn using a new random fill colour.
if you want each circle to be a different colour then move lines 4-6 after line 19
Just a lil' correction. noLoop() can be issued anywhere.
Processing invokes draw() at least once, no matter what! >-)
When writing to newbies, it is better to be precise, otherwise we can get exotic code... It is a bit like the message "hit any key", provoking perplexity ("which key?!").
Although I have seen, when I wrote "at the end of xxx()", the line after the closing brace of this function...
Thanks guys, you rock.
When I want to use it, I place noLoop() right after size()! I like to clump related canvas settings together! =:)