I'm using the p5.js library. When the mousePressed
is called I want to create a black ellipse, two seconds later I want to draw another a white ellipse directly on top. I would like to 'animate' the alpha channel on this second white ellipse to give the illusion that the black ellipse is fading out.
I can't seem to wrap my head around how to approach this. How can I create a timer as such that maps the alpha channel and stops when a = 255?
var a;
var x;
var y;
function setup() {
var canvas = createCanvas(windowWidth, windowHeight;
ellipseMode(RADIUS);
imageMode(CENTER);
noStroke();
background('white');
}
function mousePressed() {
x = mouseX;
y = mouseY;
fill('black');
ellipse(x, y, 45, 45);
setTimeout(function() {
//animate a
fill(255, 255, 255, a);
ellipse(x, y, 45, 45);
}, 2000)
}