-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminimalistic_waves.js
67 lines (48 loc) · 1.55 KB
/
minimalistic_waves.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
const canvasSketch = require('canvas-sketch');
const random = require('canvas-sketch-util/random');
const math = require('canvas-sketch-util/math');
const settings = {
dimensions: [ 1080, 1080 ],
animate: true
};
const sketch = () => {
return ({ context, width, height, frame }) => {
context.fillStyle = 'white';
context.fillRect(0, 0, width, height);
const cols = 10;
const rows = 10;
const numCells = cols * rows;
const gridw = width * 0.8;
const gridh = height * 0.8;
const cellw = gridw / cols;
const cellh = gridh / rows;
const margx = (width - gridw) * 0.5;
const margy = (height - gridh) * 0.5;
for (let i = 0; i < numCells; i++) {
const col = i % cols;
const row = Math.floor(i / cols);
const x = col * cellw;
const y = row * cellh;
const w = cellw * 0.8;
const h = cellh * 0.8;
// add reference to frame here to have the sketch move
const n = random.noise2D(x + frame*20, y, 0.001);
const angle = n * Math.PI * 0.2;
//const scale = (n + 1) / 2 * 30;
//const scale = (n * 0.5 + 0.5) * 30;
const scale = math.mapRange(n, -1, 1, 1, 30);
context.save();
context.translate(x, y);
context.translate(margx, margy);
context.translate(cellw*0.5, cellh*0.5);
context.rotate(angle);
context.lineWidth = scale;
context.beginPath();
context.moveTo(w * -0.5, 0);
context.lineTo(w * 0.5, 0);
context.stroke();
context.restore();
}
};
};
canvasSketch(sketch, settings);