Tyler Ben

Generation

generate functionTue, 01 Aug 2023

Debug this // Define variables let stars = []; let numStars = 100; // Set up the canvas function setup() { createCanvas(600, 600); // Create stars and add them to the array for (let i = 0; i < numStars; i++) { stars.push(new Star()); } } // Draw the stars function draw() { background(0); // Update and display each star for (let i = 0; i < numStars; i++) { stars[i].update(); stars[i].display(); } } // Define the Star class class Star { constructor() { this.x = random(width); this.y = random(height); this.size = random(1, 5); this.speed = random(1, 5); this.color = color(random(255), random(255), random(255)); } // Update the star's position update() { this.x += this.speed; if (this.x > width) { this.x = 0; } } // Display the star on the canvas display() { fill(this.color); noStroke(); ellipse(this.x, this.y, this.size, this.size); } }

// Define variables let stars = []; let numStars = 100; // Set up the canvas function setup() { createCanvas(600, 600); // Create stars and add them to the array for (let i = 0; i < numStars; i++) { stars.push(new Star()); } } // Draw the stars function draw() { background(0); // Update and display each star for (let i = 0; i < numStars; i++) { stars[i].update(); stars[i].display(); } } // Define the Star class class Star { constructor() { this.x = random(width); this.y = random(height); this.size = random(1, 5); this.speed = random(1, 5); this.color = color(random(255), random(255), random(255)); } // Update the star's position update() { this.x += this.

Javascript
Generate More

Questions about programming?Chat with your personal AI assistant