xxxxxxxxxx
49
let stars = [];
let sunY = 50; // Initial position of the sun
function setup() {
createCanvas(800, 400);
noStroke();
// Create stars
for (let i = 0; i < 100; i++) {
stars.push({
x: random(width),
y: random(height),
size: random(1, 10),
});
}
}
function draw() {
if (mouseIsPressed) { // Check if mouse is pressed
background(255); // Bright background
sunY -= 1; // Move sun up
} else {
background(0); // Night sky
}
// Draw sun
fill(250, 250, 0); // Yellow color
circle(50, sunY, 70);
// Draw stars
fill(255);
for (let i = 0; i < stars.length; i++) {
ellipse(stars[i].x, stars[i].y, stars[i].size, stars[i].size);
}
// Draw cityscape buildings
fill(100); // Building color
for (let x = 50; x < width; x += 100) {
let buildingHeight = random(100, 300);
rect(x, height - buildingHeight, 80, buildingHeight);
// Windows in buildings
for (let y = height - buildingHeight + 20; y < height - 20; y += 40) {
for (let i = x + 10; i < x + 80; i += 20) {
fill(random(0, 200), random(0, 200), 0); // Random yellowish lights
rect(i, y, 10, 10);
}
}
}
}