diff options
author | Valerio Virgillito | 2012-06-12 20:57:02 -0700 |
---|---|---|
committer | Valerio Virgillito | 2012-06-12 20:57:02 -0700 |
commit | 493485c1ebc4d4034e10b47c161035409e598fcf (patch) | |
tree | c3e29ac5efd38230b49fc7101b2970102918c84c /assets/canvas-runtime.js | |
parent | 81cc4087588e12b851ead25a16368ec4dc846203 (diff) | |
parent | c7135de92b25b380bebcafac541821a3696cfdfa (diff) | |
download | ninja-493485c1ebc4d4034e10b47c161035409e598fcf.tar.gz |
Merge pull request #290 from pushkarjoshi/brushtool
Brushtool
Diffstat (limited to 'assets/canvas-runtime.js')
-rw-r--r-- | assets/canvas-runtime.js | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js index fe5f839c..feb35187 100644 --- a/assets/canvas-runtime.js +++ b/assets/canvas-runtime.js | |||
@@ -2107,7 +2107,40 @@ NinjaCvsRt.RuntimeBrushStroke = Object.create(NinjaCvsRt.RuntimeGeomObj, { | |||
2107 | } | 2107 | } |
2108 | this._LocalPoints = newPoints.slice(0); | 2108 | this._LocalPoints = newPoints.slice(0); |
2109 | } | 2109 | } |
2110 | } | 2110 | |
2111 | // *** compute the bounding box ********* | ||
2112 | var BBoxMin = [Infinity, Infinity, Infinity]; | ||
2113 | var BBoxMax = [-Infinity, -Infinity, -Infinity]; | ||
2114 | if (numPoints === 0) { | ||
2115 | BBoxMin = [0, 0, 0]; | ||
2116 | BBoxMax = [0, 0, 0]; | ||
2117 | } else { | ||
2118 | for (var i=0;i<numPoints;i++){ | ||
2119 | var pt = this._LocalPoints[i]; | ||
2120 | for (var d = 0; d < 3; d++) { | ||
2121 | if (BBoxMin[d] > pt[d]) { | ||
2122 | BBoxMin[d] = pt[d]; | ||
2123 | } | ||
2124 | if (BBoxMax[d] < pt[d]) { | ||
2125 | BBoxMax[d] = pt[d]; | ||
2126 | } | ||
2127 | }//for every dimension d from 0 to 2 | ||
2128 | } | ||
2129 | } | ||
2130 | |||
2131 | //increase the bbox given the stroke width and the angle (in case of calligraphic brush) | ||
2132 | var bboxPadding = this._strokeWidth*0.5; | ||
2133 | for (var d = 0; d < 3; d++) { | ||
2134 | BBoxMin[d]-= bboxPadding; | ||
2135 | BBoxMax[d]+= bboxPadding; | ||
2136 | }//for every dimension d from 0 to 2 | ||
2137 | |||
2138 | //******* update the local coords so that the bbox min is at the origin ****** | ||
2139 | for (var i=0;i<numPoints;i++) { | ||
2140 | this._LocalPoints[i][0]-= BBoxMin[0]; | ||
2141 | this._LocalPoints[i][1]-= BBoxMin[1]; | ||
2142 | } | ||
2143 | }//if we need to do smoothing | ||
2111 | } | 2144 | } |
2112 | }, | 2145 | }, |
2113 | 2146 | ||
@@ -2231,7 +2264,10 @@ NinjaCvsRt.RuntimeBrushStroke = Object.create(NinjaCvsRt.RuntimeGeomObj, { | |||
2231 | var disp = [brushStamp[t][0], brushStamp[t][1]]; | 2264 | var disp = [brushStamp[t][0], brushStamp[t][1]]; |
2232 | var alphaVal = 1.0; | 2265 | var alphaVal = 1.0; |
2233 | var distFromOpaqueRegion = Math.abs(t-halfNumTraces) - opaqueRegionHalfWidth; | 2266 | var distFromOpaqueRegion = Math.abs(t-halfNumTraces) - opaqueRegionHalfWidth; |
2234 | if (distFromOpaqueRegion>0) { | 2267 | if (numTraces === 1){ |
2268 | distFromOpaqueRegion = 0; | ||
2269 | } | ||
2270 | else if (distFromOpaqueRegion>0) { | ||
2235 | var transparencyFactor = distFromOpaqueRegion/maxTransparentRegionHalfWidth; | 2271 | var transparencyFactor = distFromOpaqueRegion/maxTransparentRegionHalfWidth; |
2236 | alphaVal = 1.0 - transparencyFactor;//(transparencyFactor*transparencyFactor);//the square term produces nonlinearly varying alpha values | 2272 | alphaVal = 1.0 - transparencyFactor;//(transparencyFactor*transparencyFactor);//the square term produces nonlinearly varying alpha values |
2237 | alphaVal *= 0.5; //factor that accounts for lineWidth == 2 | 2273 | alphaVal *= 0.5; //factor that accounts for lineWidth == 2 |