From 30d75e82c7649ef2ab9f71fa360f5735eb098bc5 Mon Sep 17 00:00:00 2001 From: Julie Lala Date: Fri, 11 Apr 2014 00:29:49 -0400 Subject: shift to quantize --- assets/javascripts/util.js | 1 + assets/stylesheets/css.css | 2 + rect.js | 60 +++++++++++ rectagnesl-drag.html | 246 --------------------------------------------- rectangles-drag.html | 246 +++++++++++++++++++++++++++++++++++++++++++++ rectangles.html | 189 ++++++++++++++-------------------- vec2.js | 66 ++++++++++++ 7 files changed, 451 insertions(+), 359 deletions(-) create mode 100644 rect.js delete mode 100644 rectagnesl-drag.html create mode 100644 rectangles-drag.html create mode 100644 vec2.js diff --git a/assets/javascripts/util.js b/assets/javascripts/util.js index d100731..81103aa 100644 --- a/assets/javascripts/util.js +++ b/assets/javascripts/util.js @@ -20,6 +20,7 @@ function mix(n,a,b){ return a*(1-n)+b*n } function ceil(n){ return Math.ceil(n) } function floor(n){ return Math.floor(n) } function round(n){ return Math.round(n) } +function quantize(n,a){ return round(n / a) * a } function max(a,b){ return Math.max(a,b) } function min(a,b){ return Math.min(a,b) } function abs(n){ return Math.abs(n) } diff --git a/assets/stylesheets/css.css b/assets/stylesheets/css.css index e59793a..1e54a94 100644 --- a/assets/stylesheets/css.css +++ b/assets/stylesheets/css.css @@ -9,6 +9,8 @@ html, body { height: 100%; background: -moz-linear-gradient(top, rgba(240,249,255,1) 0%, rgba(244,251,255,1) 59%, rgba(244,251,255,1) 59%, rgba(234,247,255,1) 100%); /* FF3.6+ */ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(240,249,255,1)), color-stop(59%,rgba(244,251,255,1)), color-stop(59%,rgba(244,251,255,1)), color-stop(100%,rgba(234,247,255,1))); /* Chrome,Safari4+ */ + font-family: sans-serif; + font-weight: 300; } .mx-scene { z-index: 1; diff --git a/rect.js b/rect.js new file mode 100644 index 0000000..dcf2d33 --- /dev/null +++ b/rect.js @@ -0,0 +1,60 @@ +function rect (x0,y0,x1,y1){ + if (x0 instanceof vec2) { + this.x = x0 + this.y = y0 + } + else if (x1 === undefined) { + this.x = new vec2(x0,x0) + this.y = new vec2(y0,y0) + } + else { + this.x = new vec2(x0,x1) + this.y = new vec2(y0,y1) + } + this.translation = new vec2(0,0) +} +rect.prototype.clone = function(){ + return new rect( this.x.clone(), this.y.clone() ) +} +rect.prototype.center = function(){ + return new vec2(this.x.midpoint(), this.y.midpoint()) +} +rect.prototype.area = function(){ + return this.x.length() * this.y.length() +} +rect.prototype.normalize = function(){ + this.x.normalize().add(this.translation.a) + this.y.normalize().add(this.translation.b) + this.translation.a = this.translation.b = 0 + return this +} +rect.prototype.contains = function(x,y){ + return this.x.contains(x) && this.y.contains(y) +} +rect.prototype.intersects = function(r){ + return this.x.intersects(r.x) && this.y.intersects(r.y) +} +rect.prototype.width = function(){ return this.x.length() } +rect.prototype.height = function(){ return this.y.length() } +rect.prototype.fill = function(){ + ctx.fillRect(this.x.a + this.translation.a, this.y.a + this.translation.b, this.x.length(), this.y.length()) +} +rect.prototype.stroke = function(){ + ctx.beginPath() + ctx.moveTo(this.x.a, this.y.a) + ctx.lineTo(this.x.b, this.y.b) + ctx.stroke() +} +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(){ + return "[" + this.x.toString() + " " + this.y.toString() + "]" +} +rect.prototype.quantize = function(n){ + this.x.quantize(n) + this.y.quantize(n) +} diff --git a/rectagnesl-drag.html b/rectagnesl-drag.html deleted file mode 100644 index 086ce27..0000000 --- a/rectagnesl-drag.html +++ /dev/null @@ -1,246 +0,0 @@ - - - - - - - - -
-
- -
- - - - - diff --git a/rectangles-drag.html b/rectangles-drag.html new file mode 100644 index 0000000..086ce27 --- /dev/null +++ b/rectangles-drag.html @@ -0,0 +1,246 @@ + + + + + + + + +
+
+ +
+ + + + + diff --git a/rectangles.html b/rectangles.html index 8878985..aa31344 100644 --- a/rectangles.html +++ b/rectangles.html @@ -6,6 +6,9 @@ body > div { float: left; } +#info { + padding: 30px; +} @@ -17,118 +20,15 @@ body > div { + +