diff options
| author | Julie Lala <jules@okfoc.us> | 2014-11-18 10:46:18 -0500 |
|---|---|---|
| committer | Julie Lala <jules@okfoc.us> | 2014-11-18 10:46:18 -0500 |
| commit | 551dabc2e9f0202848fe000084fc4283272faed3 (patch) | |
| tree | 494c52955304914246e9a8d5f804d6160286bdbf | |
| parent | 44b4f43420c6571bc00aca48968a70bcea538972 (diff) | |
why are my endpoints so lumpy..
| -rw-r--r-- | assets/test/brush/index2.html | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/assets/test/brush/index2.html b/assets/test/brush/index2.html index c18e320..004b030 100644 --- a/assets/test/brush/index2.html +++ b/assets/test/brush/index2.html @@ -38,6 +38,7 @@ var mymouse = new mouse({ lastPoint.a = cursor.x.a lastPoint.b = cursor.y.a maskCtx.clearRect(0,0,w,h) + drawLine(lastPoint, lastPoint) // imagedata = ctx.getImageData( 0, 0, canvas.width, canvas.height ) // data = imagedata.data }, @@ -52,8 +53,9 @@ var mymouse = new mouse({ 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.globalCompositeOperator = "multiply" - canvas.drawImage(mask, 0, 0) + ctx.globalCompositeOperation = "multiply" + ctx.drawImage(mask, 0, 0) + maskCtx.clearRect(0,0,w,h) }, }) @@ -69,7 +71,7 @@ function drawLine (u, v) { var p = new point (0,0) var radius2 = radius * radius - if (w == h && h == radius*2) return +// if (w == h && h == radius*2) return var imagedata = ctx.createImageData(w, h) var d = imagedata.data @@ -88,13 +90,13 @@ function drawLine (u, v) { d[t+3] = 0 } else { - d[t+0] = d[t+1] = d[t+2] = round( tan(sqrt(dist)/radius) * 255) + d[t+0] = d[t+1] = d[t+2] = round( (sqrt(dist)/radius) * 255) d[t+3] = 255 } } } scratchCtx.putImageData(imagedata, 0, 0) - maskCtx.globalCompositeOperation = 'darken'; + maskCtx.globalCompositeOperation = 'destination-out'; maskCtx.drawImage(scratch, xmin - radius, ymin - radius) } @@ -106,6 +108,7 @@ function sqr(x) { return x * x } function dist2(v, w) { return sqr(v.a - w.a) + sqr(v.b - w.b) } 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 if (t < 0) return dist2(p, v) if (t > 1) return dist2(p, w) |
