blob: b62a8131e250d8b20a59158ba3fa5be4ff68ff86 (
plain)
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
|
/*
*/
window.ctx = window.w = window.h = null;
var map = new function(){
var base = this
base.el = document.querySelector("#map")
if (! base.el) return
base.dimensions = new vec2(window.innerWidth, window.innerHeight)
base.bounds = new vec2(window.innerWidth, window.innerHeight)
base.center = new vec2(0,0)
base.sides = function(){
var sides = base.bounds.clone().div(2).div(base.zoom)
return new Rect( base.center.a - sides.a, -base.center.b - sides.b,
base.center.a + sides.a, -base.center.b + sides.b )
}
base.zoom = 1/8
base.zoom_exponent = -3
base.set_zoom = function (n) {
base.zoom_exponent = n
base.zoom = pow(2, base.zoom_exponent)
}
var canvas = document.createElement("canvas")
var ctx = window.ctx = canvas.getContext("2d")
var w = window.w = canvas.width = base.dimensions.a
var h = window.h = canvas.height = base.dimensions.b
document.querySelector("#map").appendChild(canvas)
base.update = function(){
base.draw.animate()
}
base.toggle = function(){
$(base.el).toggle()
}
}
|