Fade in and Out

You can set the speed when rising different from the speed when falling; here, the opacity increases quickly (+10 per frame) but fades out slowly (-1 per frame). The same idea can apply to motion and to size animation, of course. Borrowing an idea from sound,we can call this the "Attack" and "Decay."
int opacity; int speed=10; void setup() { size(500,300); } void draw() { background(0); opacity = opacity + speed; if (opacity > 255) { opacity = 255; speed = -1; } if (opacity < 0) { speed=10; } fill(255,0,0,opacity); ellipse(250,150,250,250); }