This repository has been archived by the owner on Oct 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcanvasSetup.js
48 lines (45 loc) · 1.62 KB
/
canvasSetup.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
// Whole thing is just canvas setup
const c = document.querySelector("canvas"); // get the only canvas element
const draw = c.getContext('2d'); // get canvas context
c.width = document.body.clientWidth; // make canvas full screen
c.height = document.body.clientHeight;
const mixed3dC = document.createElement('canvas');
mixed3dC.width = 8000;
mixed3dC.height = 8000;
mixed3dC.style.position = "absolute";
mixed3dC.id = 'mixed-3d-graphics';
mixed3dC.hidden = true;
const mixed3dDraw = mixed3dC.getContext('2d');
document.body.appendChild(mixed3dC);
const mixed2dC = document.createElement('canvas');
mixed2dC.width = 8000;
mixed2dC.height = 8000;
mixed2dC.style.position = "absolute";
mixed2dC.id = 'mixed-2d-graphics';
mixed2dC.hidden = true;
const mixed2dDraw = mixed2dC.getContext('2d',{alpha: false});
document.body.appendChild(mixed2dC);
// add an off screen canvas for image rotation and such
const osC = document.createElement('canvas');
osC.width = 15266;
osC.height = 7357;
osC.style.position = "absolute";
osC.id = 'off-screen-canvas';
osC.hidden = true;
const osDraw = osC.getContext('2d');
document.body.appendChild(osC);
// add an off screen canvas for drawing the map without transformations
const osC2 = document.createElement('canvas');
osC2.width = 8000;
osC2.height = 8000;
osC2.style.position = "absolute";
osC2.id = 'off-screen-canvas-2';
osC2.hidden = true;
const osDraw2 = osC2.getContext('2d');
document.body.appendChild(osC2);
//Saves canvas state
draw.save();
// transforms final rendered map
osDraw.translate(osC.width / 2, 0);
osDraw.rotate(Math.PI / 4); //rotate 45 degrees
osDraw.transform(1, -0.35, -0.35, 1, 0, 0); //skew