xxxxxxxxxx
61
let speed = 3;
let stars = [];
let population = 600;
let images = [];
function preload(){
images.push(loadImage('equations/test.png'));
}
function getRandomImage(){
return random(images);
}
function setup() {
createCanvas(400, 400);
for(let i = 0; i < population; i++){
stars.push(new Star(1,1));
}
}
function draw() {
background(220);
translate(width/2,height/2);
for(let i = stars.length - 1; i >= 0; i--){
stars[i].update();
stars[i].show();
}
}
class Star{
constructor(){
this.pos = createVector(random(-width,width),random(-height,height),random(width));
this.e = getRandomImage();
}
update(){
this.pos.z -= speed;
if (this.pos.z < 1) {
this.pos.z = width;
this.pos.x = random(-width, width);
this.pos.y = random(-height, height);
}
}
show(){
let x = map(this.pos.x/this.pos.z,0,1,0,width);
let y = map(this.pos.y/this.pos.z,0,1,0,height);
let r = map(this.pos.z, 0, width, 16, 0);
let alpha = map(this.pos.z,0,width,100,0);
noStroke();
fill(0,0,0,alpha);
//circle(x,y,r);
//textSize(r);
//text("MATHY",x,y);
image(this.e,x,y,5,5);
}
}