-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
42 lines (32 loc) · 998 Bytes
/
main.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
function draw(ctx) {
// Clear the canvas
ctx.setTransform(1, 0, 0, 1, 0, 0);
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
// Center the canvas
ctx.translate(ctx.canvas.width / 2, ctx.canvas.height / 2);
// Styles
ctx.strokeStyle = '#333';
ctx.lineWidth = 2;
drawDragon(ctx, 0);
}
// TODO
function drawDragon(ctx, n) {
// Feel free to modify anything, adjust function signatures, add functions, etc. as you like :)
drawLine(ctx, -200, 0, 200, 0);
}
function drawLine(ctx, x1, y1, x2, y2) {
ctx.beginPath();
ctx.moveTo(x1, y1);
ctx.lineTo(x2, y2);
ctx.stroke();
}
// Some biolerplate to draw on the fullscreen canvas
const canvas = document.getElementById('canvas');
const context = canvas.getContext('2d');
function onResize() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
draw(context);
}
window.addEventListener('load', onResize);
window.addEventListener('resize', onResize);