aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPushkar Joshi2012-03-12 15:21:59 -0700
committerPushkar Joshi2012-03-12 15:21:59 -0700
commit7b4b068cadc0af8ec7e930e1c2b429e945f96984 (patch)
treef00ee1ef255573dcb9ab81de98324f4fe99eb405
parent00b1e6a9bed04172ad84bdd810f1bd999e8fa0eb (diff)
downloadninja-7b4b068cadc0af8ec7e930e1c2b429e945f96984.tar.gz
seemingly working version of the calligraphic brush (seems to work with transparency and large stroke widths...seems to work better with smoothing)
-rwxr-xr-xjs/lib/geom/brush-stroke.js26
1 files changed, 6 insertions, 20 deletions
diff --git a/js/lib/geom/brush-stroke.js b/js/lib/geom/brush-stroke.js
index 595a6a63..4c42539a 100755
--- a/js/lib/geom/brush-stroke.js
+++ b/js/lib/geom/brush-stroke.js
@@ -424,34 +424,21 @@ var BrushStroke = function GLBrushStroke() {
424 var startPos = [-halfNumTraces*deltaDisplacement[0],-halfNumTraces*deltaDisplacement[1]]; 424 var startPos = [-halfNumTraces*deltaDisplacement[0],-halfNumTraces*deltaDisplacement[1]];
425 425
426 var brushStamp = []; 426 var brushStamp = [];
427 /*for (t=0;t<numTraces;t++){
428 var brushPt = [startPos[0]+t*deltaDisplacement[0], startPos[1]+t*deltaDisplacement[1]];
429 brushStamp.push(brushPt);
430 }*/
431 //todo BEGIN TEMP
432 numTraces *=2;
433 halfNumTraces *= 2;
434 opaqueRegionHalfWidth *=2;
435 maxTransparentRegionHalfWidth *= 2;
436 for (t=0;t<numTraces;t++){ 427 for (t=0;t<numTraces;t++){
437 var brushPt = [startPos[0]+t*deltaDisplacement[0]*0.5, startPos[1]+t*deltaDisplacement[1]*0.5]; 428 var brushPt = [startPos[0]+t*deltaDisplacement[0], startPos[1]+t*deltaDisplacement[1]];
438 brushStamp.push(brushPt); 429 brushStamp.push(brushPt);
439 } 430 }
440 //todo END TEMP
441 431
442 ctx.lineJoin="bevel"; 432 ctx.lineJoin="bevel";
443 ctx.lineCap="butt"; 433 ctx.lineCap="butt";
444 ctx.globalCompositeOperation = 'source-over'; 434 ctx.globalCompositeOperation = 'source-over';
445 //if (maxTransparentRegionHalfWidth===0){
446 ctx.globalCompositeOperation ='lighter'; //todo...we wish to add up the colors, but 'lighter' seems to produce white pixels unlike the round brush
447 //}
448 ctx.globalAlpha = this._strokeColor[3]; 435 ctx.globalAlpha = this._strokeColor[3];
449 ctx.lineWidth=this._strokeWidth/10;//todo figure out the correct formula for the line width 436 //ctx.lineWidth=this._strokeWidth/10;//todo figure out the correct formula for the line width
450 //if (ctx.lineWidth<2) 437 //if (ctx.lineWidth<2)
451 ctx.lineWidth=1; 438 ctx.lineWidth=2;
452 //if (t===numTraces-1){ 439 if (t===numTraces-1){
453 // ctx.lineWidth = 1; 440 ctx.lineWidth = 1;
454 //} 441 }
455 442
456 for (t=0;t<numTraces;t++){ 443 for (t=0;t<numTraces;t++){
457 var disp = [brushStamp[t][0], brushStamp[t][1]]; 444 var disp = [brushStamp[t][0], brushStamp[t][1]];
@@ -467,7 +454,6 @@ var BrushStroke = function GLBrushStroke() {
467 ctx.strokeStyle="rgba("+parseInt(255*this._strokeColor[0])+","+parseInt(255*this._strokeColor[1])+","+parseInt(255*this._strokeColor[2])+","+alphaVal+")"; 454 ctx.strokeStyle="rgba("+parseInt(255*this._strokeColor[0])+","+parseInt(255*this._strokeColor[1])+","+parseInt(255*this._strokeColor[2])+","+alphaVal+")";
468 //linearly interpolate between the two stroke colors 455 //linearly interpolate between the two stroke colors
469 var currStrokeColor = VecUtils.vecInterpolate(4, this._strokeColor, this._secondStrokeColor, t/numTraces); 456 var currStrokeColor = VecUtils.vecInterpolate(4, this._strokeColor, this._secondStrokeColor, t/numTraces);
470 //ctx.globalAlpha = currStrokeColor[3];
471 //ctx.strokeStyle="rgba("+parseInt(255*currStrokeColor[0])+","+parseInt(255*currStrokeColor[1])+","+parseInt(255*currStrokeColor[2])+","+alphaVal+")"; 457 //ctx.strokeStyle="rgba("+parseInt(255*currStrokeColor[0])+","+parseInt(255*currStrokeColor[1])+","+parseInt(255*currStrokeColor[2])+","+alphaVal+")";
472 458
473 ctx.translate(disp[0],disp[1]); 459 ctx.translate(disp[0],disp[1]);