function configureTool() { var the_toolObj = fl.tools.activeTool; the_toolObj.setIcon("splat.png"); the_toolObj.setMenuString("Splat Tool"); the_toolObj.setToolName("Splat Tool"); the_toolObj.setToolTip("Splat Tool"); the_toolObj.setOptionsFile("splat.xml"); } function activate() { the_toolObj = fl.tools.activeTool; res = the_toolObj.points; a = the_toolObj.a; b = the_toolObj.b; inner = the_toolObj.inner; } function notifySettingsChanged() { the_toolObj = fl.tools.activeTool; res = the_toolObj.points; a = the_toolObj.a; b = the_toolObj.b; inner = the_toolObj.inner; } function mouseDown() { fl.drawingLayer.beginDraw(); penDown = fl.tools.penDownLoc; transformPoint(penDown, fl.getDocumentDOM().viewMatrix); penDown = fl.tools.snapPoint(penDown); rScale = new Array(); for (var i = 0; i < res * 6; i += 6) { rScale[i] = inner; rScale[i + 1] = 1; rScale[i + 2] = 1; rScale[i + 3] = inner; rScale[i + 4] = inner / 2; rScale[i + 5] = inner / 2; } } function mouseMove() { if (fl.tools.mouseIsDown) { pen = fl.tools.penLoc; transformPoint(pen, fl.getDocumentDOM().viewMatrix); pen = fl.tools.snapPoint(pen); w = pen.x - penDown.x; h = pen.y - penDown.y; r = Math.sqrt(w * w + h * h); segAngle = Math.PI * 2 / (res * 6); points = new Array(); for (var i = 0; i < res * 6; i += 6) { var angle = segAngle * i; var rad = r * rScale[i]; points[i] = {x:penDown.x + Math.cos(angle) * rad, y:penDown.y + Math.sin(angle) * rad}; angle = segAngle * (i + 1); rad = r * rScale[i + 1]; points[i + 1] = {x:penDown.x + Math.cos(angle - a) * rad, y:penDown.y + Math.sin(angle - a) * rad}; angle = segAngle * (i + 2); rad = r * rScale[i + 2]; points[i + 2] = {x:penDown.x + Math.cos(angle + a) * rad, y:penDown.y + Math.sin(angle + a) * rad}; angle = segAngle * (i + 3); rad = r * rScale[i + 3]; points[i + 3] = {x:penDown.x + Math.cos(angle) * rad, y:penDown.y + Math.sin(angle) * rad}; angle = segAngle * (i + 4); rad = r * rScale[i + 4]; points[i + 4] = {x:penDown.x + Math.cos(angle - b) * rad, y:penDown.y + Math.sin(angle - b) * rad}; angle = segAngle * (i + 5); rad = r * rScale[i + 5]; points[i + 5] = {x:penDown.x + Math.cos(angle + b) * rad, y:penDown.y + Math.sin(angle + b) * rad}; } points[i] = {x:points[0].x, y:points[0].y}; fl.drawingLayer.beginFrame(); the_drawL = fl.drawingLayer; the_path = the_drawL.newPath(); for (var i = 0; i < points.length; i++) { invert(points[i], fl.getDocumentDOM().viewMatrix); } for (i = 0; i < res * 6; i += 3) { the_path.addCubicCurve(points[i].x, points[i].y, points[i + 1].x, points[i + 1].y, points[i + 2].x, points[i + 2].y, points[i + 3].x, points[i + 3].y); } the_drawL.drawPath(the_path); fl.drawingLayer.endFrame(); } } function mouseUp() { fl.drawingLayer.endDraw(); the_doc = fl.getDocumentDOM(); the_path.makeShape(); } function transformPoint(pt, mat) { var x = pt.x * mat.a + pt.y * mat.c; // + mat.tx; var y = pt.x * mat.b + pt.y * mat.d; // + mat.ty; pt.x = x; pt.y = y; } function invert(pt, mat) { var det = mat.a * mat.d - mat.b * mat.c; var x = pt.x * mat.d / det + pt.y * -mat.c / det; // -mat.tx; var y = pt.x * -mat.b / det + pt.y * mat.a / det; // -mat.ty; pt.x = x; pt.y = y; }