xxxxxxxxxx
62
let starSpeed = 10;
let resetInterval = 1000;
class Star{
constructor(){
this.setup();
}
draw(){
let sx = map(this.x/this.z,0,1,0,width);
let sy = map(this.y/this.z,0,1,0,height);
let px = map(this.x/this.pz,0,1,0,width);
let py = map(this.y/this.pz,0,1,0,height);
this.pz = this.z;
stroke(random(150,255),150,random(150,255));
strokeWeight(this.sr);
line(px,py,sx,sy);
}
update(){
this.z -=starSpeed;
if(this.z <= resetInterval){
this.setup();
}
}
setup(){
this.z = random(width);
this.x = random(-width,width);
this.y = random(-height,height);
this.pz = this.z;
this.sr = random(1,1000)/300;
}
}
const stars = [];
function setup() {
createCanvas(800, 800);
for(let i = 0; i < 5000;i++){
stars.push(new Star());
}
}
function draw() {
starSpeed = map(mouseX,0,width,0,200);
resetInterval = map(mouseY,0,height,0,750);
background('black');
translate(width/2,height/2);
stars.forEach(star => {
star.draw();
star.update();
})
}