home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 2010 Software/Programs / PCGuia_programas.iso / Software / Utils / Livebrush / Install-LivebrushLite.air / livebrush.swf / scripts / com / livebrush / tools / LiveBrush.as < prev    next >
Encoding:
Text File  |  2009-10-26  |  38.4 KB  |  1,094 lines

  1. package com.livebrush.tools
  2. {
  3.    import com.livebrush.data.Settings;
  4.    import com.livebrush.geom.ColorSequence;
  5.    import com.livebrush.geom.Counter;
  6.    import com.livebrush.geom.Osc;
  7.    import com.livebrush.graphics.DecoGroup;
  8.    import com.livebrush.graphics.Edge;
  9.    import com.livebrush.graphics.Line;
  10.    import com.livebrush.graphics.canvas.Canvas;
  11.    import com.livebrush.graphics.canvas.CanvasManager;
  12.    import com.livebrush.graphics.canvas.LineLayer;
  13.    import com.livebrush.styles.DecoAsset;
  14.    import com.livebrush.styles.DecoStyle;
  15.    import com.livebrush.styles.LineStyle;
  16.    import com.livebrush.styles.StrokeStyle;
  17.    import com.livebrush.styles.Style;
  18.    import com.livebrush.styles.StyleManager;
  19.    import flash.display.MovieClip;
  20.    import flash.events.EventDispatcher;
  21.    import flash.geom.Point;
  22.    import flash.utils.getTimer;
  23.    
  24.    public class LiveBrush extends EventDispatcher
  25.    {
  26.       public static var idList:Array = [];
  27.       
  28.       public static const DRAWING:String = "drawing";
  29.       
  30.       public static const FINISHED:String = "finished";
  31.       
  32.       public static const FINISHING:String = "finishing";
  33.       
  34.       private var strokeAlpha:Number;
  35.       
  36.       public var inPt:Point;
  37.       
  38.       private var oscObjs:Object;
  39.       
  40.       private var strokeColor:Number = -1;
  41.       
  42.       private var accelPt:Point;
  43.       
  44.       public var id:int;
  45.       
  46.       public var lastMousePos:Point;
  47.       
  48.       private var edgeAngle:Number;
  49.       
  50.       private var decoIndex:Number = -1;
  51.       
  52.       private var _lastAnglePos:Point;
  53.       
  54.       private var forceDeco:Boolean = false;
  55.       
  56.       public var layer:LineLayer;
  57.       
  58.       public var pos:Point;
  59.       
  60.       private var decoHoldCount:Counter;
  61.       
  62.       private var decoPos:Object;
  63.       
  64.       public var cacheBuffer:int = 10;
  65.       
  66.       private var decoKey:int = 1;
  67.       
  68.       private var decoColorHoldCount:Counter;
  69.       
  70.       private var counterObjs:Object;
  71.       
  72.       private var velPt:Point;
  73.       
  74.       public var cache:int = 0;
  75.       
  76.       public var state:String = "drawing";
  77.       
  78.       private var decoSuccess:Boolean;
  79.       
  80.       public var dynamicMove:Function;
  81.       
  82.       public var style:Style;
  83.       
  84.       public var showCursor:Boolean = true;
  85.       
  86.       private var decoColor:Number = -1;
  87.       
  88.       private var edge:Edge;
  89.       
  90.       public var lastInPt:Point;
  91.       
  92.       private var colorSequenceObjs:Object;
  93.       
  94.       public var stateIndex:int;
  95.       
  96.       private var strokeColorHoldCount:Counter;
  97.       
  98.       private var width:Number;
  99.       
  100.       private var lastDecoPt:Point;
  101.       
  102.       private var lastDecoTime:Number;
  103.       
  104.       public var dotMc:MovieClip;
  105.       
  106.       private var lastAngle:Number = 0;
  107.       
  108.       public var lastPos:Point;
  109.       
  110.       private var tSuccess:String;
  111.       
  112.       private var _angleRads:Number = 0;
  113.       
  114.       public var line:Line;
  115.       
  116.       public function LiveBrush(style:Style, layer:LineLayer, pos:Point)
  117.       {
  118.          super();
  119.          this.id = getNewID();
  120.          this.oscObjs = {};
  121.          this.counterObjs = {};
  122.          this.colorSequenceObjs = {};
  123.          this.style = style;
  124.          this.layer = layer;
  125.          this.pos = pos.clone();
  126.          this.init();
  127.       }
  128.       
  129.       public static function getNewID() : int
  130.       {
  131.          var newID:int = 0;
  132.          var highestID:int = 0;
  133.          for(var i:int = 0; i < idList.length; i++)
  134.          {
  135.             if(idList[i] >= highestID)
  136.             {
  137.                highestID = int(idList[i]);
  138.             }
  139.          }
  140.          newID = highestID + 1;
  141.          idList.push(newID);
  142.          return newID;
  143.       }
  144.       
  145.       private function getDecoColor() : Number
  146.       {
  147.          var color:Number = NaN;
  148.          switch(this.decoStyle.colorType)
  149.          {
  150.             case DecoStyle.FIXED:
  151.                color = this.decoStyle.selectedColor;
  152.                break;
  153.             case DecoStyle.LIST:
  154.                if(this.decoColorHoldCount.value == this.decoStyle.colorHold || this.decoColor == -1)
  155.                {
  156.                   color = this.colorSequence("decoColor",this.decoStyle.colorList,this.decoStyle.colorSteps).nextColor();
  157.                }
  158.                else
  159.                {
  160.                   color = this.decoColor;
  161.                }
  162.                break;
  163.             case DecoStyle.SPEED:
  164.                if(this.decoColorHoldCount.count() == this.decoStyle.colorHold || this.decoColor == -1)
  165.                {
  166.                   color = this.colorSequence("decoColor",this.decoStyle.colorList,this.decoStyle.colorSteps).interpolate(0,1,this.drawSpeedPercent);
  167.                }
  168.                else
  169.                {
  170.                   color = this.decoColor;
  171.                }
  172.                break;
  173.             case DecoStyle.WIDTH:
  174.                if(this.decoColorHoldCount.count() == this.decoStyle.colorHold || this.decoColor == -1)
  175.                {
  176.                   color = this.colorSequence("decoColor",this.decoStyle.colorList,this.decoStyle.colorSteps).interpolate(0,1,this.strokeWidthPercent);
  177.                }
  178.                else
  179.                {
  180.                   color = this.decoColor;
  181.                }
  182.                break;
  183.             case DecoStyle.RANDOM:
  184.                if(this.decoColorHoldCount.count() == this.decoStyle.colorHold || this.decoColor == -1)
  185.                {
  186.                   color = this.colorSequence("decoColor",this.decoStyle.colorList,this.decoStyle.colorSteps).randomColor();
  187.                }
  188.                else
  189.                {
  190.                   color = this.decoColor;
  191.                }
  192.                break;
  193.             case DecoStyle.STROKE:
  194.                color = this.strokeColor;
  195.                break;
  196.             case DecoStyle.NONE:
  197.                color = -1;
  198.          }
  199.          return color;
  200.       }
  201.       
  202.       public function setNewLine(_pos:Point = null) : void
  203.       {
  204.          this.line = Line.newLine(this.style.lineStyle.smoothing,this.strokeStyle.strokeType,this.strokeStyle.lines,this.strokeStyle.weight);
  205.          this.line.changed = true;
  206.          this.line.style = this.style;
  207.          this.layer.line = this.line;
  208.          this.velPt = new Point();
  209.          this.accelPt = new Point();
  210.          this.pos = _pos != null ? _pos.clone() : this.pos.clone();
  211.          this.inPt = this.pos.clone();
  212.          this.lastPos = this.pos.clone();
  213.          this.lastMousePos = this.mousePos;
  214.          this.lastDecoPt = this.pos.clone();
  215.          this.lastDecoTime = 0;
  216.          this._lastAnglePos = this.pos;
  217.       }
  218.       
  219.       private function getDecoProps() : Settings
  220.       {
  221.          var initObj:Settings = new Settings();
  222.          var position:Object = this.decoPos = this.getDecoPosition();
  223.          var scaleXY:Number = this.getDecoScale();
  224.          this.decoColor = initObj.color = this.getDecoColor();
  225.          initObj.colorPercent = this.getDecoColorPercent();
  226.          initObj.alpha = this.getDecoAlpha();
  227.          initObj.angle = this.getDecoAngle();
  228.          initObj.pos = position.relative;
  229.          initObj.offset = position.offset;
  230.          initObj.scale = {
  231.             "x":scaleXY * (this.decoStyle.xFlip ? -1 : 1),
  232.             "y":scaleXY * (position.relative >= 0.5 && this.decoStyle.autoFlip || this.decoStyle.yFlip ? -1 : 1)
  233.          };
  234.          initObj.align = this.decoStyle.alignType;
  235.          initObj.brushState = {
  236.             "x":this.x,
  237.             "y":this.y,
  238.             "vx":this.vx,
  239.             "vy":this.vy,
  240.             "speed":this.speed,
  241.             "angleRads":this.angleRads,
  242.             "width":this.width,
  243.             "edgeAngle":this.edgeAngle
  244.          };
  245.          return initObj;
  246.       }
  247.       
  248.       private function init() : void
  249.       {
  250.          this.setNewLine();
  251.          if(this.styleManager.colorsLocked)
  252.          {
  253.             this.strokeColorHoldCount = new Counter(1,this.styleManager.lockedColorSettings.colorHold,1);
  254.          }
  255.          else
  256.          {
  257.             this.strokeColorHoldCount = new Counter(1,this.strokeStyle.colorHold,1);
  258.          }
  259.          this.decoColorHoldCount = new Counter(1,this.decoStyle.colorHold,1);
  260.          this.decoHoldCount = new Counter(1,this.decoStyle.decoHold,1);
  261.          if(this.isDynamic)
  262.          {
  263.             try
  264.             {
  265.                this.dynamicMove = this.lineStyle.getDynamicControl().move;
  266.             }
  267.             catch(e:Error)
  268.             {
  269.                dynamicMove = move;
  270.                lineStyle.type = LineStyle.NORMAL;
  271.                lineStyle.inputSWF = "";
  272.             }
  273.          }
  274.       }
  275.       
  276.       private function degreesToRadians(degrees:Number) : Number
  277.       {
  278.          return degrees * Math.PI / 180;
  279.       }
  280.       
  281.       public function get decoStyle() : DecoStyle
  282.       {
  283.          return this.style.decoStyle;
  284.       }
  285.       
  286.       public function get lineStyle() : LineStyle
  287.       {
  288.          return this.style.lineStyle;
  289.       }
  290.       
  291.       private function randNum(min:Number, max:Number, floor:Boolean = false) : Number
  292.       {
  293.          var rand:Number = min + Math.random() * max;
  294.          return floor ? Math.floor(rand) : rand;
  295.       }
  296.       
  297.       private function getDecoGroup() : DecoGroup
  298.       {
  299.          var t:Object = null;
  300.          var decoGroup:DecoGroup = null;
  301.          var i:int = 0;
  302.          var deco:DecoGroup = null;
  303.          if((this.strokeStyle.decorate || this.forceDeco) && this.line.length > 1)
  304.          {
  305.             t = this.strokeStyle.thresholds;
  306.             this.decoSuccess = true;
  307.             if(t.speed.enabled)
  308.             {
  309.                this.successCheck(this.speed >= t.speed.min);
  310.                this.successCheck(this.speed <= t.speed.max);
  311.             }
  312.             if(t.width.enabled)
  313.             {
  314.                this.successCheck(this.width >= t.width.min);
  315.                this.successCheck(this.width <= t.width.max);
  316.             }
  317.             if(t.angle.enabled)
  318.             {
  319.                this.successCheck(this.edgeAngle >= t.angle.min);
  320.                this.successCheck(this.edgeAngle <= t.angle.max);
  321.             }
  322.             if(t.distance.enabled)
  323.             {
  324.                this.successCheck(this.lastDecoDistance >= t.distance.min);
  325.                this.successCheck(this.lastDecoDistance <= t.distance.max);
  326.             }
  327.             if(t.random.enabled)
  328.             {
  329.                this.successCheck(this.randNum(0,t.random.max,true) == 1);
  330.             }
  331.             if(t.interval.enabled)
  332.             {
  333.                this.successCheck(getTimer() - this.lastDecoTime >= t.interval.min);
  334.             }
  335.             if(this.decoSuccess || this.forceDeco)
  336.             {
  337.                this.lastDecoPt = this.pos.clone();
  338.                this.lastDecoTime = getTimer();
  339.                decoGroup = new DecoGroup();
  340.                for(i = 0; i < this.decoStyle.decoNum; i++)
  341.                {
  342.                   decoGroup.addDeco(this.getDecoAsset(),this.getDecoProps());
  343.                }
  344.                this.counterObj("decoOffsetPos").reset();
  345.                if(!this.decoStyle.persist)
  346.                {
  347.                   try
  348.                   {
  349.                      this.oscObj("decoAlpha").reset();
  350.                   }
  351.                   catch(e:Error)
  352.                   {
  353.                   }
  354.                   try
  355.                   {
  356.                      this.oscObj("decoTint").reset();
  357.                   }
  358.                   catch(e:Error)
  359.                   {
  360.                   }
  361.                   try
  362.                   {
  363.                      this.counterObj("decoAngle").reset();
  364.                   }
  365.                   catch(e:Error)
  366.                   {
  367.                   }
  368.                   try
  369.                   {
  370.                      this.oscObj("decoAngle").reset();
  371.                   }
  372.                   catch(e:Error)
  373.                   {
  374.                   }
  375.                   try
  376.                   {
  377.                      this.oscObj("decoSize").reset();
  378.                   }
  379.                   catch(e:Error)
  380.                   {
  381.                   }
  382.                   try
  383.                   {
  384.                      this.colorSequence("decoColor").reset();
  385.                   }
  386.                   catch(e:Error)
  387.                   {
  388.                   }
  389.                   try
  390.                   {
  391.                      this.oscObj("decoPos").reset();
  392.                   }
  393.                   catch(e:Error)
  394.                   {
  395.                   }
  396.                   try
  397.                   {
  398.                      this.counterObj("decoPos").reset();
  399.                   }
  400.                   catch(e:Error)
  401.                   {
  402.                   }
  403.                   try
  404.                   {
  405.                      this.counterObj("decoSequence").reset();
  406.                   }
  407.                   catch(e:Error)
  408.                   {
  409.                   }
  410.                   try
  411.                   {
  412.                      this.decoColorHoldCount.reset();
  413.                   }
  414.                   catch(e:Error)
  415.                   {
  416.                   }
  417.                   try
  418.                   {
  419.                      this.decoHoldCount.reset();
  420.                   }
  421.                   catch(e:Error)
  422.                   {
  423.                   }
  424.                   this.decoColor = -1;
  425.                   this.decoIndex = -1;
  426.                }
  427.                this.forceDeco = false;
  428.             }
  429.          }
  430.          return decoGroup;
  431.       }
  432.       
  433.       public function queueFinish() : void
  434.       {
  435.          this.state = this.style.lineStyle.type == LineStyle.NORMAL || this.lineStyle.mouseUpComplete && this.isElastic ? FINISHED : FINISHING;
  436.       }
  437.       
  438.       private function getDecoAlpha() : Number
  439.       {
  440.          var alpha:Number = NaN;
  441.          switch(this.decoStyle.alphaType)
  442.          {
  443.             case DecoStyle.FIXED:
  444.                alpha = this.decoStyle.minAlpha;
  445.                break;
  446.             case DecoStyle.SPEED:
  447.                alpha = this.percentOf(this.drawSpeedPercent,this.decoStyle.maxAlpha - this.decoStyle.minAlpha) + this.decoStyle.minAlpha;
  448.                break;
  449.             case DecoStyle.WIDTH:
  450.                alpha = this.percentOf(this.strokeWidthPercent,this.decoStyle.maxAlpha - this.decoStyle.minAlpha) + this.decoStyle.minAlpha;
  451.                break;
  452.             case DecoStyle.OSC:
  453.                alpha = this.oscObj("decoAlpha",this.decoStyle.minAlpha,this.decoStyle.maxAlpha,this.decoStyle.alphaSpeed).update().x;
  454.                break;
  455.             case DecoStyle.STROKE:
  456.                alpha = this.strokeAlpha;
  457.                break;
  458.             case DecoStyle.RANDOM:
  459.                alpha = this.randNum(this.decoStyle.minAlpha,this.decoStyle.maxAlpha);
  460.          }
  461.          return alpha;
  462.       }
  463.       
  464.       public function get canvasManager() : CanvasManager
  465.       {
  466.          return this.layer.canvas.canvasManager;
  467.       }
  468.       
  469.       private function getDecoColorPercent() : Number
  470.       {
  471.          var percent:Number = NaN;
  472.          switch(this.decoStyle.tintType)
  473.          {
  474.             case DecoStyle.FIXED:
  475.                percent = this.decoStyle.minTint;
  476.                break;
  477.             case DecoStyle.SPEED:
  478.                percent = this.percentOf(this.drawSpeedPercent,this.decoStyle.maxTint - this.decoStyle.minTint) + this.decoStyle.minTint;
  479.                break;
  480.             case DecoStyle.WIDTH:
  481.                percent = this.percentOf(this.strokeWidthPercent,this.decoStyle.maxTint - this.decoStyle.minTint) + this.decoStyle.minTint;
  482.                break;
  483.             case DecoStyle.OSC:
  484.                percent = this.oscObj("decoTint",this.decoStyle.minTint,this.decoStyle.maxTint,this.decoStyle.tintSpeed).update().x;
  485.                break;
  486.             case DecoStyle.RANDOM:
  487.                percent = this.randNum(this.decoStyle.minTint,this.decoStyle.maxTint);
  488.          }
  489.          return percent;
  490.       }
  491.       
  492.       private function colorSequence(id:String, colorList:Array = null, strokeColorSteps:int = 1) : ColorSequence
  493.       {
  494.          if(this.colorSequenceObjs[id] == null)
  495.          {
  496.             this.colorSequenceObjs[id] = new ColorSequence(colorList,strokeColorSteps);
  497.          }
  498.          return this.colorSequenceObjs[id];
  499.       }
  500.       
  501.       public function get speed() : Number
  502.       {
  503.          return Math.sqrt(this.vx * this.vx + this.vy * this.vy);
  504.       }
  505.       
  506.       public function get isElastic() : Boolean
  507.       {
  508.          return this.lineStyle.type == LineStyle.ELASTIC;
  509.       }
  510.       
  511.       public function get canvas() : Canvas
  512.       {
  513.          return this.layer.canvas;
  514.       }
  515.       
  516.       public function get strokeStyle() : StrokeStyle
  517.       {
  518.          return this.style.strokeStyle;
  519.       }
  520.       
  521.       private function counterObj(id:String, start:Number = 1, end:Number = 2, speed:Number = 1) : Counter
  522.       {
  523.          if(this.counterObjs[id] == null)
  524.          {
  525.             this.counterObjs[id] = new Counter(start,end,speed);
  526.          }
  527.          return this.counterObjs[id];
  528.       }
  529.       
  530.       public function get drawSpeedPercent() : Number
  531.       {
  532.          return (this.speedMax - this.lineStyle.minDrawSpeed) / Math.max(1,this.lineStyle.maxDrawSpeed - this.lineStyle.minDrawSpeed);
  533.       }
  534.       
  535.       public function get mousePos() : Point
  536.       {
  537.          return this.layer.canvas.mousePt;
  538.       }
  539.       
  540.       private function getDecoAngle() : Number
  541.       {
  542.          var angle:Number = NaN;
  543.          var decoPosPt:Point = null;
  544.          var decoOffsetPt:Point = null;
  545.          var dirPt:Point = null;
  546.          var angleRads:Number = NaN;
  547.          switch(this.decoStyle.angleType)
  548.          {
  549.             case DecoStyle.FIXED:
  550.                angle = this.decoStyle.minAngle;
  551.                break;
  552.             case DecoStyle.WIDTH:
  553.                angle = this.percentOf(this.strokeWidthPercent,this.decoStyle.maxAngle - this.decoStyle.minAngle) + this.decoStyle.minAngle;
  554.                break;
  555.             case DecoStyle.DIR:
  556.                angle = this.angle + this.decoStyle.minAngle;
  557.                break;
  558.             case DecoStyle.SPEED:
  559.                angle = this.percentOf(this.drawSpeedPercent,this.decoStyle.maxAngle - this.decoStyle.minAngle) + this.decoStyle.minAngle;
  560.                break;
  561.             case DecoStyle.OSC:
  562.                angle = this.oscObj("decoAngle",this.decoStyle.minAngle,this.decoStyle.maxAngle,this.decoStyle.angleSpeed / 100).update().x;
  563.                break;
  564.             case DecoStyle.ROTATE:
  565.                angle = this.counterObj("decoAngle",this.decoStyle.minAngle,this.decoStyle.maxAngle,this.decoStyle.angleSpeed).count();
  566.                break;
  567.             case DecoStyle.POS_DIR:
  568.                decoPosPt = this.edge.midPoint(this.decoPos.relative);
  569.                decoOffsetPt = decoPosPt.add(this.decoPos.offset);
  570.                dirPt = decoOffsetPt.subtract(decoPosPt);
  571.                angleRads = Math.atan2(dirPt.y,dirPt.x) + Math.PI / 2;
  572.                angle = angleRads * 180 / Math.PI;
  573.                break;
  574.             case DecoStyle.RANDOM:
  575.                angle = this.randNum(this.decoStyle.minAngle,this.decoStyle.maxAngle);
  576.                break;
  577.             case DecoStyle.NONE:
  578.                angle = 0;
  579.          }
  580.          return angle;
  581.       }
  582.       
  583.       public function get lastDecoDistance() : Number
  584.       {
  585.          return Point.distance(this.lastDecoPt,this.pos);
  586.       }
  587.       
  588.       public function get y() : Number
  589.       {
  590.          return this.pos.y;
  591.       }
  592.       
  593.       private function getDecoPosition() : Object
  594.       {
  595.          var pos:Number = NaN;
  596.          var angle:Number = NaN;
  597.          var maxRadius:Number = NaN;
  598.          var radius:Number = NaN;
  599.          var offset:Point = new Point();
  600.          switch(this.decoStyle.posType)
  601.          {
  602.             case DecoStyle.FIXED:
  603.                pos = this.decoStyle.minPos;
  604.                break;
  605.             case DecoStyle.RANDOM:
  606.                pos = this.randNum(this.decoStyle.minPos,this.decoStyle.maxPos);
  607.                break;
  608.             case DecoStyle.A:
  609.                pos = 0;
  610.                break;
  611.             case DecoStyle.B:
  612.                pos = 1;
  613.                break;
  614.             case DecoStyle.CENTER:
  615.                pos = 0.5;
  616.                break;
  617.             case DecoStyle.ALT:
  618.                pos = this.counterObj("decoPos",this.decoStyle.minPos,this.decoStyle.maxPos,this.decoStyle.maxPos - this.decoStyle.minPos).count();
  619.                break;
  620.             case DecoStyle.SPEED:
  621.                pos = this.percentOf(this.drawSpeedPercent,this.decoStyle.maxPos - this.decoStyle.minPos) + this.decoStyle.minPos;
  622.                break;
  623.             case DecoStyle.WIDTH:
  624.                pos = this.percentOf(this.strokeWidthPercent,this.decoStyle.maxPos - this.decoStyle.minPos) + this.decoStyle.minPos;
  625.                break;
  626.             case DecoStyle.OSC:
  627.                pos = this.oscObj("decoPos",this.decoStyle.minPos,this.decoStyle.maxPos,this.decoStyle.posSpeed).update().x;
  628.                break;
  629.             case DecoStyle.SCATTER:
  630.                pos = 0.5;
  631.                maxRadius = Math.max(1,this.decoStyle.maxPos);
  632.                radius = Math.sqrt(Math.random()) * maxRadius;
  633.                angle = this.degreesToRadians(this.decoStyle.minPos) + this.angleRads + this.counterObj("decoOffsetPos",0,Math.PI * 2,Math.PI * 2 / this.decoStyle.decoNum).count();
  634.                offset.x = Math.cos(angle) * radius;
  635.                offset.y = Math.sin(angle) * radius;
  636.                break;
  637.             case DecoStyle.ORBIT:
  638.                pos = 0.5;
  639.                angle = this.degreesToRadians(this.decoStyle.minPos) + this.angleRads + this.counterObj("decoOffsetPos",0,Math.PI * 2,Math.PI * 2 / this.decoStyle.decoNum).count();
  640.                offset.x = Math.cos(angle) * Math.max(1,this.decoStyle.maxPos);
  641.                offset.y = Math.sin(angle) * Math.max(1,this.decoStyle.maxPos);
  642.          }
  643.          return {
  644.             "relative":pos,
  645.             "offset":offset
  646.          };
  647.       }
  648.       
  649.       public function get x() : Number
  650.       {
  651.          return this.pos.x;
  652.       }
  653.       
  654.       private function getStrokeEdgeAngle() : Number
  655.       {
  656.          var angle:Number = NaN;
  657.          switch(this.strokeStyle.angleType)
  658.          {
  659.             case StrokeStyle.FIXED:
  660.                angle = this.strokeStyle.minAngle;
  661.                break;
  662.             case StrokeStyle.WIDTH:
  663.                angle = this.percentOf(this.strokeWidthPercent,this.strokeStyle.maxAngle - this.strokeStyle.minAngle) + this.strokeStyle.minAngle;
  664.                break;
  665.             case StrokeStyle.DIR:
  666.                angle = this.angle + this.strokeStyle.minAngle;
  667.                break;
  668.             case StrokeStyle.SPEED:
  669.                angle = this.percentOf(this.drawSpeedPercent,this.strokeStyle.maxAngle - this.strokeStyle.minAngle) + this.strokeStyle.minAngle;
  670.                break;
  671.             case StrokeStyle.OSC:
  672.                angle = this.oscObj("strokeAngle",this.strokeStyle.minAngle,this.strokeStyle.maxAngle,this.strokeStyle.angleSpeed / 100).update().x;
  673.                break;
  674.             case StrokeStyle.ROTATE:
  675.                angle = this.counterObj("edgeAngle",this.strokeStyle.minAngle,this.strokeStyle.maxAngle,this.strokeStyle.angleSpeed).count();
  676.                break;
  677.             case StrokeStyle.RANDOM:
  678.                angle = this.randNum(this.strokeStyle.minAngle,this.strokeStyle.maxAngle);
  679.          }
  680.          return angle;
  681.       }
  682.       
  683.       private function getDecoAsset() : DecoAsset
  684.       {
  685.          var decoAsset:DecoAsset = null;
  686.          if(this.forceDeco)
  687.          {
  688.             this.decoIndex = Math.min(this.decoKey,this.decoStyle.decoSet.activeLength) - 1;
  689.             decoAsset = this.decoStyle.decoSet.getDecoByIndex(this.decoIndex);
  690.          }
  691.          else
  692.          {
  693.             switch(this.decoStyle.orderType)
  694.             {
  695.                case DecoStyle.SEQUENCE_DECO:
  696.                   if(this.decoHoldCount.count() == this.decoStyle.decoHold || this.decoIndex == -1)
  697.                   {
  698.                      this.decoIndex = this.counterObj("decoSequence",0,this.decoStyle.decoSet.activeLength - 1,1).count();
  699.                      decoAsset = this.decoStyle.decoSet.getActiveDecoByIndex(this.decoIndex);
  700.                   }
  701.                   else
  702.                   {
  703.                      decoAsset = this.decoStyle.decoSet.getActiveDecoByIndex(this.decoIndex);
  704.                   }
  705.                   break;
  706.                case DecoStyle.FIXED_DECO:
  707.                   if(this.decoHoldCount.count() == this.decoStyle.decoHold || this.decoIndex == -1)
  708.                   {
  709.                      this.decoIndex = this.decoStyle.selectedDecoIndex;
  710.                      decoAsset = this.decoStyle.decoSet.getDecoByIndex(this.decoIndex);
  711.                   }
  712.                   else
  713.                   {
  714.                      decoAsset = this.decoStyle.decoSet.getActiveDecoByIndex(this.decoIndex);
  715.                   }
  716.                   break;
  717.                case DecoStyle.RANDOM_DECO:
  718.                   if(this.decoHoldCount.count() == this.decoStyle.decoHold || this.decoIndex == -1)
  719.                   {
  720.                      this.decoIndex = this.randNum(0,this.decoStyle.decoSet.activeLength,true);
  721.                      decoAsset = this.decoStyle.decoSet.getActiveDecoByIndex(this.decoIndex);
  722.                   }
  723.                   else
  724.                   {
  725.                      decoAsset = this.decoStyle.decoSet.getActiveDecoByIndex(this.decoIndex);
  726.                   }
  727.             }
  728.          }
  729.          return decoAsset;
  730.       }
  731.       
  732.       public function die() : void
  733.       {
  734.       }
  735.       
  736.       private function oscObj(id:String, center:Number = 0.5, range:Number = 50, speed:Number = 10) : Osc
  737.       {
  738.          var realRange:Number = NaN;
  739.          if(this.oscObjs[id] == null)
  740.          {
  741.             realRange = range - center;
  742.             range = realRange / 2;
  743.             center = range + center;
  744.             this.oscObjs[id] = new Osc(center,center,range,range,speed);
  745.          }
  746.          return this.oscObjs[id];
  747.       }
  748.       
  749.       public function get angleRads() : Number
  750.       {
  751.          return this._angleRads;
  752.       }
  753.       
  754.       public function get speedMax() : Number
  755.       {
  756.          return Math.min(this.speed,this.lineStyle.maxDrawSpeed);
  757.       }
  758.       
  759.       public function get mouseSpeed() : Number
  760.       {
  761.          return this.layer.canvas.mouseSpeed;
  762.       }
  763.       
  764.       private function getStrokeEdgeWidth() : Number
  765.       {
  766.          var width:Number = NaN;
  767.          if(this.strokeStyle.widthType == StrokeStyle.FIXED)
  768.          {
  769.             width = this.style.strokeStyle.minWidth;
  770.          }
  771.          else if(this.strokeStyle.widthType == StrokeStyle.SPEED)
  772.          {
  773.             width = this.percentOf(this.drawSpeedPercent,this.strokeStyle.maxWidth - this.strokeStyle.minWidth) + this.strokeStyle.minWidth;
  774.          }
  775.          else if(this.strokeStyle.widthType == StrokeStyle.OSC)
  776.          {
  777.             width = this.oscObj("strokeWidth",this.strokeStyle.minWidth,this.strokeStyle.maxWidth,this.strokeStyle.widthSpeed).update().x;
  778.          }
  779.          else if(this.strokeStyle.widthType == StrokeStyle.RANDOM)
  780.          {
  781.             width = this.randNum(this.strokeStyle.minWidth,this.strokeStyle.maxWidth);
  782.          }
  783.          return width;
  784.       }
  785.       
  786.       public function get isDynamic() : Boolean
  787.       {
  788.          return this.lineStyle.type == LineStyle.DYNAMIC;
  789.       }
  790.       
  791.       public function get vx() : Number
  792.       {
  793.          return this.velPt.x;
  794.       }
  795.       
  796.       public function get vy() : Number
  797.       {
  798.          return this.velPt.y;
  799.       }
  800.       
  801.       public function get styleManager() : StyleManager
  802.       {
  803.          return this.style.styleManager;
  804.       }
  805.       
  806.       private function successCheck(condition:Boolean) : Boolean
  807.       {
  808.          this.decoSuccess = this.decoSuccess ? condition : false;
  809.          return condition;
  810.       }
  811.       
  812.       public function move() : Boolean
  813.       {
  814.          var speed:Number;
  815.          var targetPt:Point;
  816.          var angle:Number = NaN;
  817.          var slowVX:Number = NaN;
  818.          var slowVY:Number = NaN;
  819.          var dist:Number = NaN;
  820.          var moving:Boolean = false;
  821.          if(this.state == DRAWING && !this.lineStyle.lockMouse)
  822.          {
  823.             this.inPt = this.mousePos;
  824.          }
  825.          targetPt = this.inPt;
  826.          if(this.lineStyle.type == LineStyle.ELASTIC || this.lineStyle.type == LineStyle.NORMAL || this.state == FINISHING)
  827.          {
  828.             if((this.style.lineStyle.type == LineStyle.ELASTIC || this.state == FINISHING) && this.style.lineStyle.elastic > 0)
  829.             {
  830.                this.accelPt.x = (targetPt.x - this.pos.x) * this.style.lineStyle.elastic;
  831.                this.accelPt.y = (targetPt.y - this.pos.y) * this.style.lineStyle.elastic;
  832.                this.velPt = this.velPt.add(this.accelPt);
  833.                this.velPt.x *= this.style.lineStyle.friction;
  834.                this.velPt.y *= this.style.lineStyle.friction;
  835.             }
  836.             else if((this.style.lineStyle.type == LineStyle.ELASTIC || this.state == FINISHING) && this.style.lineStyle.friction > 0)
  837.             {
  838.                this.velPt.x = (targetPt.x - this.pos.x) * this.style.lineStyle.friction;
  839.                this.velPt.y = (targetPt.y - this.pos.y) * this.style.lineStyle.friction;
  840.             }
  841.             else
  842.             {
  843.                this.velPt.x = targetPt.x - this.pos.x;
  844.                this.velPt.y = targetPt.y - this.pos.y;
  845.             }
  846.             this.pos = this.pos.add(this.velPt);
  847.          }
  848.          else if(this.style.lineStyle.type == LineStyle.DYNAMIC)
  849.          {
  850.             try
  851.             {
  852.                this.pos = this.dynamicMove(targetPt.clone(),this.pos.clone()).clone();
  853.                this.velPt = this.pos.subtract(this.lastPos);
  854.             }
  855.             catch(e:Error)
  856.             {
  857.                lineStyle.type = LineStyle.NORMAL;
  858.                move();
  859.             }
  860.          }
  861.          speed = this.speed;
  862.          if(speed >= this.lineStyle.minDrawSpeed || this.line.length == 0)
  863.          {
  864.             moving = true;
  865.             angle = Math.atan2(this.vy,this.vx);
  866.             if(speed > 4 || this.line.length < 7 || this.state == FINISHING || this.style.lineStyle.type == LineStyle.DYNAMIC)
  867.             {
  868.                this._angleRads = angle;
  869.                this._lastAnglePos = this.pos;
  870.                this.lastAngle = angle;
  871.             }
  872.             else
  873.             {
  874.                slowVX = this.pos.x - this._lastAnglePos.x;
  875.                slowVY = this.pos.y - this._lastAnglePos.y;
  876.                dist = Point.distance(this.pos,this._lastAnglePos);
  877.                if(dist > 10)
  878.                {
  879.                   this._angleRads = Math.atan2(slowVY,slowVX);
  880.                   this._lastAnglePos = this.pos.clone();
  881.                }
  882.             }
  883.             this.line.addEdge(this.createEdge());
  884.             this.lastPos = this.pos.clone();
  885.          }
  886.          if(speed <= this.lineStyle.minDrawSpeed && this.state == FINISHING)
  887.          {
  888.             this.state = FINISHED;
  889.             moving = false;
  890.          }
  891.          return moving;
  892.       }
  893.       
  894.       public function get angle() : Number
  895.       {
  896.          return this.angleRads * 180 / Math.PI;
  897.       }
  898.       
  899.       private function getStrokeColor() : uint
  900.       {
  901.          var color:Number = NaN;
  902.          var colorHold:int = 0;
  903.          var colorSteps:int = 0;
  904.          var colorList:Array = null;
  905.          var colorType:String = null;
  906.          var selectedColor:Number = NaN;
  907.          var settings:Settings = null;
  908.          if(this.styleManager.colorsLocked)
  909.          {
  910.             settings = this.styleManager.lockedColorSettings;
  911.             colorHold = int(settings.colorHold);
  912.             colorSteps = int(settings.colorSteps);
  913.             colorList = settings.colorList;
  914.             colorType = settings.colorType;
  915.             selectedColor = Number(settings.color);
  916.          }
  917.          else
  918.          {
  919.             colorHold = this.strokeStyle.colorHold;
  920.             colorSteps = this.strokeStyle.colorSteps;
  921.             colorList = this.strokeStyle.colorList;
  922.             colorType = this.strokeStyle.colorType;
  923.             selectedColor = this.strokeStyle.selectedColor;
  924.          }
  925.          switch(colorType)
  926.          {
  927.             case StrokeStyle.FIXED:
  928.                color = selectedColor;
  929.                break;
  930.             case StrokeStyle.LIST:
  931.                if(this.strokeColorHoldCount.count() == colorHold || this.strokeColor == -1)
  932.                {
  933.                   color = this.colorSequence("strokeColor",colorList,colorSteps).nextColor();
  934.                }
  935.                else
  936.                {
  937.                   color = this.strokeColor;
  938.                }
  939.                break;
  940.             case StrokeStyle.SPEED:
  941.                if(this.strokeColorHoldCount.count() == colorHold || this.strokeColor == -1)
  942.                {
  943.                   color = this.colorSequence("strokeColor",colorList,colorSteps).interpolate(0,1,this.drawSpeedPercent);
  944.                }
  945.                else
  946.                {
  947.                   color = this.strokeColor;
  948.                }
  949.                break;
  950.             case StrokeStyle.WIDTH:
  951.                if(this.strokeColorHoldCount.count() == colorHold || this.strokeColor == -1)
  952.                {
  953.                   color = this.colorSequence("strokeColor",colorList,colorSteps).interpolate(0,1,this.strokeWidthPercent);
  954.                }
  955.                else
  956.                {
  957.                   color = this.strokeColor;
  958.                }
  959.                break;
  960.             case StrokeStyle.RANDOM:
  961.                if(this.strokeColorHoldCount.count() == colorHold || this.strokeColor == -1)
  962.                {
  963.                   color = this.colorSequence("strokeColor",colorList,colorSteps).randomColor();
  964.                }
  965.                else
  966.                {
  967.                   color = this.strokeColor;
  968.                }
  969.                break;
  970.             case StrokeStyle.SAMPLE:
  971.                if(this.strokeColorHoldCount.count() == colorHold || this.strokeColor == -1)
  972.                {
  973.                   color = this.layer.canvas.getMouseColor();
  974.                }
  975.                else
  976.                {
  977.                   color = this.strokeColor;
  978.                }
  979.                break;
  980.             case StrokeStyle.SAMPLE_BRUSH:
  981.                this.strokeColorHoldCount.count();
  982.                if(this.strokeColorHoldCount.value == colorHold || this.strokeColor == -1)
  983.                {
  984.                   color = this.layer.canvas.getColorAt(this.x,this.y);
  985.                }
  986.                else
  987.                {
  988.                   color = this.strokeColor;
  989.                }
  990.                break;
  991.             case StrokeStyle.NONE:
  992.                color = 0;
  993.          }
  994.          return color;
  995.       }
  996.       
  997.       private function createEdge() : Edge
  998.       {
  999.          this.width = this.getStrokeEdgeWidth();
  1000.          this.edgeAngle = this.getStrokeEdgeAngle();
  1001.          this.strokeAlpha = this.getStrokeAlpha();
  1002.          this.strokeColor = this.getStrokeColor();
  1003.          this.edge = new Edge(this.pos.x,this.pos.y,this.width,this.edgeAngle,this.style.strokeStyle.lines,this.strokeColor,this.strokeAlpha,null);
  1004.          this.edge.decoGroup = this.getDecoGroup();
  1005.          return this.edge;
  1006.       }
  1007.       
  1008.       private function getStrokeAlpha() : Number
  1009.       {
  1010.          var alpha:Number = NaN;
  1011.          if(!this.styleManager.alphaLocked)
  1012.          {
  1013.             switch(this.strokeStyle.alphaType)
  1014.             {
  1015.                case StrokeStyle.FIXED:
  1016.                   alpha = this.strokeStyle.minAlpha;
  1017.                   break;
  1018.                case StrokeStyle.SPEED:
  1019.                   alpha = this.percentOf(this.drawSpeedPercent,this.strokeStyle.maxAlpha - this.strokeStyle.minAlpha) + this.strokeStyle.minAlpha;
  1020.                   break;
  1021.                case StrokeStyle.WIDTH:
  1022.                   alpha = this.percentOf(this.strokeWidthPercent,this.strokeStyle.maxAlpha - this.strokeStyle.minAlpha) + this.strokeStyle.minAlpha;
  1023.                   break;
  1024.                case StrokeStyle.OSC:
  1025.                   alpha = this.oscObj("strokeAlpha",this.strokeStyle.minAlpha,this.strokeStyle.maxAlpha,this.strokeStyle.alphaSpeed).update().x;
  1026.                   break;
  1027.                case StrokeStyle.RANDOM:
  1028.                   alpha = this.randNum(this.strokeStyle.minAlpha,this.strokeStyle.maxAlpha);
  1029.                   break;
  1030.                case StrokeStyle.NONE:
  1031.                   alpha = 0;
  1032.             }
  1033.          }
  1034.          else
  1035.          {
  1036.             alpha = Number(this.styleManager.lockedColorSettings.alpha);
  1037.          }
  1038.          return alpha;
  1039.       }
  1040.       
  1041.       private function getDecoScale() : Number
  1042.       {
  1043.          var size:Number = NaN;
  1044.          switch(this.decoStyle.sizeType)
  1045.          {
  1046.             case DecoStyle.FIXED:
  1047.                size = this.decoStyle.minSize;
  1048.                break;
  1049.             case DecoStyle.SPEED:
  1050.                size = this.percentOf(this.drawSpeedPercent,this.decoStyle.maxSize - this.decoStyle.minSize) + this.decoStyle.minSize;
  1051.                break;
  1052.             case DecoStyle.WIDTH:
  1053.                size = this.percentOf(this.strokeWidthPercent,this.decoStyle.maxSize - this.decoStyle.minSize) + this.decoStyle.minSize;
  1054.                break;
  1055.             case DecoStyle.OSC:
  1056.                size = this.oscObj("decoSize",this.decoStyle.minSize,this.decoStyle.maxSize,this.decoStyle.sizeSpeed).update().x;
  1057.                break;
  1058.             case DecoStyle.RANDOM:
  1059.                size = this.randNum(this.decoStyle.minSize,this.decoStyle.maxSize);
  1060.                break;
  1061.             case DecoStyle.NONE:
  1062.                size = 1;
  1063.          }
  1064.          return size;
  1065.       }
  1066.       
  1067.       public function addDeco(key:int = 1) : void
  1068.       {
  1069.          this.forceDeco = true;
  1070.          if(key == 0)
  1071.          {
  1072.             key = 10;
  1073.          }
  1074.          this.decoKey = key;
  1075.       }
  1076.       
  1077.       public function get strokeWidthPercent() : Number
  1078.       {
  1079.          return (this.width - this.strokeStyle.minWidth) / Math.max(1,this.strokeStyle.maxWidth - this.strokeStyle.minWidth);
  1080.       }
  1081.       
  1082.       public function get canvasAngleRads() : Number
  1083.       {
  1084.          return this.layer.canvas.angleRads;
  1085.       }
  1086.       
  1087.       private function percentOf(percent:Number, value:Number) : Number
  1088.       {
  1089.          return value * percent;
  1090.       }
  1091.    }
  1092. }
  1093.  
  1094.