summaryrefslogtreecommitdiff
path: root/public/js/draw.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2013-03-03 17:50:39 -0500
committerJules Laplace <jules@okfoc.us>2013-03-03 17:50:39 -0500
commit7b5362f5edcc9ddb91b0a5224ff107d57e12902a (patch)
tree9efad43c1951c437ec6afa58e140b4c0e419dacd /public/js/draw.js
parentc506e9a524084951a9164eb99b3038fe0131045b (diff)
canvasquery
Diffstat (limited to 'public/js/draw.js')
-rw-r--r--public/js/draw.js23
1 files changed, 18 insertions, 5 deletions
diff --git a/public/js/draw.js b/public/js/draw.js
index 786b6b6..8bd82df 100644
--- a/public/js/draw.js
+++ b/public/js/draw.js
@@ -1,4 +1,5 @@
$(function(){
+ if ($("#workspace").length == 0) return;
var drawing = false;
var color = colors.black;
var brush = new Brush({ style: 'pencil', color: color, width: 10 });
@@ -60,11 +61,6 @@ $(function(){
}
}
- function Point(e, offset) {
- this.x = e.pageX - offset.left;
- this.y = e.pageY - offset.top;
- }
-
});
function Brush (b) {
@@ -94,3 +90,20 @@ function Brush (b) {
ctx.putImageData(id, 0, 0);
$("#drawing").append(canvas);
}
+
+function Point(e, offset) {
+ this.x = e.pageX - offset.left;
+ this.y = e.pageY - offset.top;
+}
+Point.prototype.add = function(p) {
+ this.x += p.x;
+ this.y += p.y;
+}
+Point.prototype.subtract = function(p) {
+ this.x -= p.x;
+ this.y -= p.y;
+}
+Point.prototype.quantize = function(x, y) {
+ this.x = Math.floor( this.x / x ) * x;
+ this.y = Math.floor( this.y / y ) * y;
+}