This repository has been archived by the owner on Jan 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
old.html
153 lines (133 loc) · 4.43 KB
/
old.html
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Viewer</title>
<style>
* {
margin: 0;
}
body, canvas {
width: 100vw;
height: 100vh;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<script>
var name = 'polus'
var resScale = 1.5;
var posoffx = 810;
var posoffy = 320;
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
const fs = require('fs');
const data = JSON.parse(fs.readFileSync("./" + name + "-colliders.json", 'utf-8'))
canvas.width = document.body.clientWidth; //document.width is obsolete
canvas.height = document.body.clientHeight; //document.height is obsolete
ctx.fillStyle = "red";
ctx.font = "10px Arial"
ctx.lineWidth = resScale;
let ccc = 1
var translateCoordinate = (o, c) => {
return {
x: (((o.x + c.position.x + c.offset.x * ccc) * 100) + canvas.width / 2) /resScale - posoffx,
y: (-((o.y + c.position.y + c.offset.y * ccc) * 100) + canvas.height / 2) /resScale - posoffy
}
}
var drawPolygon = (polygon) => {
polygon.points[polygon.points.length] = polygon.points[0]
drawEdge(polygon)
ctx.globalAlpha = 0.1
ctx.fill()
ctx.globalAlpha = 1
}
let aaa = 2
let bbb = 99999999999999
var drawBox = (collider) => {
var coords = [
{ x: 0 - collider.size.x / aaa, y: 0 - collider.size.y / aaa },
{ x: 0 + collider.size.x / aaa, y: 0 - collider.size.y / aaa },
{ x: 0 + collider.size.x / aaa, y: 0 + collider.size.y / aaa },
{ x: 0 - collider.size.x / aaa, y: 0 + collider.size.y / aaa },
{ x: 0 - collider.size.x / aaa, y: 0 - collider.size.y / aaa }
]
collider.points = coords;
drawEdge(collider)
ctx.globalAlpha = 0.1
ctx.fill()
ctx.globalAlpha = 1
}
var drawEdge = (collider) => {
ctx.beginPath();
for (let i = 0; i < collider.points.length; i++) {
const point = translateCoordinate(collider.points[i], collider);
ctx.lineTo(point.x, point.y)
}
ctx.stroke();
}
var drawCollider = (collider) => {
return collider.name.toLowerCase()//.startsWith('shadow')
// return collider.type == "polygon"
}
var img = document.createElement('img');
img.src = './polus.jpg';
img.onload = () => {
let render = () => {
ctx.fillStyle = "white";
ctx.fillRect(0, 0, canvas.width, canvas.height);
if (name == 'polus') {
ctx.globalAlpha = 0.5
ctx.drawImage(img, 0, 0,img.width, img.height, (-posoffx + (810*1/(resScale/1.5))), (-posoffy + (320 * 1/(resScale / 1.5))), img.width*(1/(resScale) * 1.5), img.height * (1 / (resScale) * 1.5))
ctx.globalAlpha = 1
}
data.forEach(collider => {
if (!drawCollider(collider)) return
switch (collider.type) {
case 'polygon':
ctx.strokeStyle = "#ff0000"
ctx.fillStyle = "#ff0000"
drawPolygon(collider);
break;
case 'box':
ctx.strokeStyle = "#00ff00"
ctx.fillStyle = "#00ff00"
drawBox(collider);
break;
case 'edge':
ctx.strokeStyle = "#0000ff"
ctx.fillStyle = "#0000ff"
drawEdge(collider);
break;
}
ctx.fillStyle = "black";
let textpos = translateCoordinate(collider.points ? collider.points[0] : collider.size, collider)
ctx.fillText(collider.name + "," + collider.position.x, textpos.x, textpos.y);
})
}
setInterval(render, 10)
}
document.body.onwheel = (event) => {
resScale += event.deltaY/1000
}
document.body.onkeydown = (event) => {
switch(event.key) {
case 'w':
posoffy -= 10
break;
case 's':
posoffy += 10
break;
case 'a':
posoffx -= 10
break;
case 'd':
posoffx += 10
break;
}
}
</script>
</body>
</html>