====== Surprising Space: Geometry ======
By: [[yuna-wu|Yuna Wu]]
let x, y;
var stars = [];
function setup() {
createCanvas(1920, 1080);
//Stars
for (var i = 0; i < 1000; i++) {
stars[i] = new Star();
}
}
// star class //
class Star {
constructor() {
this.x = random(width);
this.y = random(height);
this.size = random(0.25, 3);
this.t = random(TAU);
}
draw() {
this.t += 0.1;
var scale = this.size + sin(this.t) * 2;
fill(255)
noStroke();
ellipse(this.x, this.y, scale, scale);
}
}
class Building {
constructor(positionX, positionY, size) {
this.x = positionX;
this.y = positionY;
this.size = size;
}
draw() {
fill(240, 235, 221);
ellipse(996, 406, 605, 305);
fill(180, 208, 240);
ellipse(996, 276, 405, 345);
}
}
class Earth {
constructor(positionX, positionY, size) {
this.x = positionX;
this.y = positionY;
this.size = size;
}
draw() {
fill(14, 75, 173);
ellipse(96, 1006, 405, 405);
fill(15, 145, 49);
ellipse(96, 906, 95, 55);
ellipse(36, 1006, 105, 55);
ellipse(150, 1086, 95, 55);
}
}
//Rockets class
class Rocket {
constructor(startingX, startingY) {
this.positionX = startingX;
this.positionY = startingY
}
draw() {
translate(this.positionX+180,this.positionY+50);
rotate(radians(-10));
fill(191, 187, 187);
rect(200, 250, 95, 155, 20);
fill(201, 71, 71);
triangle(200, 265, 295, 265, 248, 175);
ellipse(248, 306, 55, 55);
fill(186, 219, 230);
ellipse(248, 306, 45, 45);
noFill();
stroke(255);
resetMatrix();
}
}
function draw() {
background(1, 3, 28);
//stars
for (var i = 0; i < stars.length; i++) {
stars[i].draw();
}
//building
let building1 = new Building(10, 10, 10)
building1.draw();
let earth1 = new Earth(10, 10, 10)
earth1.draw();
//rocket
let rockets1 = new Rocket(10, 10)
rockets1.draw();
//rocket
colorMode(RGB, 255)
let g2 = drawingContext.createLinearGradient(280,250, 150,800);
g2.addColorStop(0, color(255));
g2.addColorStop(0.2, color(255, 180, 0));
g2.addColorStop(1, color(45, 3, 0));
drawingContext.fillStyle = g2;
translate(this.positionX+180,this.positionY+50);
rotate(radians(-10));
ellipse(426, 620, 95, 485);
resetMatrix();
let g3 = drawingContext.createLinearGradient(350, 340, 250,500);
g3.addColorStop(0, color(255));
g3.addColorStop(0.5, color(255, 249, 194));
g3.addColorStop(0.9, color(194, 164, 16));
g3.addColorStop(1, color(200, 100, 0));
drawingContext.fillStyle = g3;
translate(this.positionX+180,this.positionY+50);
rotate(radians(-10));
ellipse(426, 520, 75, 205);
resetMatrix();
}
Back to [[yuna-wu|Yuna Wu's Page]]