-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathsketch.js
More file actions
36 lines (26 loc) · 1017 Bytes
/
Copy pathsketch.js
File metadata and controls
36 lines (26 loc) · 1017 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import Crystal from './Crystal.js';
import { favicon } from './util.js';
window.setup = () => {
createCanvas(windowWidth, windowHeight);
noLoop();
angleMode(DEGREES);
rectMode(RADIUS);
}
window.draw = () => {
const CRYSTAL_SIZE_MAX = 150;
const GAP_MIN = 10;
const crystalSize = min(CRYSTAL_SIZE_MAX, min(windowWidth, windowHeight) - 2 * GAP_MIN);
const cols = int((windowWidth - GAP_MIN) / (crystalSize + GAP_MIN));
const rows = int((windowHeight - GAP_MIN) / (crystalSize + GAP_MIN));
const gapHor = (windowWidth - cols * crystalSize) / (cols + 1);
const gapVer = (windowHeight - rows * crystalSize) / (rows + 1);
for (let i = 0; i < cols * rows; i++) {
const x = gapHor + crystalSize / 2 + (i % cols) * (crystalSize + gapHor);
const y = gapVer + crystalSize / 2 + int(i / cols) * (crystalSize + gapVer);
new Crystal(x, y, crystalSize).render();
}
favicon(displayDensity(), crystalSize, gapHor, gapVer);
}
window.windowResized = () => {
resizeCanvas(windowWidth, windowHeight);
}