summaryrefslogtreecommitdiff
path: root/assets/javascripts/rectangles/map/draw.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2014-05-05 15:56:07 -0400
committerJules Laplace <jules@okfoc.us>2014-05-05 15:56:07 -0400
commit9f4204d35f1dbd861417cd8a04bb26c46299f55a (patch)
tree79a6f43198f38dba10de55d47c3995b83a29d263 /assets/javascripts/rectangles/map/draw.js
parent79b0e1b0a127260978c69165466953ae86f6d6b2 (diff)
happy with refactor
Diffstat (limited to 'assets/javascripts/rectangles/map/draw.js')
-rw-r--r--assets/javascripts/rectangles/map/draw.js162
1 files changed, 0 insertions, 162 deletions
diff --git a/assets/javascripts/rectangles/map/draw.js b/assets/javascripts/rectangles/map/draw.js
deleted file mode 100644
index b2fc05f..0000000
--- a/assets/javascripts/rectangles/map/draw.js
+++ /dev/null
@@ -1,162 +0,0 @@
-
-map.draw = new function(){
-
- var base = this
-
- base.animate = function(){
- ctx.save()
- map.draw.clear_canvas()
- map.draw.ruler()
-
- ctx.translate( map.bounds.a * 1/2, map.bounds.b * 1/2)
- ctx.scale( map.zoom, map.zoom )
- ctx.translate( map.center.a, map.center.b)
- ctx.scale( -1, 1 )
-
- map.draw.regions(Rooms.regions)
- map.draw.mouse(map.ui.mouse.cursor)
- map.draw.coords()
- scene && map.draw.camera(scene.camera)
-
- ctx.restore()
- }
-
- base.clear_canvas = function(){
- ctx.fillStyle = "rgba(255,255,255,0.99)"
- ctx.clearRect(0,0,w,h)
- ctx.fillRect(0,0,w,h)
- }
-
- base.ruler = function (){
- ctx.strokeStyle = "rgba(80,80,80,0.5)"
- ctx.lineWidth = 1
- var len = 5
- for (var i = 0.5; i < w; i += 10) {
- line(i, 0, i, len)
- line(0, i, len, i)
- }
- }
-
- base.regions = function(regions){
- for (var i = 0; i < regions.length; i++) {
- if (regions[i].dupe) continue
- ctx.fillStyle = colors[i % colors.length]
- fill_region(regions[i])
- stroke_sides(regions[i])
- }
- }
-
- base.mouse = function(mouse){
- var radius = 3 / map.zoom
-
- ctx.fillStyle = "rgba(255,0,0,0.4)";
- ctx.beginPath();
- ctx.arc(mouse.x.b, mouse.y.b, radius, 0, 2*Math.PI, false);
- ctx.fill();
-
- if (mouse.width() != 0 && mouse.height() != 0) {
- if (map.ui.dragging) {
- stroke_rect(mouse)
- }
- else {
- ctx.fillStyle = "rgba(255,255,0,0.5)"
- fill_region( mouse.clone().translate() )
- }
- }
- }
-
- base.camera = function(cam){
- ctx.lineWidth = 0.5
-
- ctx.save()
-
- ctx.translate(cam.x, cam.z)
- ctx.rotate(cam.rotationY)
-
- var radius = 3 / map.zoom
-
- ctx.fillStyle = '#888';
-
- ctx.beginPath();
- ctx.moveTo(0,0)
- ctx.lineTo(-radius,-radius/2)
- ctx.lineTo(0,radius*3)
- ctx.lineTo(radius,-radius/2)
- ctx.moveTo(0,0)
- ctx.fill()
-
- ctx.restore()
- }
-
- base.coords = function(){
- ctx.fillStyle = "#888";
- dot_at(0,0)
- ctx.fillStyle = "#bbb";
- dot_at(100,0)
- dot_at(0,100)
- ctx.fillStyle = "#ddd";
- dot_at(200,0)
- dot_at(0,200)
- ctx.fillStyle = "#eee";
- dot_at(300,0)
- dot_at(0,300)
-
- ctx.strokeStyle = "rgba(0,0,0,0.1)"
- ctx.lineWidth = 1/map.zoom
-
- var sides = map.sides()
- var quant = sides.clone().quantize(200)
- for (var x = quant.x.a - 200; x <= quant.x.b; x += 200) {
- line(x, sides.y.a, x, sides.y.b)
- }
- for (var y = quant.y.a - 200; y <= quant.y.b; y += 200) {
- line(sides.x.a, y, sides.x.b, y)
- }
- }
-
- //
-
- function line (x,y,a,b,translation){
- if (translation) {
- x += translation.a
- a += translation.a
- y += translation.b
- b += translation.b
- }
- ctx.beginPath()
- ctx.moveTo(x,y)
- ctx.lineTo(a,b)
- ctx.stroke()
- }
-
- function fill_region(r){
- ctx.fillRect(r.x.a + r.translation.a,
- r.y.a + r.translation.b,
- r.x.length(),
- r.y.length())
- }
-
- function stroke_sides (r){
- if (r.sides & FRONT) line(r.x.a, r.y.a, r.x.b, r.y.a)
- if (r.sides & BACK) line(r.x.a, r.y.b, r.x.b, r.y.b)
- if (r.sides & LEFT) line(r.x.a, r.y.a, r.x.a, r.y.b)
- if (r.sides & RIGHT) line(r.x.b, r.y.a, r.x.b, r.y.b)
- }
-
- function stroke_rect (r){
- line(r.x.a, r.y.a, r.x.b, r.y.b, r.translation)
- }
-
- function dot_at (x,z){
- ctx.save()
- ctx.translate(x,z)
-
- var radius = 2 / map.zoom
-
- ctx.beginPath();
- ctx.arc(0, 0, radius, 0, 2*Math.PI, false);
- ctx.fill();
-
- ctx.restore()
- }
-} \ No newline at end of file