-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsketch-01.js
More file actions
64 lines (50 loc) · 1.66 KB
/
Copy pathsketch-01.js
File metadata and controls
64 lines (50 loc) · 1.66 KB
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
const canvasSketch = require('canvas-sketch');
const random = require('canvas-sketch-util/random');
import { getRandomColor } from './colors.js'
const settings = {
dimensions: [ 1080, 1080 ]
};
const sketch = () => {
return ({ context, width, height }) => {
context.fillStyle = 'white';
context.fillRect(0, 0, width, height);
const w = width * 0.1;
const h = height * 0.1;
const gap = width * 0.03;
const ix = width * 0.17;
const iy = height * 0.17;
const drawCanvas = () => {
for (let i = 0; i < 5; i++) {
for (let j = 0; j < 5; j++) {
const x = ix + (w + gap) * i;
const y = iy + (w + gap) * j;
const rdn = random.range(1, 35)
context.lineWidth = random.range(1 ,10);
context.beginPath();
context.rect(x, y, w, h);
context.strokeStyle = getRandomColor()
context.stroke();
if ( Math.random() > 0.5 ) {
context.lineWidth = random.range(1 ,10);
context.beginPath();
context.rect(x + rdn, y + rdn, w - rdn*2, h - rdn*2)
context.strokeStyle = getRandomColor()
context.stroke();
}
}
}
}
drawCanvas();
// clearCanvas = () => {
// context.clearRect(0, 0, width, height)
// }
// const interval = setInterval( () => {
// drawCanvas();
// }, 100);
// const interval2 = setInterval( () => {
// clearCanvas();
// drawCanvas();
// }, 5000);
};
};
canvasSketch(sketch, settings);