fade in out in a function
in
Programming Questions
•
6 months ago
This this part of a larger code to fade actual objects using a lot of conditionals...
(and I can guess that using sine-wave makes it easier) yet I would like to figure
out how to make this work. Alpha is universal so at anytime it should change
but the circle is not drawn until the loops are completed.. I think this is a
problem of scope:
(and I can guess that using sine-wave makes it easier) yet I would like to figure
out how to make this work. Alpha is universal so at anytime it should change
but the circle is not drawn until the loops are completed.. I think this is a
problem of scope:
int alpha = 0;
boolean fade;
void setup() {
smooth();
frameRate(1);
fade = false;
}
void draw() {
fill(200, 50, 100, alpha);
ellipse(50, 50, 50, 50);
twinkle();
println("cycle");
}
void twinkle() {
//fade in and out
if (fade == false) {
for (float i = 0; i<=255; i++) {
alpha = (int)i;
println("++ " + alpha);
}
if (alpha == 255) {
fade = true;
println("fade = true");
}
}
else {
for (float i=255; i>=0; i--) {
alpha = (int)i;
println("-- " + alpha);
}
if (alpha == 0) {
fade = false;
println("fade = false");
}
}
}
1