createCanvas(windowWidth, windowHeight);
function resetBackground(){background(0);}
const numberOfStars = 1000
for (let i = 0; i < numberOfStars; i++) {
const xPos = getRandomX()
const yPos = getRandomY()
const zPos = getRandomZ()
const vectorPosition = createVector(xPos, yPos, zPos)
limitedZ: map(zPos, 0, width, 1, 10)
const getRandomY = () => random(0, height)
const getRandomX = () => random(0, width)
const getRandomZ = () => random(0,width)
function applyToAllStars(functionName) {
for (let star of stars) {
applyToAllStars(moveStar)
applyToAllStars(drawStar)
function moveStar(star) {
const speedX = map(mouseX, 0, width, -star.limitedZ, star.limitedZ)
const speedY = map(mouseY, 0, height, -star.limitedZ, star.limitedZ)
const vectorMovement = createVector(speedX, speedY, 0);
const nextVectorPosition = p5.Vector.add(star.pos, vectorMovement);
star.pos = nextVectorPosition
replaceStarIfFallsOff(star)
function replaceStarIfFallsOff(star){
if (star.pos.x > width) {
star.pos.y = getRandomY()
star.pos.y = getRandomY()
if (star.pos.y > height) {
star.pos.x = getRandomX()
star.pos.x = getRandomX()
function drawStar(star) {
circle(star.pos.x, star.pos.y, star.limitedZ)