aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes
diff options
context:
space:
mode:
authorPushkar Joshi2012-02-29 11:38:33 -0800
committerPushkar Joshi2012-02-29 11:38:33 -0800
commit46fb52be241dced940d46629c809a09c86ed4438 (patch)
tree7e8462aeb86c8d579efbbd1ae6688d594e82bcbd /js/helper-classes
parentf000a3cced9adbfff1d7aa641e6eb42ad6edf7e8 (diff)
downloadninja-46fb52be241dced940d46629c809a09c86ed4438.tar.gz
changed the registration point of the brush tool icon and
added a temporary check to prevent extremely long brush strokes
Diffstat (limited to 'js/helper-classes')
-rwxr-xr-xjs/helper-classes/RDGE/GLBrushStroke.js16
1 files changed, 7 insertions, 9 deletions
diff --git a/js/helper-classes/RDGE/GLBrushStroke.js b/js/helper-classes/RDGE/GLBrushStroke.js
index f63bcc8a..07a4a039 100755
--- a/js/helper-classes/RDGE/GLBrushStroke.js
+++ b/js/helper-classes/RDGE/GLBrushStroke.js
@@ -35,7 +35,8 @@ function GLBrushStroke() {
35 this._strokeStyle = "Solid"; 35 this._strokeStyle = "Solid";
36 36
37 //the wetness of the brush (currently this is multiplied to the square of the stroke width, but todo should be changed to not depend on stroke width entirely 37 //the wetness of the brush (currently this is multiplied to the square of the stroke width, but todo should be changed to not depend on stroke width entirely
38 this._WETNESS_FACTOR = 0.010625;//0.0625; 38 //smaller value means more samples for the path
39 this._WETNESS_FACTOR = 0.25;
39 40
40 //drawing context 41 //drawing context
41 this._world = null; 42 this._world = null;
@@ -75,10 +76,10 @@ function GLBrushStroke() {
75 //add the point only if it is some epsilon away from the previous point 76 //add the point only if it is some epsilon away from the previous point
76 var numPoints = this._Points.length; 77 var numPoints = this._Points.length;
77 if (numPoints>0) { 78 if (numPoints>0) {
78 var threshold = this._WETNESS_FACTOR*this._strokeWidth*this._strokeWidth; 79 var threshold = this._WETNESS_FACTOR*this._strokeWidth;
79 var prevPt = this._Points[numPoints-1]; 80 var prevPt = this._Points[numPoints-1];
80 var diffPt = [prevPt[0]-pt[0], prevPt[1]-pt[1]]; 81 var diffPt = [prevPt[0]-pt[0], prevPt[1]-pt[1]];
81 var diffPtMag = diffPt[0]*diffPt[0] + diffPt[1]*diffPt[1]; 82 var diffPtMag = Math.sqrt(diffPt[0]*diffPt[0] + diffPt[1]*diffPt[1]);
82 if (diffPtMag>threshold){ 83 if (diffPtMag>threshold){
83 this._Points.push(pt); 84 this._Points.push(pt);
84 this._dirty=true; 85 this._dirty=true;
@@ -136,7 +137,7 @@ function GLBrushStroke() {
136 137
137 //**** add samples to the path if needed...linear interpolation for now 138 //**** add samples to the path if needed...linear interpolation for now
138 if (numPoints>1) { 139 if (numPoints>1) {
139 var threshold = this._WETNESS_FACTOR*this._strokeWidth*this._strokeWidth; 140 var threshold = this._WETNESS_FACTOR*this._strokeWidth;
140 var prevPt = this._Points[0]; 141 var prevPt = this._Points[0];
141 var prevIndex = 0; 142 var prevIndex = 0;
142 for (var i=1;i<numPoints;i++){ 143 for (var i=1;i<numPoints;i++){
@@ -324,17 +325,14 @@ function GLBrushStroke() {
324 325
325 var R2 = this._strokeWidth; 326 var R2 = this._strokeWidth;
326 var R = R2*0.5; 327 var R = R2*0.5;
327 var hardness = 0.25; //for a pencil, this is always 1 //TODO get hardness parameter from user interface 328 var hardness = 0; //for a pencil, this is always 1 //TODO get hardness parameter from user interface
328 var innerRadius = (hardness*R)-1; 329 var innerRadius = (hardness*R)-1;
329 if (innerRadius<1) 330 if (innerRadius<1)
330 innerRadius=1; 331 innerRadius=1;
331 332
332 var r = ctx.createRadialGradient(0,0,innerRadius, 0,0,R); 333 var r = ctx.createRadialGradient(0,0,innerRadius, 0,0,R);
333 //r.addColorStop(0, 'rgba(255,0,0,0.5)'); 334 var midColor = "rgba("+parseInt(255*this._strokeColor[0])+","+parseInt(255*this._strokeColor[1])+","+parseInt(255*this._strokeColor[2])+",1)";
334 var midColor = "rgba("+parseInt(255*this._strokeColor[0])+","+parseInt(255*this._strokeColor[1])+","+parseInt(255*this._strokeColor[2])+",0.5)";
335 r.addColorStop(0, midColor); 335 r.addColorStop(0, midColor);
336 //r.addColorStop(0.5, 'rgba(255,0,0,0.5)'); // prevent aggregation of semi-opaque pixels
337 //r.addColorStop(1, 'rgba(255,0,0,0.0)');
338 var endColor = "rgba("+parseInt(255*this._strokeColor[0])+","+parseInt(255*this._strokeColor[1])+","+parseInt(255*this._strokeColor[2])+",0.0)"; 336 var endColor = "rgba("+parseInt(255*this._strokeColor[0])+","+parseInt(255*this._strokeColor[1])+","+parseInt(255*this._strokeColor[2])+",0.0)";
339 r.addColorStop(1, endColor); 337 r.addColorStop(1, endColor);
340 ctx.fillStyle = r; 338 ctx.fillStyle = r;