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: forked from: OilPainting

/**
 * Copyright Mae_ITR ( http://wonderfl.net/user/Mae_ITR )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/ggJ3
 */

// forked from zigxzag's forked from: OilPainting
// forked from k3lab's OilPainting

package {
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.display.CapsStyle;
    import flash.display.LineScaleMode;

    import flash.filters.DropShadowFilter;

    public class FlashTest extends Sprite {
        private var targetLayer:Sprite;
        private var layers:Array;
        private var layerNum:int = 4;
        private var currentLayerNum:int = 1;
        
        private var prevX:int;
        private var prevY:int;
        private var startPosX:int;
        private var startPosY:int;
        private var disX:Number;
        private var disY:Number;
        private var colors:Array = [0x000000,0x999999,0xCCCCCC,0xFFFFFF];
        private var color:uint = 0x000000;
        
        public function FlashTest() {
            var filter:DropShadowFilter = new DropShadowFilter(0, 90);
	        layers = new Array();
    	    for (var i:int = 0; i < layerNum;i++ ) {
    	        layers[i] = new Sprite;
        		layers[i].filters = [filter];
        		layers[i].doubleClickEnabled = true;
        		addChild(layers[i]);
    	    }			
            targetLayer = layers[0];			
			
	        stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
            stage.addEventListener(MouseEvent.MOUSE_MOVE, _move);
            stage.addEventListener(MouseEvent.DOUBLE_CLICK,onMouseDoubleClick)
        }
        private function onMouseDown(e:MouseEvent):void 
    	{			
    		color = colors[currentLayerNum]
    		targetLayer = layers[currentLayerNum];
    		if (currentLayerNum >= layerNum - 1) {
    			currentLayerNum = 0;
    		}else {
    			currentLayerNum++;
    		}
    	}
        private function onMouseDoubleClick(e:MouseEvent):void{
            for (var i:int = 0; i < layerNum;i++ ) {
    		    layers[i].graphics.clear();
    	    }
	    }

        private function _move(e:MouseEvent):void {
            
            var distance:Number = Math.sqrt(Math.pow(prevX - startPosX, 2) + Math.pow(prevY - startPosY, 2))
            var a:Number = distance * 10 * (Math.pow(Math.random(), 2) - 0.5)
            var r:Number = Math.random() - 0.5
            var size:Number = Math.random() * 18 / distance
			
            disX = (prevX - startPosX) * Math.sin(0.5) + startPosX;
            disY = (prevY - startPosY) * Math.cos(0.5) + startPosY;
            startPosX = prevX;
            startPosY = prevY;
            prevX = mouseX
            prevY = mouseY
            
            targetLayer.graphics.moveTo(startPosX, startPosY);
            targetLayer.graphics.curveTo(disX,disY,prevX,prevY)
            targetLayer.graphics.lineStyle(((Math.random()+20/10-0.5)*size+(1-Math.random()+30/20-0.5)*size), color,1, false, LineScaleMode.NONE, CapsStyle.ROUND);	
            targetLayer.graphics.moveTo(startPosX + a, startPosY + a);
            targetLayer.graphics.lineTo(startPosX+r+a, startPosY+r+a);
            targetLayer.graphics.endFill();
        }
    }
}