/ Published in: ActionScript 3
Expand |
Embed | Plain Text
var loc:Vector.<Point> = new Vector.<Point>(); var lifts:Vector.<int> = new Vector.<int>(); var index:int = 0; var resolution:int = 1; var down:Boolean; stage.addEventListener(MouseEvent.MOUSE_DOWN, onDown); stage.addEventListener(MouseEvent.MOUSE_UP, onUp); stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyReleased); addEventListener(Event.ENTER_FRAME, onLoop); function onKeyReleased(evt:KeyboardEvent):void{ if (evt.keyCode == Keyboard.RIGHT){ resolution -= 1; if (resolution <1) resolution = 1; }else if (evt.keyCode == Keyboard.LEFT){ resolution += 1; } } function onDown(evt:MouseEvent):void{ down = true; lifts.push(index); } function onUp(evt:MouseEvent):void{ down = false; } function onLoop(evt:Event):void { if (down){ loc[index] = new Point(mouseX, mouseY); index++; } graphics.clear(); graphics.lineStyle(0,0x000000); var j:int = 0; var lift:int; var liftLength:int = lifts.length; var lastLoc:int = loc.length - 1; for (var i:int = 0; i<liftLength; i++){ j = lifts[i]; graphics.moveTo(loc[j].x, loc[j].y); if (i <liftLength - 1){ lift = lifts[i + 1] - 1; }else{ lift = lastLoc; } while (j <lift){ j++; if (j % resolution == 1 || resolution == 1){ graphics.lineTo(loc[j].x, loc[j].y); } } graphics.lineTo(loc[j].x, loc[j].y); } }
Comments
Subscribe to comments
You need to login to post a comment.

Just a tid-bit. For those wanting smoother lines, bump up the frame rate. Had mine at 60 for good results.