home *** CD-ROM | disk | FTP | other *** search
Text File | 2009-10-26 | 38.4 KB | 1,094 lines |
- package com.livebrush.tools
- {
- import com.livebrush.data.Settings;
- import com.livebrush.geom.ColorSequence;
- import com.livebrush.geom.Counter;
- import com.livebrush.geom.Osc;
- import com.livebrush.graphics.DecoGroup;
- import com.livebrush.graphics.Edge;
- import com.livebrush.graphics.Line;
- import com.livebrush.graphics.canvas.Canvas;
- import com.livebrush.graphics.canvas.CanvasManager;
- import com.livebrush.graphics.canvas.LineLayer;
- import com.livebrush.styles.DecoAsset;
- import com.livebrush.styles.DecoStyle;
- import com.livebrush.styles.LineStyle;
- import com.livebrush.styles.StrokeStyle;
- import com.livebrush.styles.Style;
- import com.livebrush.styles.StyleManager;
- import flash.display.MovieClip;
- import flash.events.EventDispatcher;
- import flash.geom.Point;
- import flash.utils.getTimer;
-
- public class LiveBrush extends EventDispatcher
- {
- public static var idList:Array = [];
-
- public static const DRAWING:String = "drawing";
-
- public static const FINISHED:String = "finished";
-
- public static const FINISHING:String = "finishing";
-
- private var strokeAlpha:Number;
-
- public var inPt:Point;
-
- private var oscObjs:Object;
-
- private var strokeColor:Number = -1;
-
- private var accelPt:Point;
-
- public var id:int;
-
- public var lastMousePos:Point;
-
- private var edgeAngle:Number;
-
- private var decoIndex:Number = -1;
-
- private var _lastAnglePos:Point;
-
- private var forceDeco:Boolean = false;
-
- public var layer:LineLayer;
-
- public var pos:Point;
-
- private var decoHoldCount:Counter;
-
- private var decoPos:Object;
-
- public var cacheBuffer:int = 10;
-
- private var decoKey:int = 1;
-
- private var decoColorHoldCount:Counter;
-
- private var counterObjs:Object;
-
- private var velPt:Point;
-
- public var cache:int = 0;
-
- public var state:String = "drawing";
-
- private var decoSuccess:Boolean;
-
- public var dynamicMove:Function;
-
- public var style:Style;
-
- public var showCursor:Boolean = true;
-
- private var decoColor:Number = -1;
-
- private var edge:Edge;
-
- public var lastInPt:Point;
-
- private var colorSequenceObjs:Object;
-
- public var stateIndex:int;
-
- private var strokeColorHoldCount:Counter;
-
- private var width:Number;
-
- private var lastDecoPt:Point;
-
- private var lastDecoTime:Number;
-
- public var dotMc:MovieClip;
-
- private var lastAngle:Number = 0;
-
- public var lastPos:Point;
-
- private var tSuccess:String;
-
- private var _angleRads:Number = 0;
-
- public var line:Line;
-
- public function LiveBrush(style:Style, layer:LineLayer, pos:Point)
- {
- super();
- this.id = getNewID();
- this.oscObjs = {};
- this.counterObjs = {};
- this.colorSequenceObjs = {};
- this.style = style;
- this.layer = layer;
- this.pos = pos.clone();
- this.init();
- }
-
- public static function getNewID() : int
- {
- var newID:int = 0;
- var highestID:int = 0;
- for(var i:int = 0; i < idList.length; i++)
- {
- if(idList[i] >= highestID)
- {
- highestID = int(idList[i]);
- }
- }
- newID = highestID + 1;
- idList.push(newID);
- return newID;
- }
-
- private function getDecoColor() : Number
- {
- var color:Number = NaN;
- switch(this.decoStyle.colorType)
- {
- case DecoStyle.FIXED:
- color = this.decoStyle.selectedColor;
- break;
- case DecoStyle.LIST:
- if(this.decoColorHoldCount.value == this.decoStyle.colorHold || this.decoColor == -1)
- {
- color = this.colorSequence("decoColor",this.decoStyle.colorList,this.decoStyle.colorSteps).nextColor();
- }
- else
- {
- color = this.decoColor;
- }
- break;
- case DecoStyle.SPEED:
- if(this.decoColorHoldCount.count() == this.decoStyle.colorHold || this.decoColor == -1)
- {
- color = this.colorSequence("decoColor",this.decoStyle.colorList,this.decoStyle.colorSteps).interpolate(0,1,this.drawSpeedPercent);
- }
- else
- {
- color = this.decoColor;
- }
- break;
- case DecoStyle.WIDTH:
- if(this.decoColorHoldCount.count() == this.decoStyle.colorHold || this.decoColor == -1)
- {
- color = this.colorSequence("decoColor",this.decoStyle.colorList,this.decoStyle.colorSteps).interpolate(0,1,this.strokeWidthPercent);
- }
- else
- {
- color = this.decoColor;
- }
- break;
- case DecoStyle.RANDOM:
- if(this.decoColorHoldCount.count() == this.decoStyle.colorHold || this.decoColor == -1)
- {
- color = this.colorSequence("decoColor",this.decoStyle.colorList,this.decoStyle.colorSteps).randomColor();
- }
- else
- {
- color = this.decoColor;
- }
- break;
- case DecoStyle.STROKE:
- color = this.strokeColor;
- break;
- case DecoStyle.NONE:
- color = -1;
- }
- return color;
- }
-
- public function setNewLine(_pos:Point = null) : void
- {
- this.line = Line.newLine(this.style.lineStyle.smoothing,this.strokeStyle.strokeType,this.strokeStyle.lines,this.strokeStyle.weight);
- this.line.changed = true;
- this.line.style = this.style;
- this.layer.line = this.line;
- this.velPt = new Point();
- this.accelPt = new Point();
- this.pos = _pos != null ? _pos.clone() : this.pos.clone();
- this.inPt = this.pos.clone();
- this.lastPos = this.pos.clone();
- this.lastMousePos = this.mousePos;
- this.lastDecoPt = this.pos.clone();
- this.lastDecoTime = 0;
- this._lastAnglePos = this.pos;
- }
-
- private function getDecoProps() : Settings
- {
- var initObj:Settings = new Settings();
- var position:Object = this.decoPos = this.getDecoPosition();
- var scaleXY:Number = this.getDecoScale();
- this.decoColor = initObj.color = this.getDecoColor();
- initObj.colorPercent = this.getDecoColorPercent();
- initObj.alpha = this.getDecoAlpha();
- initObj.angle = this.getDecoAngle();
- initObj.pos = position.relative;
- initObj.offset = position.offset;
- initObj.scale = {
- "x":scaleXY * (this.decoStyle.xFlip ? -1 : 1),
- "y":scaleXY * (position.relative >= 0.5 && this.decoStyle.autoFlip || this.decoStyle.yFlip ? -1 : 1)
- };
- initObj.align = this.decoStyle.alignType;
- initObj.brushState = {
- "x":this.x,
- "y":this.y,
- "vx":this.vx,
- "vy":this.vy,
- "speed":this.speed,
- "angleRads":this.angleRads,
- "width":this.width,
- "edgeAngle":this.edgeAngle
- };
- return initObj;
- }
-
- private function init() : void
- {
- this.setNewLine();
- if(this.styleManager.colorsLocked)
- {
- this.strokeColorHoldCount = new Counter(1,this.styleManager.lockedColorSettings.colorHold,1);
- }
- else
- {
- this.strokeColorHoldCount = new Counter(1,this.strokeStyle.colorHold,1);
- }
- this.decoColorHoldCount = new Counter(1,this.decoStyle.colorHold,1);
- this.decoHoldCount = new Counter(1,this.decoStyle.decoHold,1);
- if(this.isDynamic)
- {
- try
- {
- this.dynamicMove = this.lineStyle.getDynamicControl().move;
- }
- catch(e:Error)
- {
- dynamicMove = move;
- lineStyle.type = LineStyle.NORMAL;
- lineStyle.inputSWF = "";
- }
- }
- }
-
- private function degreesToRadians(degrees:Number) : Number
- {
- return degrees * Math.PI / 180;
- }
-
- public function get decoStyle() : DecoStyle
- {
- return this.style.decoStyle;
- }
-
- public function get lineStyle() : LineStyle
- {
- return this.style.lineStyle;
- }
-
- private function randNum(min:Number, max:Number, floor:Boolean = false) : Number
- {
- var rand:Number = min + Math.random() * max;
- return floor ? Math.floor(rand) : rand;
- }
-
- private function getDecoGroup() : DecoGroup
- {
- var t:Object = null;
- var decoGroup:DecoGroup = null;
- var i:int = 0;
- var deco:DecoGroup = null;
- if((this.strokeStyle.decorate || this.forceDeco) && this.line.length > 1)
- {
- t = this.strokeStyle.thresholds;
- this.decoSuccess = true;
- if(t.speed.enabled)
- {
- this.successCheck(this.speed >= t.speed.min);
- this.successCheck(this.speed <= t.speed.max);
- }
- if(t.width.enabled)
- {
- this.successCheck(this.width >= t.width.min);
- this.successCheck(this.width <= t.width.max);
- }
- if(t.angle.enabled)
- {
- this.successCheck(this.edgeAngle >= t.angle.min);
- this.successCheck(this.edgeAngle <= t.angle.max);
- }
- if(t.distance.enabled)
- {
- this.successCheck(this.lastDecoDistance >= t.distance.min);
- this.successCheck(this.lastDecoDistance <= t.distance.max);
- }
- if(t.random.enabled)
- {
- this.successCheck(this.randNum(0,t.random.max,true) == 1);
- }
- if(t.interval.enabled)
- {
- this.successCheck(getTimer() - this.lastDecoTime >= t.interval.min);
- }
- if(this.decoSuccess || this.forceDeco)
- {
- this.lastDecoPt = this.pos.clone();
- this.lastDecoTime = getTimer();
- decoGroup = new DecoGroup();
- for(i = 0; i < this.decoStyle.decoNum; i++)
- {
- decoGroup.addDeco(this.getDecoAsset(),this.getDecoProps());
- }
- this.counterObj("decoOffsetPos").reset();
- if(!this.decoStyle.persist)
- {
- try
- {
- this.oscObj("decoAlpha").reset();
- }
- catch(e:Error)
- {
- }
- try
- {
- this.oscObj("decoTint").reset();
- }
- catch(e:Error)
- {
- }
- try
- {
- this.counterObj("decoAngle").reset();
- }
- catch(e:Error)
- {
- }
- try
- {
- this.oscObj("decoAngle").reset();
- }
- catch(e:Error)
- {
- }
- try
- {
- this.oscObj("decoSize").reset();
- }
- catch(e:Error)
- {
- }
- try
- {
- this.colorSequence("decoColor").reset();
- }
- catch(e:Error)
- {
- }
- try
- {
- this.oscObj("decoPos").reset();
- }
- catch(e:Error)
- {
- }
- try
- {
- this.counterObj("decoPos").reset();
- }
- catch(e:Error)
- {
- }
- try
- {
- this.counterObj("decoSequence").reset();
- }
- catch(e:Error)
- {
- }
- try
- {
- this.decoColorHoldCount.reset();
- }
- catch(e:Error)
- {
- }
- try
- {
- this.decoHoldCount.reset();
- }
- catch(e:Error)
- {
- }
- this.decoColor = -1;
- this.decoIndex = -1;
- }
- this.forceDeco = false;
- }
- }
- return decoGroup;
- }
-
- public function queueFinish() : void
- {
- this.state = this.style.lineStyle.type == LineStyle.NORMAL || this.lineStyle.mouseUpComplete && this.isElastic ? FINISHED : FINISHING;
- }
-
- private function getDecoAlpha() : Number
- {
- var alpha:Number = NaN;
- switch(this.decoStyle.alphaType)
- {
- case DecoStyle.FIXED:
- alpha = this.decoStyle.minAlpha;
- break;
- case DecoStyle.SPEED:
- alpha = this.percentOf(this.drawSpeedPercent,this.decoStyle.maxAlpha - this.decoStyle.minAlpha) + this.decoStyle.minAlpha;
- break;
- case DecoStyle.WIDTH:
- alpha = this.percentOf(this.strokeWidthPercent,this.decoStyle.maxAlpha - this.decoStyle.minAlpha) + this.decoStyle.minAlpha;
- break;
- case DecoStyle.OSC:
- alpha = this.oscObj("decoAlpha",this.decoStyle.minAlpha,this.decoStyle.maxAlpha,this.decoStyle.alphaSpeed).update().x;
- break;
- case DecoStyle.STROKE:
- alpha = this.strokeAlpha;
- break;
- case DecoStyle.RANDOM:
- alpha = this.randNum(this.decoStyle.minAlpha,this.decoStyle.maxAlpha);
- }
- return alpha;
- }
-
- public function get canvasManager() : CanvasManager
- {
- return this.layer.canvas.canvasManager;
- }
-
- private function getDecoColorPercent() : Number
- {
- var percent:Number = NaN;
- switch(this.decoStyle.tintType)
- {
- case DecoStyle.FIXED:
- percent = this.decoStyle.minTint;
- break;
- case DecoStyle.SPEED:
- percent = this.percentOf(this.drawSpeedPercent,this.decoStyle.maxTint - this.decoStyle.minTint) + this.decoStyle.minTint;
- break;
- case DecoStyle.WIDTH:
- percent = this.percentOf(this.strokeWidthPercent,this.decoStyle.maxTint - this.decoStyle.minTint) + this.decoStyle.minTint;
- break;
- case DecoStyle.OSC:
- percent = this.oscObj("decoTint",this.decoStyle.minTint,this.decoStyle.maxTint,this.decoStyle.tintSpeed).update().x;
- break;
- case DecoStyle.RANDOM:
- percent = this.randNum(this.decoStyle.minTint,this.decoStyle.maxTint);
- }
- return percent;
- }
-
- private function colorSequence(id:String, colorList:Array = null, strokeColorSteps:int = 1) : ColorSequence
- {
- if(this.colorSequenceObjs[id] == null)
- {
- this.colorSequenceObjs[id] = new ColorSequence(colorList,strokeColorSteps);
- }
- return this.colorSequenceObjs[id];
- }
-
- public function get speed() : Number
- {
- return Math.sqrt(this.vx * this.vx + this.vy * this.vy);
- }
-
- public function get isElastic() : Boolean
- {
- return this.lineStyle.type == LineStyle.ELASTIC;
- }
-
- public function get canvas() : Canvas
- {
- return this.layer.canvas;
- }
-
- public function get strokeStyle() : StrokeStyle
- {
- return this.style.strokeStyle;
- }
-
- private function counterObj(id:String, start:Number = 1, end:Number = 2, speed:Number = 1) : Counter
- {
- if(this.counterObjs[id] == null)
- {
- this.counterObjs[id] = new Counter(start,end,speed);
- }
- return this.counterObjs[id];
- }
-
- public function get drawSpeedPercent() : Number
- {
- return (this.speedMax - this.lineStyle.minDrawSpeed) / Math.max(1,this.lineStyle.maxDrawSpeed - this.lineStyle.minDrawSpeed);
- }
-
- public function get mousePos() : Point
- {
- return this.layer.canvas.mousePt;
- }
-
- private function getDecoAngle() : Number
- {
- var angle:Number = NaN;
- var decoPosPt:Point = null;
- var decoOffsetPt:Point = null;
- var dirPt:Point = null;
- var angleRads:Number = NaN;
- switch(this.decoStyle.angleType)
- {
- case DecoStyle.FIXED:
- angle = this.decoStyle.minAngle;
- break;
- case DecoStyle.WIDTH:
- angle = this.percentOf(this.strokeWidthPercent,this.decoStyle.maxAngle - this.decoStyle.minAngle) + this.decoStyle.minAngle;
- break;
- case DecoStyle.DIR:
- angle = this.angle + this.decoStyle.minAngle;
- break;
- case DecoStyle.SPEED:
- angle = this.percentOf(this.drawSpeedPercent,this.decoStyle.maxAngle - this.decoStyle.minAngle) + this.decoStyle.minAngle;
- break;
- case DecoStyle.OSC:
- angle = this.oscObj("decoAngle",this.decoStyle.minAngle,this.decoStyle.maxAngle,this.decoStyle.angleSpeed / 100).update().x;
- break;
- case DecoStyle.ROTATE:
- angle = this.counterObj("decoAngle",this.decoStyle.minAngle,this.decoStyle.maxAngle,this.decoStyle.angleSpeed).count();
- break;
- case DecoStyle.POS_DIR:
- decoPosPt = this.edge.midPoint(this.decoPos.relative);
- decoOffsetPt = decoPosPt.add(this.decoPos.offset);
- dirPt = decoOffsetPt.subtract(decoPosPt);
- angleRads = Math.atan2(dirPt.y,dirPt.x) + Math.PI / 2;
- angle = angleRads * 180 / Math.PI;
- break;
- case DecoStyle.RANDOM:
- angle = this.randNum(this.decoStyle.minAngle,this.decoStyle.maxAngle);
- break;
- case DecoStyle.NONE:
- angle = 0;
- }
- return angle;
- }
-
- public function get lastDecoDistance() : Number
- {
- return Point.distance(this.lastDecoPt,this.pos);
- }
-
- public function get y() : Number
- {
- return this.pos.y;
- }
-
- private function getDecoPosition() : Object
- {
- var pos:Number = NaN;
- var angle:Number = NaN;
- var maxRadius:Number = NaN;
- var radius:Number = NaN;
- var offset:Point = new Point();
- switch(this.decoStyle.posType)
- {
- case DecoStyle.FIXED:
- pos = this.decoStyle.minPos;
- break;
- case DecoStyle.RANDOM:
- pos = this.randNum(this.decoStyle.minPos,this.decoStyle.maxPos);
- break;
- case DecoStyle.A:
- pos = 0;
- break;
- case DecoStyle.B:
- pos = 1;
- break;
- case DecoStyle.CENTER:
- pos = 0.5;
- break;
- case DecoStyle.ALT:
- pos = this.counterObj("decoPos",this.decoStyle.minPos,this.decoStyle.maxPos,this.decoStyle.maxPos - this.decoStyle.minPos).count();
- break;
- case DecoStyle.SPEED:
- pos = this.percentOf(this.drawSpeedPercent,this.decoStyle.maxPos - this.decoStyle.minPos) + this.decoStyle.minPos;
- break;
- case DecoStyle.WIDTH:
- pos = this.percentOf(this.strokeWidthPercent,this.decoStyle.maxPos - this.decoStyle.minPos) + this.decoStyle.minPos;
- break;
- case DecoStyle.OSC:
- pos = this.oscObj("decoPos",this.decoStyle.minPos,this.decoStyle.maxPos,this.decoStyle.posSpeed).update().x;
- break;
- case DecoStyle.SCATTER:
- pos = 0.5;
- maxRadius = Math.max(1,this.decoStyle.maxPos);
- radius = Math.sqrt(Math.random()) * maxRadius;
- angle = this.degreesToRadians(this.decoStyle.minPos) + this.angleRads + this.counterObj("decoOffsetPos",0,Math.PI * 2,Math.PI * 2 / this.decoStyle.decoNum).count();
- offset.x = Math.cos(angle) * radius;
- offset.y = Math.sin(angle) * radius;
- break;
- case DecoStyle.ORBIT:
- pos = 0.5;
- angle = this.degreesToRadians(this.decoStyle.minPos) + this.angleRads + this.counterObj("decoOffsetPos",0,Math.PI * 2,Math.PI * 2 / this.decoStyle.decoNum).count();
- offset.x = Math.cos(angle) * Math.max(1,this.decoStyle.maxPos);
- offset.y = Math.sin(angle) * Math.max(1,this.decoStyle.maxPos);
- }
- return {
- "relative":pos,
- "offset":offset
- };
- }
-
- public function get x() : Number
- {
- return this.pos.x;
- }
-
- private function getStrokeEdgeAngle() : Number
- {
- var angle:Number = NaN;
- switch(this.strokeStyle.angleType)
- {
- case StrokeStyle.FIXED:
- angle = this.strokeStyle.minAngle;
- break;
- case StrokeStyle.WIDTH:
- angle = this.percentOf(this.strokeWidthPercent,this.strokeStyle.maxAngle - this.strokeStyle.minAngle) + this.strokeStyle.minAngle;
- break;
- case StrokeStyle.DIR:
- angle = this.angle + this.strokeStyle.minAngle;
- break;
- case StrokeStyle.SPEED:
- angle = this.percentOf(this.drawSpeedPercent,this.strokeStyle.maxAngle - this.strokeStyle.minAngle) + this.strokeStyle.minAngle;
- break;
- case StrokeStyle.OSC:
- angle = this.oscObj("strokeAngle",this.strokeStyle.minAngle,this.strokeStyle.maxAngle,this.strokeStyle.angleSpeed / 100).update().x;
- break;
- case StrokeStyle.ROTATE:
- angle = this.counterObj("edgeAngle",this.strokeStyle.minAngle,this.strokeStyle.maxAngle,this.strokeStyle.angleSpeed).count();
- break;
- case StrokeStyle.RANDOM:
- angle = this.randNum(this.strokeStyle.minAngle,this.strokeStyle.maxAngle);
- }
- return angle;
- }
-
- private function getDecoAsset() : DecoAsset
- {
- var decoAsset:DecoAsset = null;
- if(this.forceDeco)
- {
- this.decoIndex = Math.min(this.decoKey,this.decoStyle.decoSet.activeLength) - 1;
- decoAsset = this.decoStyle.decoSet.getDecoByIndex(this.decoIndex);
- }
- else
- {
- switch(this.decoStyle.orderType)
- {
- case DecoStyle.SEQUENCE_DECO:
- if(this.decoHoldCount.count() == this.decoStyle.decoHold || this.decoIndex == -1)
- {
- this.decoIndex = this.counterObj("decoSequence",0,this.decoStyle.decoSet.activeLength - 1,1).count();
- decoAsset = this.decoStyle.decoSet.getActiveDecoByIndex(this.decoIndex);
- }
- else
- {
- decoAsset = this.decoStyle.decoSet.getActiveDecoByIndex(this.decoIndex);
- }
- break;
- case DecoStyle.FIXED_DECO:
- if(this.decoHoldCount.count() == this.decoStyle.decoHold || this.decoIndex == -1)
- {
- this.decoIndex = this.decoStyle.selectedDecoIndex;
- decoAsset = this.decoStyle.decoSet.getDecoByIndex(this.decoIndex);
- }
- else
- {
- decoAsset = this.decoStyle.decoSet.getActiveDecoByIndex(this.decoIndex);
- }
- break;
- case DecoStyle.RANDOM_DECO:
- if(this.decoHoldCount.count() == this.decoStyle.decoHold || this.decoIndex == -1)
- {
- this.decoIndex = this.randNum(0,this.decoStyle.decoSet.activeLength,true);
- decoAsset = this.decoStyle.decoSet.getActiveDecoByIndex(this.decoIndex);
- }
- else
- {
- decoAsset = this.decoStyle.decoSet.getActiveDecoByIndex(this.decoIndex);
- }
- }
- }
- return decoAsset;
- }
-
- public function die() : void
- {
- }
-
- private function oscObj(id:String, center:Number = 0.5, range:Number = 50, speed:Number = 10) : Osc
- {
- var realRange:Number = NaN;
- if(this.oscObjs[id] == null)
- {
- realRange = range - center;
- range = realRange / 2;
- center = range + center;
- this.oscObjs[id] = new Osc(center,center,range,range,speed);
- }
- return this.oscObjs[id];
- }
-
- public function get angleRads() : Number
- {
- return this._angleRads;
- }
-
- public function get speedMax() : Number
- {
- return Math.min(this.speed,this.lineStyle.maxDrawSpeed);
- }
-
- public function get mouseSpeed() : Number
- {
- return this.layer.canvas.mouseSpeed;
- }
-
- private function getStrokeEdgeWidth() : Number
- {
- var width:Number = NaN;
- if(this.strokeStyle.widthType == StrokeStyle.FIXED)
- {
- width = this.style.strokeStyle.minWidth;
- }
- else if(this.strokeStyle.widthType == StrokeStyle.SPEED)
- {
- width = this.percentOf(this.drawSpeedPercent,this.strokeStyle.maxWidth - this.strokeStyle.minWidth) + this.strokeStyle.minWidth;
- }
- else if(this.strokeStyle.widthType == StrokeStyle.OSC)
- {
- width = this.oscObj("strokeWidth",this.strokeStyle.minWidth,this.strokeStyle.maxWidth,this.strokeStyle.widthSpeed).update().x;
- }
- else if(this.strokeStyle.widthType == StrokeStyle.RANDOM)
- {
- width = this.randNum(this.strokeStyle.minWidth,this.strokeStyle.maxWidth);
- }
- return width;
- }
-
- public function get isDynamic() : Boolean
- {
- return this.lineStyle.type == LineStyle.DYNAMIC;
- }
-
- public function get vx() : Number
- {
- return this.velPt.x;
- }
-
- public function get vy() : Number
- {
- return this.velPt.y;
- }
-
- public function get styleManager() : StyleManager
- {
- return this.style.styleManager;
- }
-
- private function successCheck(condition:Boolean) : Boolean
- {
- this.decoSuccess = this.decoSuccess ? condition : false;
- return condition;
- }
-
- public function move() : Boolean
- {
- var speed:Number;
- var targetPt:Point;
- var angle:Number = NaN;
- var slowVX:Number = NaN;
- var slowVY:Number = NaN;
- var dist:Number = NaN;
- var moving:Boolean = false;
- if(this.state == DRAWING && !this.lineStyle.lockMouse)
- {
- this.inPt = this.mousePos;
- }
- targetPt = this.inPt;
- if(this.lineStyle.type == LineStyle.ELASTIC || this.lineStyle.type == LineStyle.NORMAL || this.state == FINISHING)
- {
- if((this.style.lineStyle.type == LineStyle.ELASTIC || this.state == FINISHING) && this.style.lineStyle.elastic > 0)
- {
- this.accelPt.x = (targetPt.x - this.pos.x) * this.style.lineStyle.elastic;
- this.accelPt.y = (targetPt.y - this.pos.y) * this.style.lineStyle.elastic;
- this.velPt = this.velPt.add(this.accelPt);
- this.velPt.x *= this.style.lineStyle.friction;
- this.velPt.y *= this.style.lineStyle.friction;
- }
- else if((this.style.lineStyle.type == LineStyle.ELASTIC || this.state == FINISHING) && this.style.lineStyle.friction > 0)
- {
- this.velPt.x = (targetPt.x - this.pos.x) * this.style.lineStyle.friction;
- this.velPt.y = (targetPt.y - this.pos.y) * this.style.lineStyle.friction;
- }
- else
- {
- this.velPt.x = targetPt.x - this.pos.x;
- this.velPt.y = targetPt.y - this.pos.y;
- }
- this.pos = this.pos.add(this.velPt);
- }
- else if(this.style.lineStyle.type == LineStyle.DYNAMIC)
- {
- try
- {
- this.pos = this.dynamicMove(targetPt.clone(),this.pos.clone()).clone();
- this.velPt = this.pos.subtract(this.lastPos);
- }
- catch(e:Error)
- {
- lineStyle.type = LineStyle.NORMAL;
- move();
- }
- }
- speed = this.speed;
- if(speed >= this.lineStyle.minDrawSpeed || this.line.length == 0)
- {
- moving = true;
- angle = Math.atan2(this.vy,this.vx);
- if(speed > 4 || this.line.length < 7 || this.state == FINISHING || this.style.lineStyle.type == LineStyle.DYNAMIC)
- {
- this._angleRads = angle;
- this._lastAnglePos = this.pos;
- this.lastAngle = angle;
- }
- else
- {
- slowVX = this.pos.x - this._lastAnglePos.x;
- slowVY = this.pos.y - this._lastAnglePos.y;
- dist = Point.distance(this.pos,this._lastAnglePos);
- if(dist > 10)
- {
- this._angleRads = Math.atan2(slowVY,slowVX);
- this._lastAnglePos = this.pos.clone();
- }
- }
- this.line.addEdge(this.createEdge());
- this.lastPos = this.pos.clone();
- }
- if(speed <= this.lineStyle.minDrawSpeed && this.state == FINISHING)
- {
- this.state = FINISHED;
- moving = false;
- }
- return moving;
- }
-
- public function get angle() : Number
- {
- return this.angleRads * 180 / Math.PI;
- }
-
- private function getStrokeColor() : uint
- {
- var color:Number = NaN;
- var colorHold:int = 0;
- var colorSteps:int = 0;
- var colorList:Array = null;
- var colorType:String = null;
- var selectedColor:Number = NaN;
- var settings:Settings = null;
- if(this.styleManager.colorsLocked)
- {
- settings = this.styleManager.lockedColorSettings;
- colorHold = int(settings.colorHold);
- colorSteps = int(settings.colorSteps);
- colorList = settings.colorList;
- colorType = settings.colorType;
- selectedColor = Number(settings.color);
- }
- else
- {
- colorHold = this.strokeStyle.colorHold;
- colorSteps = this.strokeStyle.colorSteps;
- colorList = this.strokeStyle.colorList;
- colorType = this.strokeStyle.colorType;
- selectedColor = this.strokeStyle.selectedColor;
- }
- switch(colorType)
- {
- case StrokeStyle.FIXED:
- color = selectedColor;
- break;
- case StrokeStyle.LIST:
- if(this.strokeColorHoldCount.count() == colorHold || this.strokeColor == -1)
- {
- color = this.colorSequence("strokeColor",colorList,colorSteps).nextColor();
- }
- else
- {
- color = this.strokeColor;
- }
- break;
- case StrokeStyle.SPEED:
- if(this.strokeColorHoldCount.count() == colorHold || this.strokeColor == -1)
- {
- color = this.colorSequence("strokeColor",colorList,colorSteps).interpolate(0,1,this.drawSpeedPercent);
- }
- else
- {
- color = this.strokeColor;
- }
- break;
- case StrokeStyle.WIDTH:
- if(this.strokeColorHoldCount.count() == colorHold || this.strokeColor == -1)
- {
- color = this.colorSequence("strokeColor",colorList,colorSteps).interpolate(0,1,this.strokeWidthPercent);
- }
- else
- {
- color = this.strokeColor;
- }
- break;
- case StrokeStyle.RANDOM:
- if(this.strokeColorHoldCount.count() == colorHold || this.strokeColor == -1)
- {
- color = this.colorSequence("strokeColor",colorList,colorSteps).randomColor();
- }
- else
- {
- color = this.strokeColor;
- }
- break;
- case StrokeStyle.SAMPLE:
- if(this.strokeColorHoldCount.count() == colorHold || this.strokeColor == -1)
- {
- color = this.layer.canvas.getMouseColor();
- }
- else
- {
- color = this.strokeColor;
- }
- break;
- case StrokeStyle.SAMPLE_BRUSH:
- this.strokeColorHoldCount.count();
- if(this.strokeColorHoldCount.value == colorHold || this.strokeColor == -1)
- {
- color = this.layer.canvas.getColorAt(this.x,this.y);
- }
- else
- {
- color = this.strokeColor;
- }
- break;
- case StrokeStyle.NONE:
- color = 0;
- }
- return color;
- }
-
- private function createEdge() : Edge
- {
- this.width = this.getStrokeEdgeWidth();
- this.edgeAngle = this.getStrokeEdgeAngle();
- this.strokeAlpha = this.getStrokeAlpha();
- this.strokeColor = this.getStrokeColor();
- this.edge = new Edge(this.pos.x,this.pos.y,this.width,this.edgeAngle,this.style.strokeStyle.lines,this.strokeColor,this.strokeAlpha,null);
- this.edge.decoGroup = this.getDecoGroup();
- return this.edge;
- }
-
- private function getStrokeAlpha() : Number
- {
- var alpha:Number = NaN;
- if(!this.styleManager.alphaLocked)
- {
- switch(this.strokeStyle.alphaType)
- {
- case StrokeStyle.FIXED:
- alpha = this.strokeStyle.minAlpha;
- break;
- case StrokeStyle.SPEED:
- alpha = this.percentOf(this.drawSpeedPercent,this.strokeStyle.maxAlpha - this.strokeStyle.minAlpha) + this.strokeStyle.minAlpha;
- break;
- case StrokeStyle.WIDTH:
- alpha = this.percentOf(this.strokeWidthPercent,this.strokeStyle.maxAlpha - this.strokeStyle.minAlpha) + this.strokeStyle.minAlpha;
- break;
- case StrokeStyle.OSC:
- alpha = this.oscObj("strokeAlpha",this.strokeStyle.minAlpha,this.strokeStyle.maxAlpha,this.strokeStyle.alphaSpeed).update().x;
- break;
- case StrokeStyle.RANDOM:
- alpha = this.randNum(this.strokeStyle.minAlpha,this.strokeStyle.maxAlpha);
- break;
- case StrokeStyle.NONE:
- alpha = 0;
- }
- }
- else
- {
- alpha = Number(this.styleManager.lockedColorSettings.alpha);
- }
- return alpha;
- }
-
- private function getDecoScale() : Number
- {
- var size:Number = NaN;
- switch(this.decoStyle.sizeType)
- {
- case DecoStyle.FIXED:
- size = this.decoStyle.minSize;
- break;
- case DecoStyle.SPEED:
- size = this.percentOf(this.drawSpeedPercent,this.decoStyle.maxSize - this.decoStyle.minSize) + this.decoStyle.minSize;
- break;
- case DecoStyle.WIDTH:
- size = this.percentOf(this.strokeWidthPercent,this.decoStyle.maxSize - this.decoStyle.minSize) + this.decoStyle.minSize;
- break;
- case DecoStyle.OSC:
- size = this.oscObj("decoSize",this.decoStyle.minSize,this.decoStyle.maxSize,this.decoStyle.sizeSpeed).update().x;
- break;
- case DecoStyle.RANDOM:
- size = this.randNum(this.decoStyle.minSize,this.decoStyle.maxSize);
- break;
- case DecoStyle.NONE:
- size = 1;
- }
- return size;
- }
-
- public function addDeco(key:int = 1) : void
- {
- this.forceDeco = true;
- if(key == 0)
- {
- key = 10;
- }
- this.decoKey = key;
- }
-
- public function get strokeWidthPercent() : Number
- {
- return (this.width - this.strokeStyle.minWidth) / Math.max(1,this.strokeStyle.maxWidth - this.strokeStyle.minWidth);
- }
-
- public function get canvasAngleRads() : Number
- {
- return this.layer.canvas.angleRads;
- }
-
- private function percentOf(percent:Number, value:Number) : Number
- {
- return value * percent;
- }
- }
- }
-
-