diff options
| author | Julie Lala <jules@okfoc.us> | 2014-04-15 20:13:49 -0400 |
|---|---|---|
| committer | Julie Lala <jules@okfoc.us> | 2014-04-15 20:13:49 -0400 |
| commit | 28da2a26238ff76f87f4e086a9832a5478c35b23 (patch) | |
| tree | 39cfb3f33fb5100234397baecb9037c26daa7fe3 | |
| parent | 2fdd2f4ee268b8d159e57a91bb0dbf977f6fecef (diff) | |
nomenclature
| -rw-r--r-- | rect.js | 2 | ||||
| -rw-r--r-- | rectangles.html | 6 | ||||
| -rw-r--r-- | vec2.js | 5 |
3 files changed, 9 insertions, 4 deletions
@@ -22,7 +22,7 @@ rect.prototype.center = function(){ rect.prototype.area = function(){ return this.x.length() * this.y.length() } -rect.prototype.normalize = function(){ +rect.prototype.translate = function(){ this.x.abs().add(this.translation.a) this.y.abs().add(this.translation.b) this.translation.a = this.translation.b = 0 diff --git a/rectangles.html b/rectangles.html index 71f83c6..32790d7 100644 --- a/rectangles.html +++ b/rectangles.html @@ -131,11 +131,11 @@ canvas.addEventListener("mousemove", function(e){ document.addEventListener("mouseup", function(e){ if (creating) { if (mouse.height() != 0 && mouse.width() != 0) { - rects.push(mouse.normalize()) + rects.push(mouse.translate()) } } if (dragging) { - dragging.normalize() + dragging.translate() } mouse = new rect(e.pageX, e.pageY) creating = dragging = false @@ -258,7 +258,7 @@ function draw_mouse(){ } else { ctx.fillStyle = "rgba(255,255,0,0.5)" - mouse.clone().normalize().fill() + mouse.clone().translate().fill() } } } @@ -38,6 +38,11 @@ vec2.prototype.div = function(n){ this.a /= n this.b /= n } +vec2.normalize = function(){ + var dim = max(this.a, this.b) + this.a = this.a/dim + this.b = this.b/dim +} vec2.prototype.contains = function(n){ return this.a <= n && n <= this.b } |
