xxxxxxxxxx
132
let stars = [];
function setup() {
createCanvas(400, 400);
background(0);
drawStars(100);
}
function draw() {
background(0);
// Displaying the stars and updating
for (let i = 0; i < stars.length; i++) {
let star = stars[i];
star.y += star.speed; //star goes downwards
if (star.y > height) {
star.y = 0; // Reset star's position if it goes off-screen
}
fill(255);
ellipse(star.x, star.y, 4.5, 4.5);
}
// Space Suit //
// Body
fill(255);
rect(115, 237, 160, 180);
rect(158, 272, 70, 50);
// Buttons on the Suit
fill(0);
rect(164, 280, 10, 10);
rect(187, 280, 10, 10);
rect(210, 280, 10, 10);
fill(255, 204, 0);
rect(164, 310, 10, 10);
fill(255, 195, 200);
rect(187, 310, 10, 10);
fill(175, 100, 220);
rect(210, 310, 10, 10);
// Space suit helmet or snoopy cap
fill(255);
ellipse(190, 165, 150, 163);
ellipse(190, 160, 160, 150);
// Arms
fill(255);
rect(79, 243, 40, 160);
rect(272, 243, 40, 160);
// Buttons on Arms
fill(0);
rect(84, 290, 30, 50);
rect(277, 290, 30, 50);
// Face
fill(226, 190, 168);
ellipse(190, 165, 130, 130);
// Eyes
fill(255);
ellipse(160, 145, 27, 18);
fill(0);
circle(160, 144, 15);
fill(255);
ellipse(213, 145, 27, 18);
fill(0);
circle(213, 144, 15);
// Nose
fill(0);
triangle(190, 175, 195, 160, 185, 160);
// Eyelashes left eye
drawLashes(165, 146, -1);
// Eyelashes right eye
drawLashes(165 + 40, 146, 1);
// Planets //
fill(255, 140, 0); // Dark orange
ellipse(58, 90, 45, 45);
fill(173, 216, 230); // Light blue
ellipse(342, 50, 60, 60);
fill(100, 255, 100); // Green
ellipse(352, 145, 30, 30);
}
// Stars in the background
function drawStars(numStars) {
// white dots as stars
fill(255);
for (let i = 0; i < numStars; i++) {
stars.push({
x: random(width),
y: random(height),
speed: random(0.5, 2), //speed for every star
});
}
}
// Lashes
function drawLashes(x, y, direction) {
// direction: 1 for the right eye, -1 for the left eye
fill(0);
let numLashes = 4;
let lashLength = 6;
strokeWeight(2);
for (let i = 0; i < numLashes; i++) {
let lashX = x + direction * i * 5; // x-coordinate
let lashY1 = y - 9; // Y-coordinate for the top of the eyelash
let lashY2 = y - 9 - lashLength; // Y-coordinate for the bottom of the eyelash
line(lashX, lashY1, lashX, lashY2); // Drawing the eyelash
}
// Smile or mouth
noFill();
stroke(0);
strokeWeight(2);
arc(190, 190, 50, 20, 0, PI);
}