-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw.js
45 lines (36 loc) · 1.09 KB
/
draw.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
const WORLD_WIDTH = 40;
const WORLD_HEIGHT = 30;
let canvas = null;
let useGL = false;
function initializeGraphics() {
// Create new canvas, so we get a new context
canvas = document.getElementById('c');
let new_canvas = canvas.cloneNode(false);
canvas.parentNode.replaceChild(new_canvas, canvas);
canvas = new_canvas;
canvas.addEventListener('click', clickEscape); // Keep responding to click
let dpi = window.devicePixelRatio;
// Get CSS Dimensions
let style_height =
+getComputedStyle(canvas).getPropertyValue("height").slice(0, -2);
let style_width =
+getComputedStyle(canvas).getPropertyValue("width").slice(0, -2);
// Scale the canvas
canvas.setAttribute('width', style_width * dpi);
tile_size = Math.round((style_width * dpi) / WORLD_WIDTH);
canvas.setAttribute('height', WORLD_HEIGHT * tile_size);
let renderer = document.querySelector('input[name="renderer"]:checked').value;
console.log("Renderer: " + renderer);
useGL = renderer == "gl";
if (useGL)
initializeGL();
else
initializeCanvas();
}
function draw() {
if (useGL) {
drawGL();
} else {
drawCanvas();
}
}