-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcanvasDrawJS.js
61 lines (47 loc) · 1.08 KB
/
canvasDrawJS.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
/*
Barak Stout
*/
// ---------------- //
// Config Variables //
// ---------------- //
// size of the grid
var size = 20;
// color of the grid
var gridColor = "gray";
// the canvas ID from the HTML protion
var canvasID = "canvas";
// ---------------- //
// Global Variables //
// ---------------- //
var canvas = document.getElementById(canvasID);
var context = canvas.getContext("2d");
var canvasWidth = canvas.width;
var canvasHeight = canvas.height;
// ---------- //
// drawGrid() //
// ---------- //
function drawGrid()
{
for (var y = 0; y <= canvasWidth; y += size)
{
context.moveTo(y, 0);
context.lineTo(y, canvasHeight);
}
for (var x = 0; x <= canvasHeight; x += size)
{
context.moveTo(0, x);
context.lineTo(canvasWidth, x);
}
context.strokeStyle = gridColor;
context.stroke();
// go back to defualt color
context.strokeStyle = "black";
}
// --------------------- //
// consolePrintMouseXY() //
// --------------------- //
function consolePrintMouseXY(event)
{
var coords = "(x,y): (" + event.clientX + "," + event.clientY + ")";
console.log(coords);
}