summaryrefslogtreecommitdiff
path: root/assets/javascripts/rectangles/rect.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2014-04-16 13:38:57 -0400
committerJules Laplace <jules@okfoc.us>2014-04-16 13:38:57 -0400
commite50348e6d5af52d0fcc51d0ca30e21594aee6cbf (patch)
tree0b026efbf344db78d8e02b3bba0d9b72fd12ea32 /assets/javascripts/rectangles/rect.js
parent862c7b01da400818c1035ffc3cd223db0a1545f6 (diff)
split out draw code
Diffstat (limited to 'assets/javascripts/rectangles/rect.js')
-rw-r--r--assets/javascripts/rectangles/rect.js93
1 files changed, 2 insertions, 91 deletions
diff --git a/assets/javascripts/rectangles/rect.js b/assets/javascripts/rectangles/rect.js
index 5f3a211..1d402cd 100644
--- a/assets/javascripts/rectangles/rect.js
+++ b/assets/javascripts/rectangles/rect.js
@@ -1,6 +1,6 @@
-window.rect = (function(){
- var FRONT = 0x1, BACK = 0x2, LEFT = 0x4, RIGHT = 0x8
+var FRONT = 0x1, BACK = 0x2, LEFT = 0x4, RIGHT = 0x8
+window.rect = (function(){
var rect = function (x0,y0,x1,y1){
if (x0 instanceof vec2) {
this.x = x0
@@ -42,38 +42,6 @@ window.rect = (function(){
}
rect.prototype.width = function(){ return this.x.length() }
rect.prototype.height = function(){ return this.y.length() }
- rect.prototype.fill = function(){
- // if (! this.sides) return this
- ctx.fillRect(this.x.a + this.translation.a, this.y.a + this.translation.b, this.x.length(), this.y.length())
- return this
- }
- rect.prototype.stroke_sides = function(){
- if (this.sides & FRONT) line(this.x.a, this.y.a, this.x.b, this.y.a)
- if (this.sides & BACK) line(this.x.a, this.y.b, this.x.b, this.y.b)
- if (this.sides & LEFT) line(this.x.a, this.y.a, this.x.a, this.y.b)
- if (this.sides & RIGHT) line(this.x.b, this.y.a, this.x.b, this.y.b)
-
- function line(a,b,c,d){
- ctx.beginPath()
- ctx.moveTo(a,b)
- ctx.lineTo(c,d)
- ctx.stroke()
- }
- return this
- }
- rect.prototype.stroke = function(){
- ctx.beginPath()
- ctx.moveTo(this.x.a, this.y.a)
- ctx.lineTo(this.x.b, this.y.b)
- ctx.stroke()
- return this
- }
- rect.prototype.perimeter = function(){
- line( this.x.a, this.y.a, this.x.b, this.y.a, this.translation )
- line( this.x.a, this.y.b, this.x.b, this.y.b, this.translation )
- line( this.x.a, this.y.a, this.x.a, this.y.b, this.translation )
- line( this.x.b, this.y.a, this.x.b, this.y.b, this.translation )
- }
rect.prototype.toString = function(){
var sides = ""
if (this.sides & FRONT) sides += "front "
@@ -180,63 +148,6 @@ window.rect = (function(){
})
return splits
}
-
- rect.prototype.walls = function(){
- var list = [], el = null
-
- var width = this.x.length()
- var depth = this.y.length()
- var height = 500
-
- if (this.sides & FRONT) {
- el = wall('.face.front')
- el.width = width
- el.height = height
- el.x = this.x.a + width/2
- el.z = this.y.a
- list.push(el)
- }
- if (this.sides & BACK) {
- var el = wall('.face.back')
- el.width = width
- el.height = height
- el.rotationY = PI
- el.x = this.x.b - width/2
- el.z = this.y.b
- list.push(el)
- }
-
- if (this.sides & LEFT) {
- el = wall('.face.left')
- el.rotationY = -HALF_PI
- el.height = height
- el.width = depth
- el.x = this.x.a
- el.z = this.y.a + depth/2
- list.push(el)
- }
-
- if (this.sides & RIGHT) {
- el = wall('.face.right')
- el.rotationY = HALF_PI
- el.height = height
- el.width = depth
- el.x = this.x.b
- el.z = this.y.b - depth/2
- list.push(el)
- }
-
- function wall(klass){
- var el = new MX.Object3D(klass || ".face")
- el.width = el.height = el.scaleX = el.scaleY = el.scaleZ = 1
- el.z = el.y = el.x = 0
- el.y = height/2
- el.type = "Face"
- return el
- }
-
- return list
- }
return rect