In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

forked from: Penice (pen-nice)

minimarize
Get Adobe Flash player
by whirlpower 23 Nov 2010
/**
 * Copyright whirlpower ( http://wonderfl.net/user/whirlpower )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/tyna
 */

/*
forked from jozefchutka's Penice (pen-nice)
minimarize
*/

package
{
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.Point;
    
    [SWF(frameRate="30", backgroundColor="#FFFFFF")]
    public class Penice extends Sprite
    {
        private var speed:Point;
        private var position:Point;
        private var thickness:Number = 1;
        
        private var size:Number = 1.0;
        private var steps:Number = 5.0;
        private var speedSmoothness:Number = 17.0;
        private var speedDecel:Number = 1.15;
        private var minSize:Number = 0.5;
        private var maxSize:Number = 20.0;
        private var sot:Number = 2.0;
        private var thicknessSmoothness:Number = 2.0;
        
        private var drawing:Boolean = false;
        
        public function Penice()
        {
            super();
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            
            addEventListener(Event.ENTER_FRAME, onEnterFrame);
            stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
            stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
        }
        
        private function onMouseDown(event:MouseEvent):void
        {
            drawing = true;
            speed = new Point(0, 0);
            position = new Point(mouseX, mouseY);
            thickness = 1;
            graphics.lineStyle(2);
            graphics.moveTo(position.x, position.y);
        }
        
        private function onMouseUp(event:MouseEvent):void
        {
            drawing = false;
        }
        
        private function onEnterFrame(event:Event):void
        {
            if(!drawing) return;
            
            for(var i:uint = 1; i <= steps; i++)
            {
                speed.x += ((position.x + i / steps * (mouseX - position.x)) - position.x) / speedSmoothness;
                speed.y += ((position.y + i / steps * (mouseY - position.y)) - position.y) / speedSmoothness;
                
                speed.x /= speedDecel;
                speed.y /= speedDecel;
                
                position.x += speed.x;
                position.y += speed.y;
            
                var s:Number = Math.sqrt(speed.x * speed.x + speed.y * speed.y);
                thickness += (s / sot - thickness) / thicknessSmoothness;
                thickness = Math.min(Math.max(thickness, minSize), maxSize);
                
                graphics.lineStyle(thickness * size);
                graphics.lineTo(position.x, position.y);
            }
        }
    }
}