-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch_3.js
60 lines (49 loc) · 1.44 KB
/
sketch_3.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
//Random Colours on Grid of Double Squares - Swatch
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");
const settings = {
dimensions: [1080, 1080],
};
const sketch = () => {
const createGrid = () => {
const points = [];
const count = 10;
for (let x = 0; x < count; x++) {
for (let y = 0; y < count; y++) {
const u = x / (count - 1);
const v = y / (count - 1);
points.push({
position: [u, v],
radius: 25,
});
}
}
return points;
};
const points = createGrid();
const margin = 0;
return {
render(props) {
const { context, width, height } = props;
points.forEach((point) => {
const { position } = point;
const [u, v] = position;
const x = lerp(margin, width - margin, u);
const y = lerp(margin, height - margin, v);
context.beginPath();
context.rect(x - 120, y - 120, 180, 180);
context.fillStyle = random.pick(random.pick(palettes));
context.fill();
context.closePath();
context.beginPath();
context.arc(x - 60, y - 120, 20, 0, Math.PI * 2);
context.fillStyle = random.pick(random.pick(palettes));
context.fill();
context.closePath();
});
},
};
};
canvasSketch(sketch, settings);