-
Notifications
You must be signed in to change notification settings - Fork 0
/
wall.js
99 lines (77 loc) · 2.26 KB
/
wall.js
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const canvasSketch = require('canvas-sketch');
const { lerp } = require('canvas-sketch-util/math');
const random = require('canvas-sketch-util/random');
const palettes = require('nice-color-palettes');
random.setSeed(random.getRandomSeed());
const settings = {
suffix: random.getSeed(),
dimensions: [ 2048, 2048 ]
};
const sketch = () => {
const palette = random.pick(palettes);
const createGrid = () => {
const points = [];
const count = 4;
for (let x = 0; x < count; x++) {
for (let y = 0; y < count - 1; y++) {
const u = x / (count - 1);
const v = y / (count - 1);
points.push([ u, v ]);
}
}
return points;
};
const bgColor = '#303030';
const margin = 0;
return ({ context, width, height }) => {
const lineWidth = Math.round(0.01 * width);
context.fillStyle = bgColor;
context.fillRect(0, 0, width, height);
const points = random.shuffle(createGrid());
const figures = [];
while (points.length) {
const p1 = points.pop();
const p2 = points.pop();
console.log(p1, p2);
const p1x = lerp(margin, width - margin, p1[0]);
const p1y = lerp(margin, height - margin, p1[1]);
const p2x = lerp(margin, width - margin, p2[0]);
const p2y = lerp(margin, height - margin, p2[1]);
const p3x = p2x;
const p3y = lerp(margin, height - margin, 1);
const p4x = p1x;
const p4y = p3y;
figures.push({
p1x, p1y,
p2x, p2y,
p3x, p3y,
p4x, p4y,
s: Math.max(p1y, p2y)
});
}
figures.sort((f1, f2) => f1.s - f2.s);
for (let figure of figures) {
const {
p1x, p1y,
p2x, p2y,
p3x, p3y,
p4x, p4y,
} = figure;
context.beginPath();
context.moveTo(p1x, p1y);
context.lineTo(p2x, p2y);
context.lineTo(p3x, p3y);
context.lineTo(p4x, p4y);
context.lineWidth = lineWidth;
context.shadowColor = 'RGBA(48, 48, 48, 0.8)';
context.shadowBlur = lineWidth * 2;
context.shadowOffsetX = 0;
context.shadowOffsetY = -lineWidth / 2;
context.strokeStyle = 'transparent';
context.stroke();
context.fillStyle = random.pick(palette);
context.fill();
}
};
};
canvasSketch(sketch, settings);