xxxxxxxxxx
79
let Stars = [];
function windowResized() {
if (fullscreen()) {
resizeCanvas(windowWidth, windowHeight);
} else {
resizeCanvas(400, 400);
}
}
function keyPressed() {
if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {
if (key === "f") {
let fs = fullscreen();
fullscreen(!fs);
}
}
}
class Star {
constructor() {
let w = width;
let h = height;
this.x = random(-w/2, w/2);
this.y = random(-h/2, h/2);
this.z = random(w);
this.px;
this.py;
}
update() {
this.z-=4
if (this.z < 1) {
this.z = width;
this.x = random(-width/2, width/2);
this.y = random(-height/2, height/2);
}
}
show() {
stroke(255);
this.r = map(this.z, 0, width, 8, 1)
strokeWeight(this.r);
this.sx = map((this.x / this.z), 0, 1, 0, width)
this.sy = map((this.y / this.z), 0, 1, 0, height)
point(this.sx, this.sy);
this.px = this.sx;
this.py = this.sy
}
}
function setup() {
createCanvas(400, 400);
for (let i = 0; i < 600; i++) {
Stars.push(new Star());
}
}
function draw() {
translate(width/2, height/2)
background(20);
for (let s = 0; s < Stars.length; s++) {
Stars[s].update();
Stars[s].show();
}
print(Stars.length);
}