-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcanvas.js
51 lines (40 loc) · 1.44 KB
/
canvas.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
/** @type {HTMLCanvasElement} */
const canvas = document.getElementById("canvas-main-layer");
const ctx = canvas.getContext("2d");
const bgColor = "#3a3a3b";
/** @type {HTMLCanvasElement} */
const highlightCanvas = document.getElementById("canvas-highlight-layer");
const highlightCtx = highlightCanvas.getContext("2d");
const curve = new HermiteCurve(0.01, "green", 2, ctx, highlightCtx);
window.addEventListener("resize", resizeCanvas, false);
function resizeCanvas() {
/** @type {HTMLDivElement} */
const container = document.querySelector(".canvas-container");
canvas.width = container.clientWidth - 20;
canvas.height = window.innerHeight - 20;
highlightCanvas.width = container.clientWidth - 20;
highlightCanvas.height = window.innerHeight - 20;
/**
* Your drawings need to be inside this function otherwise they will be reset when
* you resize the browser window and the canvas goes will be cleared.
*/
ctx.fillStyle = bgColor;
ctx.fillRect(0, 0, canvas.width, canvas.height);
curve.draw();
}
resizeCanvas();
function canvasCursorGrab() {
canvas.style.cursor = "grab";
}
function canvasCursorGrabbing() {
canvas.style.cursor = "grabbing";
}
function canvasCursorDelete() {
canvas.style.cursor = "url('resources/delete-icon.svg') 15 15, crosshair";
}
function canvasCursorReset() {
canvas.style.cursor = null;
}
function clearHighlights() {
highlightCtx.clearRect(0, 0, highlightCanvas.width, highlightCanvas.height);
}