From ea195af100d327aac68ada28387fe8259d0f31f4 Mon Sep 17 00:00:00 2001 From: Pushkar Joshi Date: Wed, 6 Jun 2012 09:46:15 -0700 Subject: added gradients to pen path runtime --- assets/canvas-runtime.js | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) (limited to 'assets') diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js index 3ed7ed0f..4fb0a327 100644 --- a/assets/canvas-runtime.js +++ b/assets/canvas-runtime.js @@ -1951,6 +1951,40 @@ NinjaCvsRt.RuntimeSubPath = Object.create(NinjaCvsRt.RuntimeGeomObj, { } }, + //buildColor returns the fillStyle or strokeStyle for the Canvas 2D context + buildColor: { + value: 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