xxxxxxxxxx
39
/*
----- Coding Tutorial for Live Workshop -----
Date: Jan 11, 2025
Connect with Patt: @pattvira
https://www.pattvira.com/
----------------------------------------
*/
let stars = [];
function setup() {
createCanvas(400, 400);
}
function draw() {
background(0);
for (let i=stars.length-1; i>=0; i--) {
stars[i].update();
stars[i].display();
if (stars[i].done) {
stars.splice(i, 1);
}
}
}
function mouseDragged() {
stars.push(new Star(mouseX, mouseY, 0, 0));
}
function mousePressed() {
let num = random(20, 50);
for (let i=0; i<num; i++) {
let velocity = p5.Vector.random2D().mult(random(2,5));
stars.push(new Star(mouseX, mouseY, velocity.x, velocity.y));
}
}