xxxxxxxxxx
let graphics
let particles = []
let colors = ['#ffaabb', '#6677ff', '#ff3355', '#55ffbb', '#00aaff', '#99bbff', '#eeaa66']
let myShader
let moved = 0
let movespeed = 150
let amount = 100
class Particle {
constructor(a, z) {
this.a = a
this.b = random(0, TWO_PI)
this.z = z
this.c = random(colors)
this.s2 = 0
this.s = random(5, 35)
this.rx = random(0, PI)
this.ry = random(0, PI)
this.rz = random(0, PI)
}
draw() {
graphics.push()
graphics.rotateZ(this.z / 720 + this.b)
graphics.translate(this.a, 0, this.z)
graphics.rotateX(this.rx)
graphics.rotateY(this.ry)
graphics.rotateZ(this.rz)
graphics.fill(this.c)
graphics.sphere(this.s2)
graphics.pop()
this.z += movespeed
this.rx += PI / 60
this.s2 += (this.s - this.s2) * 0.1
this.b -= (35 - this.s) * 0.001
}
}
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL)
graphics = createGraphics(windowWidth, windowHeight, WEBGL)
pixelDensity(1)
graphics.pixelDensity(1)
graphics.background(0)
graphics.noStroke()
myShader = createShader(vert, frag)
shader(myShader)
graphics.fill(0)
}
function draw() {
graphics.clear()
graphics.background(10)
movespeed = 10
moved += movespeed
while(moved > 1000 / amount) {
let dir = random(TWO_PI)
particles.push(new Particle(random(100, 250), -2000 + moved))
moved -= 1000 / amount
}
for(let p of particles) {
p.draw()
}
particles = particles.filter(p => p.z < 1000)
myShader.setUniform('mainTex', graphics)
myShader.setUniform('resolution', [width * pixelDensity(), height * pixelDensity()])
rect(-width / 2, -height / 2, width, height)
}