xxxxxxxxxx
62
let spotSize;
let spotA;
let spots = [];
function setup() {
createCanvas(1920, 1080);
//Initial spot size and alpha
spotSize = 240;
spotA = 200;
}
function draw() {
background(255);
fill(0);
circle(width/2,height/2,height);
noFill();
stroke(255);
strokeWeight(5);
ellipse(mouseX, mouseY, spotSize);
for (let s of spots){
s.drop();
s.disappear();
}
//Clean up old spots in the array
if (spots.length > 50) {
spots.splice(0, 1);
}
}
function mousePressed(){
let spot = new Spot(mouseX, mouseY);
spots.push(spot);
}
class Spot {
constructor(x,y) {
this.x = x;
this.y = y;
this.size = spotSize;
this.a = spotA;
}
drop(){
noStroke();
fill(255, this.a);
ellipse(this.x, this.y, this.size);
}
disappear(){
this.size -= 0.08; //how fast spots shrink
this.a -= 0.2; //how fast spots fade
this.size = constrain(this.size, 0, this.size);
this.a = constrain(this.a, 0, this.a);
}
}