let particles = [];
function setup() {
createCanvas(windowWidth, windowHeight);
noStroke();
}
function draw() {
background(0, 50);
// ایجاد ذره جدید وقتی لمس/ماوس پایین هست
if (mouseIsPressed || touches.length > 0) {
let x = mouseX || touches[0].x;
let y = mouseY || touches[0].y;
for (let i = 0; i < 5; i++) {
particles.push(new Particle(x, y));
}
}
// آپدیت و نمایش ذرات
for (let i = particles.length - 1; i >= 0; i--) {
let p = particles[i];
p.update();
p.show();
if (p.finished()) {
particles.splice(i, 1);
}
}
}
class Particle {
constructor(x, y) {
this.x = x + random(-10, 10);
this.y = y + random(-10, 10);
this.vx = random(-1, 1);
this.vy = random(-3, -1);
this.alpha = 255;
this.size = random(10, 25);
this.color = color(random(200, 255), random(50, 150), 0, this.alpha);
}
update() {
this.x += this.vx;
this.y += this.vy;
this.alpha -= 5;
this.size *= 0.96;
}
finished() {
return this.alpha < 0;
}
show() {
fill(red(this.color), green(this.color), blue(this.color), this.alpha);
ellipse(this.x, this.y, this.size);
}
}