xxxxxxxxxx
59
lavaColors = [[252, 100, 19], [255, 195, 8],[255, 48, 2], [255, 158, 0]]
class Particle {
constructor() {
this.x = 280
this.y = 480
this.pColor = lavaColors[Math.floor(Math.random() * 4)]
this.pSize = Math.floor(Math.random() * 5) + 4
this.xVelocity = random(-0.5, 0.5)
this.yVelocity = random(-2.3, -1)
this.xAcceleration = this.xVelocity >= 0 ? -0.0001 : 0.0001
this.yAcceleration = 0.009 + (0.0003 * this.pSize)
}
update() {
this.xVelocity += this.xAcceleration
this.x += this.xVelocity
this.yVelocity += this.yAcceleration
this.y += this.yVelocity
}
show() {
noStroke()
fill(this.pColor)
ellipse(this.x, this.y, this.pSize)
}
}
const particles = []
function setup() {
createCanvas(600, 600);
}
function draw() {
background(0, 76, 156);
fill(73, 18, 6)
quad(150, 600, 250, 450, 300, 450, 400, 600)
particles.push(new Particle())
for (let i = particles.length - 1; i >= 0; i--){
if (particles[i].y > 600 || particles[i].y < 0 || particles[i].x < 0 || particles[i].x > 600) {
particles.splice(i, 1)
}
else{
particles[i].show()
particles[i].update()
}
}
fill(73, 18, 6)
square(263, 450, 35)
}