Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdevz committed Apr 26, 2024
1 parent 56ebaaa commit d2f28be
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 0 deletions.
118 changes: 118 additions & 0 deletions art/citySnow-alex/index.js
@@ -0,0 +1,118 @@
/*
@title: City at Night - Snowflakes Edition
@author: alexdevz
@snapshot: snowflake-city
*/

const buildingCount = 7;
const minBuildingWidth = 10;
const maxBuildingWidth = 20;
const minBuildingHeight = 20;
const maxBuildingHeight = 100;
const buildingColors = ['gray', 'darkgray', 'lightgray'];
const windowColor = 'yellow';
const windowSize = 2;
const moonRadius = 10;
const moonColor = 'white';
const snowflakeCount = 100;
const snowflakeColor = 'white';
const snowflakeSize = 0.5;
const skyColor = 'black';

setDocDimensions(125, 125);

function randomInRange(min, max) {
return Math.random() * (max - min) + min;
}

function randomColor() {
const index = Math.floor(Math.random() * buildingColors.length);
return buildingColors[index];
}

function sky() {
const bottomLeft = [0, 0];
const topLeft = [0, 125];
const topRight = [125, 125];
const bottomRight = [125, 0];
return [bottomLeft, topLeft, topRight, bottomRight, bottomLeft];
}

const skyPoints = sky();
drawLines([skyPoints], { fill: skyColor });

//buildings and windows
function building(x, width, height) {
const bottomLeft = [x, 0];
const bottomRight = [x + width, 0];
const topLeft = [x, height];
const topRight = [x + width, height];
return [bottomLeft, topLeft, topRight, bottomRight, bottomLeft];
}

function windows(x, width, height) {
const windows = [];
for (let i = x + windowSize; i < x + width; i += windowSize * 2) {
for (let j = windowSize; j < height; j += windowSize * 2) {
const window = [
[i, j],
[i + windowSize, j],
[i + windowSize, j + windowSize],
[i, j + windowSize],
[i, j]
];
windows.push(window);
}
}
return windows;
}
//moon
function moon() {
const moon = [];
const centerX = moonRadius;
const centerY = 125 - moonRadius;
for (let i = 0; i <= 360; i += 5) {
const angle = i * Math.PI / 180;
const x = centerX + moonRadius * Math.cos(angle);
const y = centerY + moonRadius * Math.sin(angle);
moon.push([x, y]);
}
return moon;
}

drawLines([moon()], { fill: moonColor });

//building
let x = 0;
for (let i = 0; i < buildingCount; i++) {
const width = randomInRange(minBuildingWidth, maxBuildingWidth);
const height = randomInRange(minBuildingHeight, maxBuildingHeight);
const buildingPoints = building(x, width, height);
drawLines([buildingPoints], { fill: randomColor() });
const windowPoints = windows(x, width, height);
drawLines(windowPoints, { fill: windowColor });
x += width;
}

//snow
function snowflake(x, y) {
const topLeft = [x, y];
const topRight = [x + snowflakeSize, y];
const bottomRight = [x + snowflakeSize, y + snowflakeSize];
const bottomLeft = [x, y + snowflakeSize];
return [topLeft, topRight, bottomRight, bottomLeft, topLeft];
}

for (let i = 0; i < snowflakeCount; i++) {
let x = randomInRange(0, 125);
let y = randomInRange(0, 125);

// avoid moon
while (Math.sqrt(Math.pow(x - moonRadius, 2) + Math.pow(y - (125 - moonRadius), 2)) < moonRadius) {
x = randomInRange(0, 125);
y = randomInRange(0, 125);
}

const snowflakePoints = snowflake(x, y);
drawLines([snowflakePoints], { fill: snowflakeColor });
}
Binary file added art/citySnow-alex/snapshots/0.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added art/citySnow-alex/snapshots/1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added art/citySnow-alex/snapshots/2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d2f28be

Please sign in to comment.