-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtutorial1.js
41 lines (31 loc) · 952 Bytes
/
tutorial1.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
// Tiled Lines
var canvas = document.querySelector('canvas');
var context = canvas.getContext('2d');
var size = window.innerWidth;
var dpr = window.devicePixelRatio;
canvas.width = size * dpr / 2;
canvas.height = size * dpr / 2;
context.scale(dpr, dpr);
context.lineCap = 'square';
context.lineWidth = 2;
console.log("gm")
console.log(`Canvas - [size: ${size}, dpr: ${dpr}, width: ${canvas.width}, height: ${canvas.height}`)
function draw(x, y, width, height) {
var leftToRight = Math.random() >= 0.5;
if (leftToRight) {
context.moveTo(x, y)
context.lineTo(x + width, y + height)
} else {
context.moveTo(x + width, y)
context.lineTo(x, y + height)
}
context.stroke();
setTimeout(() => {}, 10) // Avoid freezing browser
}
// draw(0, 0, size, size);
var step = 20
for (var x = 0; x < size; x += step) {
for (var y = 0; y < size; y += step) {
draw(x, y, step, step)
}
}