xxxxxxxxxx
64
let starX, starY;
let speed;
function setup() {
createCanvas(400, 400);
starX = random(width);
starY = random(height);
speed = random(1, 3);
}
let xoff = 0.0;
function drawShip(){
}
function draw() {
background(0);
// Calculate the distance between the star and the mouse
let d = dist(starX, starY, mouseX, mouseY);
// If the mouse is close to the star, reset its position
if (d < 30) {
starX = random(width);
starY = random(height);
speed = random(1, 3);
}
// Draw the falling star
fill(255, 255, 0);
stroke(255);
strokeWeight(2);
const radius1 = 15;
const radius2 = 7;
beginShape();
for (let i = 0; i < 5; i++) {
const angle1 = TWO_PI / 5 * i - HALF_PI;
const angle2 = TWO_PI / 5 * i + TWO_PI / 10 - HALF_PI;
const x1 = starX + cos(angle1) * radius1;
const y1 = starY + sin(angle1) * radius1;
const x2 = starX + cos(angle2) * radius2;
const y2 = starY + sin(angle2) * radius2;
vertex(x1, y1);
vertex(x2, y2);
}
endShape(CLOSE);
// Update the star's position
starY += speed;
// Wrap the star around the canvas
if (starY > height + 15) {
starY = -15;
starX = random(width);
speed = random(1, 3);
}
drawShip();
}