Strict Standards: Only variables should be passed by reference in /home/abeall/public_html/fireworks/download.php on line 28

Warning: Cannot modify header information - headers already sent by (output started at /home/abeall/public_html/fireworks/download.php:28) in /home/abeall/public_html/fireworks/download.php on line 44
// Fireworks JavaScript Command // Install by copying to Fireworks/Configuration/Commands/ // Aaron Beall 2007-2011 - http://abeall.com // Version 1.4.1 /* BUGS - [FIXED-v1.2] on open paths, the last point is lost - each splitBezierAtDistance operation starts over, it would be faster if it started from the previous point - [CHANGED-v1.4] copyObject/pasteObject to copyNode/pasteNode */ var dom = fw.getDocumentDOM(); // document object var sel = [].concat(fw.selection); // saved selection function AddPoints() { // require active document if (!dom) return false; // validate selection var paths = []; for(var s in sel){ if(sel[s] == '[object Path]') paths.push(sel[s]); } if(!paths.length) return alert('This command requires at least one selected path.'); // user input var spacing = 'undefined', error; while((isNaN(Number(spacing)) || Number(spacing)<=0) && spacing!=null){ if(error) alert(error); spacing = prompt('Spacing:',(fw.AddPoints_spacing || 25)); error = 'Invalid input!'; } if(spacing == null) return false; spacing = Math.abs(Number(spacing)); fw.AddPoints_spacing = spacing; //remember user input for next time // add points to all paths in selection var p = paths.length, c, ln, prevNode, nextNode, pt, nn; var con, nodes, newNodes; var subselect = fw.activeTool == 'Subselection', pointsAdded = false; while(p--){ c = paths[p].contours.length; while(c--){ con = paths[p].contours[c]; nodes = paths[p].contours[c].nodes; newNodes = []; ln = nodes.length; for(var n = 0; n < ln; n++){ newNodes.push(copyNode(nodes[n])); if(n == ln - 1 && !con.isClosed) break; nextNode = nodes[n + 1] || newNodes[0]; if(subselect && !(nodes[n].isSelectedPoint && nextNode.isSelectedPoint)) continue; while(true){ prevNode = newNodes[newNodes.length - 1]; pt = splitBezierAtDistance(prevNode, {x:prevNode.succX, y:prevNode.succY}, {x:nextNode.predX, y:nextNode.predY}, nextNode, spacing); if(pt.time >= 1) break; newNodes.push(copyNode(nodes[n])); nn = newNodes[newNodes.length - 1]; nn.x = pt.p3.x; nn.y = pt.p3.y; nn.predX = pt.cp3.x; nn.predY = pt.cp3.y; nn.succX = pt.cp4.x; nn.succY = pt.cp4.y; nn.isCurvePoint = true; prevNode.succX = pt.cp1.x; prevNode.succY = pt.cp1.y; nextNode.predX = pt.cp2.x; nextNode.predY = pt.cp2.y; pointsAdded = true; } } var isClosed = con.isClosed; paths[p].contours[c] = new Contour(); paths[p].contours[c].isClosed = isClosed; var nlen = newNodes.length; for(var n = 0; n < nlen; n++){ paths[p].contours[c].nodes[n] = new ContourNode(); pasteNode(paths[p].contours[c].nodes[n], newNodes[n]); } } } if(subselect && !pointsAdded) alert("This operation produced no output. When using the Subselect tool you must select points adjacent to each other(points will be added between them) -- or select the entire object using the Pointer tool."); if(!subselect && !pointsAdded) alert("This operation produced no output. Try a smaller Spacing value."); return true; } AddPoints(); // copy node function copyNode(pt){ var ptCopy = {} copyProps(ptCopy, pt, ["x", "y", "succX", "succY", "predX", "predY", "randomSeed", "isSelectedPoint", "isCurvePoint", "name"]); ptCopy.dynamicInfo = []; for(var i = 0; i < pt.dynamicInfo.length; i++) ptCopy.dynamicInfo[i] = copyProps({}, pt.dynamicInfo[i], ["pressure", "duration", "velocity"]); return ptCopy; } // paste node function pasteNode(pt, ptCopy){ copyProps(pt, ptCopy, ["x", "y", "succX", "succY", "predX", "predY", "randomSeed", "isSelectedPoint", "isCurvePoint", "name"]); var dynamicInfo = []; for(var i = 0; i < ptCopy.dynamicInfo.length; i++) dynamicInfo.push(copyProps(new ContourNodeDynamicInfo(), ptCopy.dynamicInfo[i], ["pressure", "duration", "velocity"])); pt.dynamicInfo = dynamicInfo; return pt; } // copy props by name function copyProps(targetObj, sourceObj, props){ var p = props.length; while(p--) targetObj[props[p]] = sourceObj[props[p]]; return targetObj; } // splits a bezier segment(as defined by p1, cp1, cp2, p2) at a specified distance from p1 function splitBezierAtDistance(p1,cp1,cp2,p2,distance){ var P1 = p1;//{x:p1.x, y:p1.y}; var C1 = cp1;//{x:p1.succX, y:p1.succY}; var C2 = cp2;//{x:p2.predX, y:p2.predY}; var P2 = p2;//{x:p2.x, y:p2.y}; var P3 = getBezierAtDistance(distance,P2,C2,C1,P1); var t3 = P3.percent; var U = { x: (C1.x - P1.x)*t3, y: (C1.y - P1.y)*t3 } var V = { x: ((C2.x - C1.x)*t3 - U.x)*t3, y: ((C2.y - C1.y)*t3 - U.y)*t3 } var newC1 = { x: U.x + P1.x, y: U.y + P1.y } var C3 = { x: U.x + V.x + newC1.x, y: U.y + V.y + newC1.y } var R = { x: (C2.x - P2.x)*(1-t3), y: (C2.y - P2.y)*(1-t3) } var S = { x: ((C1.x - C2.x)*(1-t3) - R.x)*(1-t3), y: ((C1.y - C2.y)*(1-t3) - R.y)*(1-t3) } var newC2 = { x: R.x + P2.x, y: R.y + P2.y } var C4 = { x: R.x + S.x + newC2.x, y: R.y + S.y + newC2.y } //return {C4:C4,C3:C3,t3:t3,P3:P3}; return { time:t3, cp1:newC1, cp2:newC2, p3:P3, cp3:C3, cp4:C4 }; } // find the point along a bezier segment(as defined by p1, cp1, cp2, p2) at a specified distance from p1 function getBezierAtDistance(distance,p1,cp1,cp2,p2,steps,iterations){ if(!steps) var steps = 10; if(!iterations) var iterations = 5; var i, dist, currDist, prevPoint, point, currPercent; return doWalkBezier(0,1); function doWalkBezier(minPercent,maxPercent,startDistance){ //alert('walk bezier: '+minPercent+'-'+maxPercent); dist = startDistance||0; //i = steps+1; //while(i--){ prevPoint = null; for(var i=0; i<=steps; i++){ currPercent = minPercent + (maxPercent-minPercent)*((1/steps)*i); //if(!prevPoint) alert(currPercent+': '+dist); point = getBezier(currPercent,p1,cp1,cp2,p2); point.percent = currPercent; if(prevPoint){ dist += currDist = getDistance(point,prevPoint); //alert(currPercent+': '+dist); if(dist==distance) return point; if(dist>distance) return --iterations ? doWalkBezier(prevPoint.percent,point.percent,dist-currDist) : prevPoint; } prevPoint = point; } //point = getBezier(maxPercent,p1,cp1,cp2,p2);; //point.percent = maxPercent; return point; } } // find a point along a bezier segment(as defined by p1, cp1, cp2, p2) at a specified percent(0-100) function getBezier(percent,p1,cp1,cp2,p2) { function b1(t) { return t*t*t } function b2(t) { return 3*t*t*(1-t) } function b3(t) { return 3*t*(1-t)*(1-t) } function b4(t) { return (1-t)*(1-t)*(1-t) } var pos = {x:0,y:0}; pos.x = p1.x*b1(percent) + cp1.x*b2(percent) + cp2.x*b3(percent) + p2.x*b4(percent); pos.y = p1.y*b1(percent) + cp1.y*b2(percent) + cp2.y*b3(percent) + p2.y*b4(percent); return pos; } // find the distance between two points function getDistance(p1,p2){ return Math.sqrt(((p1.x-p2.x)*(p1.x-p2.x))+((p1.y-p2.y)*(p1.y-p2.y))); }