summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/rectangles/models
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/javascripts/rectangles/models')
-rw-r--r--public/assets/javascripts/rectangles/models/rect.js6
-rw-r--r--public/assets/javascripts/rectangles/models/vec2.js3
-rw-r--r--public/assets/javascripts/rectangles/models/wall.js20
3 files changed, 20 insertions, 9 deletions
diff --git a/public/assets/javascripts/rectangles/models/rect.js b/public/assets/javascripts/rectangles/models/rect.js
index cb14e66..a4fbd87 100644
--- a/public/assets/javascripts/rectangles/models/rect.js
+++ b/public/assets/javascripts/rectangles/models/rect.js
@@ -25,6 +25,12 @@ window.Rect = (function(){
Rect.prototype.area = function(){
return this.x.length() * this.y.length()
}
+ Rect.prototype.magnitude = function(){
+ return dist(this.x.a, this.y.a, this.x.b, this.y.b)
+ }
+ Rect.prototype.maxDimension = function(){
+ return abs(this.width) > abs(this.height) ? this.width : this.height
+ }
Rect.prototype.mul = function(n){
this.x.mul(n)
diff --git a/public/assets/javascripts/rectangles/models/vec2.js b/public/assets/javascripts/rectangles/models/vec2.js
index e56a010..5cdd54c 100644
--- a/public/assets/javascripts/rectangles/models/vec2.js
+++ b/public/assets/javascripts/rectangles/models/vec2.js
@@ -8,6 +8,9 @@ vec2.prototype.magnitude = function(){
vec2.prototype.length = function(){
return abs(this.b-this.a)
}
+vec2.prototype.dist = function(){
+ return dist(0,this.a,0,this.b)
+}
vec2.prototype.clone = function(){
return new vec2(this.a, this.b)
}
diff --git a/public/assets/javascripts/rectangles/models/wall.js b/public/assets/javascripts/rectangles/models/wall.js
index e327070..b2a5b12 100644
--- a/public/assets/javascripts/rectangles/models/wall.js
+++ b/public/assets/javascripts/rectangles/models/wall.js
@@ -40,8 +40,8 @@ window.Wall = (function(){
mousemove: function(e){
},
mousedown: function(){
- base.randomize_colors()
- console.log(sidesToString(base.side))
+ // base.randomize_colors()
+ // console.log(sidesToString(base.side))
if (Scenery.nextMedia) {
Scenery.addNextToWall(base)
}
@@ -49,19 +49,21 @@ window.Wall = (function(){
})
}
- Wall.prototype.bounds_for = function(img) {
+ Wall.prototype.bounds_for = function(img, scale) {
+ scale = scale || 1
var coord = this.side & FRONT_BACK ? this.rect.x : this.rect.y
- var halfWidth = img.width/2 * img.scale
- var halfHeight = img.height/2 * img.scale
+ var halfWidth = img.width/2 * scale
+ var halfHeight = img.height/2 * scale
return new Rect( new vec2( coord.a + halfWidth, coord.b - halfWidth ),
new vec2( halfHeight, Rooms.list[this.room].height - halfHeight ) )
}
- Wall.prototype.fits = function(img){
- if (this.side & FRONT_BACK && this.rect.x.length() < img.width * img.scale) {
+
+ Wall.prototype.fits = function(img, scale){
+ if (this.side & FRONT_BACK && this.rect.x.length() < img.width * scale) {
return false
}
- if (this.side & LEFT_RIGHT && this.rect.y.length() < img.width * img.scale) {
+ if (this.side & LEFT_RIGHT && this.rect.y.length() < img.width * scale) {
return false
}
return true
@@ -117,7 +119,7 @@ window.Wall = (function(){
}
Wall.prototype.randomize_colors = function(){
- var color = choice(window.colors)
+ var color = window.grayColors[ this.side | this.half_side ]
this.siblings().forEach(function(w){ w.color(color) })
}