From 0dd045b574a27233a452e87ca8ce3d65d725bbfe Mon Sep 17 00:00:00 2001 From: Pushkar Joshi Date: Tue, 5 Jun 2012 09:40:59 -0700 Subject: enable gradients for pen stroke and fill --- js/lib/geom/sub-path.js | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) (limited to 'js/lib/geom') diff --git a/js/lib/geom/sub-path.js b/js/lib/geom/sub-path.js index db115655..f765b715 100755 --- a/js/lib/geom/sub-path.js +++ b/js/lib/geom/sub-path.js @@ -77,6 +77,37 @@ GLSubpath.prototype.buildBuffers = function () { //no need to do anything for now (no WebGL) }; +//buildColor returns the fillStyle or strokeStyle for the Canvas 2D context +GLSubpath.prototype.buildColor = function(ctx, //the 2D rendering context (for creating gradients if necessary) + ipColor, //color string, also encodes whether there's a gradient and of what type + w, //width of the region of color + h, //height of the region of color + lw) //linewidth (i.e. stroke width/size) +{ + if (ipColor.gradientMode){ + var position, gradient, cs, inset; //vars used in gradient calculations + inset = Math.ceil( lw ) - 0.5; + + if(ipColor.gradientMode === "radial") { + var ww = w - 2*lw, hh = h - 2*lw; + gradient = ctx.createRadialGradient(w/2, h/2, 0, w/2, h/2, Math.max(ww, hh)/2); + } else { + gradient = ctx.createLinearGradient(inset, h/2, w-inset, h/2); + } + var colors = ipColor.color; + + var len = colors.length; + for(n=0; n