let nStars = 5000;
nB = 50;
let starA = [];
let buildA = [];
function setup() {
cnv = createCanvas(windowWidth, windowHeight);
makeStars();
for (let i = 0; i < nB; i++) {
buildA.push(new Building());
}
angleMode(DEGREES);
}
function draw() {
background(30, 0, 255);
translate(width / 2, height / 2);
push();
t = frameCount / 30;
rotate(t);
showStars();
pop();
fill(0, 255, 157);
stroke(0, 255, 157);
strokeWeight(2);
line(20 * sin(t * 50), (height / 4) * sin(t * 10) - 100, 0, height / 2);
ellipse(20 * sin(t * 50), (height / 4) * sin(t * 10) - 100, 100, 120);
triangle(
20 * sin(t * 50),
(height / 4) * sin(t * 10) - 100,
20 * sin(t * 50) + 5,
(height / 4) * sin(t * 10) - 100 + 65,
20 * sin(t * 50) - 5,
(height / 4) * sin(t * 10) - 100 + 65
);
skyline();
circle(0, height / 2, 10);
}
function makeStars() {
for (let i = 0; i < nStars; i++) {
starA.push(new Star());
}
}
function showStars() {
fill(225, 255, 0);
noStroke();
for (let i = 0; i < nStars; i++) {
starA[i].display();
}
}
class Star {
constructor() {
this.x = random(-width, width);
this.y = random(-width, width);
this.r = random(0.5, 4);
}
display() {
circle(this.x, this.y, this.r);
}
}
class Building {
constructor() {
this.n = random(20, 40);
this.y = random(0, width / 2.5);
this.c = int(random(1, 4));
this.r = int(random(25, 40));
}
}
function skyline() {
x = -width / 2;
for (let i = 0; i < nB; i++) {
fill(255, 0, 97);
strokeWeight(1);
rect(x, buildA[i].y, buildA[i].n, width);
for (let j = 0; j < buildA[i].c; j++) {
for (let k = 0; k < buildA[i].r; k++) {
fill(225, 255, 0);
strokeWeight(0.1);
if (buildA[i].n <= 30) {
rect(x + 5, buildA[i].y + 15 * k, buildA[i].r / 1.2, buildA[i].c * 3);
}
if (buildA[i].n > 30) {
rect(x + 20, buildA[i].y + 15 * k, buildA[i].r / 4, buildA[i].c * 3);
rect(x + 3, buildA[i].y + 15 * k, buildA[i].r / 4, buildA[i].c * 3);
}
}
}
x = x + buildA[i].n;
}
}
function mousePressed() {
nStars = 5000;
nB = 50;
starA = [];
buildA = [];
makeStars();
for (let i = 0; i < nB; i++) {
buildA.push(new Building());
}
}