diff options
| author | Jules Laplace <jules@okfoc.us> | 2014-11-18 15:36:17 -0500 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2014-11-18 15:36:17 -0500 |
| commit | 24047fd4fea0f91aa66023434abc0030cf8dfb90 (patch) | |
| tree | 7a2972fd42f8f7abeb6b44dfb1b283e2d7a5bc7b /assets/test/brush/index2.html | |
| parent | 551dabc2e9f0202848fe000084fc4283272faed3 (diff) | |
making the point/vec2 naming more normal
Diffstat (limited to 'assets/test/brush/index2.html')
| -rw-r--r-- | assets/test/brush/index2.html | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/assets/test/brush/index2.html b/assets/test/brush/index2.html index 004b030..7094ca8 100644 --- a/assets/test/brush/index2.html +++ b/assets/test/brush/index2.html @@ -13,6 +13,7 @@ canvas { position: absolute; top: 0; left: 0; } <script src="/assets/javascripts/vendor/bower_components/jquery/dist/jquery.min.js"></script> <script src="/assets/javascripts/vendor/bower_components/lodash/dist/lodash.min.js"></script> <script src="/assets/javascripts/vendor/canvasutilities.js"></script> +<script src="/assets/javascripts/vendor/jsBezier-0.6.js"></script> <script src="/assets/javascripts/vendor/tube.js"></script> <script src="/assets/javascripts/math/util.js"></script> <script src="/assets/javascripts/math/point.js"></script> @@ -35,24 +36,23 @@ var mymouse = new mouse({ el: canvas, down: function(e, cursor){ drawing = true - lastPoint.a = cursor.x.a - lastPoint.b = cursor.y.a + lastPoint.x = cursor.a.x + lastPoint.y = cursor.a.y maskCtx.clearRect(0,0,w,h) drawLine(lastPoint, lastPoint) // imagedata = ctx.getImageData( 0, 0, canvas.width, canvas.height ) // data = imagedata.data }, drag: function(e, cursor){ - newPoint.a = cursor.x.b - newPoint.b = cursor.y.b + newPoint.x = cursor.b.x + newPoint.y = cursor.b.y drawLine(lastPoint, newPoint) - lastPoint.a = newPoint.a - lastPoint.b = newPoint.b + lastPoint.x = newPoint.x + lastPoint.y = newPoint.y }, up: function(e, cursor, new_cursor){ drawing = false -// drawLine({ a: cursor.x.a, b: cursor.y.a }, { a: cursor.x.b, b: cursor.y.b }) ctx.globalCompositeOperation = "multiply" ctx.drawImage(mask, 0, 0) maskCtx.clearRect(0,0,w,h) @@ -62,11 +62,11 @@ var mymouse = new mouse({ function drawLine (u, v) { var radius = 20 - var xmin = Math.min(u.a, v.a) - var ymin = Math.min(u.b, v.b) + var xmin = Math.min(u.x, v.x) + var ymin = Math.min(u.y, v.y) - var w = scratch.width = abs(u.a - v.a) + radius*2 - var h = scratch.height = abs(u.b - v.b) + radius*2 + var w = scratch.width = abs(u.x - v.x) + radius*2 + var h = scratch.height = abs(u.y - v.y) + radius*2 var p = new point (0,0) var radius2 = radius * radius @@ -81,8 +81,8 @@ function drawLine (u, v) { for (j = 0; j < h; j++) { t = (j * w + i) * 4 - p.a = xmin + i - radius - p.b = ymin + j - radius + p.x = xmin + i - radius + p.y = ymin + j - radius dist = distToSegmentSquared( p, u, v ) @@ -96,7 +96,7 @@ function drawLine (u, v) { } } scratchCtx.putImageData(imagedata, 0, 0) - maskCtx.globalCompositeOperation = 'destination-out'; + maskCtx.globalCompositeOperation = 'darken'; maskCtx.drawImage(scratch, xmin - radius, ymin - radius) } @@ -105,16 +105,15 @@ drawLine( new point( 100, 100 ), new point( 400, 100 ) ) drawLine( new point( 100, 100 ), new point( 400, 400 ) ) function sqr(x) { return x * x } -function dist2(v, w) { return sqr(v.a - w.a) + sqr(v.b - w.b) } +function dist2(v, w) { return sqr(v.x - w.x) + sqr(v.y - w.y) } function distToSegmentSquared (p, v, w) { var l2 = dist2(v, w) if (l2 == 0) return dist2(p, v) - var t = ((p.a - v.a) * (w.a - v.a) + (p.b - v.b) * (w.b - v.b)) / l2 + var t = ((p.x - v.x) * (w.x - v.x) + (p.y - v.y) * (w.y - v.y)) / l2 if (t < 0) return dist2(p, v) if (t > 1) return dist2(p, w) - return dist2(p, { a: v.a + t * (w.a - v.a), - b: v.b + t * (w.b - v.b) }) + return dist2(p, { x: v.x + t * (w.x - v.x), + y: v.y + t * (w.y - v.y) }) } - </script> |
