xxxxxxxxxx
/**
* AlphaStepGen (v1.0)
* GoToLoop (2017/Sep/20)
*
* Forum.Processing.org/two/discussion/24193/descending-curve-function#Item_2
* OpenProcessing.org/sketch/450448
*/
static final boolean JS = 1/2 == 1/2.;
final AlphaStep opaque = new AlphaStep();
void setup() {
size(800, 600);
smooth(3);
frameRate(5);
colorMode(RGB);
ellipseMode(CENTER);
strokeWeight(2.5);
stroke(0);
println(opaque.steps);
}
void draw() {
background(-1);
fill(255, 0, 0, opaque.nextAlpha());
ellipse(width>>1, height>>1, width>>1, height>>1);
if (JS) return;
String info = "Frame: " + frameCount + " - Alpha: " + opaque.toString();
getSurface().setTitle(info);
}
class AlphaStep {
static final int STEP = 5;
float opacity = 255;
final float[] steps = new float[1 + (int)opacity];
AlphaStep() {
for (int opac = (int)opacity, i = steps.length; i-- > 0;
steps[opac - i] = STEP * norm(i, opac, 0));
}
color nextAlpha() {
return round(opacity -= steps[round(opacity)]);
}
String toString() {
return nf(opaque.opacity, 0, 2);
}
}