xxxxxxxxxx
127
const LAVA_COLORS = [[252, 100, 19], [255, 195, 8],[255, 48, 2], [255, 158, 0]]
const START_POINT = [230, 370]
class Coordinates {
constructor(x, y) {
this.x = x
this.y = y
}
}
class LavaParticle {
constructor() {
this.coords = new Coordinates(START_POINT[0], START_POINT[1])
this.pColor = LAVA_COLORS[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.coords.x += this.xVelocity
this.yVelocity += this.yAcceleration
this.coords.y += this.yVelocity
}
show() {
noStroke()
fill(this.pColor)
ellipse(this.coords.x, this.coords.y, this.pSize)
}
outOfCanvas() {
return (this.coords.y > 600 || this.coords.y < 0 || this.coords.x < 0 || this.coords.x > 600)
}
}
class SmokeParticle {
constructor() {
this.coords = new Coordinates(START_POINT[0], START_POINT[1] - 20)
this.xVelocity = random(-2, 2)
this.yVelocity = random(-4, -1)
this.xAcceleration = this.xVelocity >= 0 ? -0.01 : 0.01
this.yAcceleration = -0.009
this.r = 70;
this.lifetime = 255;
}
update() {
this.xVelocity += this.xAcceleration
this.coords.x += this.xVelocity
this.yVelocity += this.yAcceleration
this.coords.y += this.yVelocity
this.lifetime -= 3;
}
show() {
noStroke()
for(let i = 0; i < 30; i++){
fill(255, 255, 255, 10)
ellipse(this.coords.x, this.coords.y, this.r - (i * 2) )
}
}
disappeared() {
return this.lifetime < 0
}
}
let img;
const particles = []
const smokeParticles = []
function preload() {
img = loadImage('texture32.png')
}
function setup() {
createCanvas(500, 500);
// smokeParticles.push(new SmokeParticle())
}
function draw() {
background(0, 76, 156);
fill(73, 18, 6)
smokeParticles.push(new SmokeParticle())
for (let i = smokeParticles.length - 1; i >= 0; i--){
if (smokeParticles[i].disappeared()) {
smokeParticles.splice(i, 1)
}
else{
smokeParticles[i].show()
smokeParticles[i].update()
}
}
fill(73, 18, 6)
quad(120, 500, 200, 350, 250, 350, 350, 500)
particles.push(new LavaParticle())
for (let i = particles.length - 1; i >= 0; i--){
if (particles[i].outOfCanvas()) {
particles.splice(i, 1)
}
else{
particles[i].show()
particles[i].update()
}
}
fill(73, 18, 6)
square(210, 350, 35)
}