We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello! I'm quite new to processing and still figuring out how some of the basics work. I'm trying to use the redraw() function in this sketch, in order to redraw the screen. However, it's not redrawing anything. I have a println() function in the void setup() which shows a value for the x variable, which randomises each time the sketch is run. Whenever I press a key, I'm thinking that shouldn't the value of the x variable change in the console, which would then determine what the colour of the ellipse would be in the sketch? But, nothing is happening to the sketch. :(.
float x = int (min(1,10));
void setup() {
size(100, 100);
smooth();
println(x);
}
void draw() {
if (x > 5) {
ellipse(50, 50, 50, 50);
} else {
rect(50, 50, 50, 50);
}
}
void keyPressed() {
redraw();
}
Answers
Do you think
redraw()
is going to start the sketch over, and thus runsetup()
again? It's not. Whatredraw()
does is causedraw()
to run again - that's all. And since your sketch is constantly runningdraw()
again anyway (because you haven't callednoLoop()
to stop it from doing that), your call toredraw()
is pointless.It's also worth mentioning that you're not changing the value assigned to x at all. And the value that you are assigning to x,
int(min(1,10))
is always going to be 1 (because 1 is smaller than 10, min(1,10) is 1, and int(1) is still 1). Maybe you should try a call torandom()
instead?Yep! My bad on the min() I was experimenting with other things as well. Thanks for the help.