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

落書きチョーク

もじゃもじゃチョーク
Get Adobe Flash player
by ProjectNya 26 Jan 2011
/**
 * Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/zsh2
 */

////////////////////////////////////////////////////////////////////////////////
// 落書きチョーク
////////////////////////////////////////////////////////////////////////////////

package {

    import flash.display.Sprite;
    import flash.display.StageScaleMode;
    import flash.display.StageAlign;
    import flash.display.Shape;
    import flash.events.Event;
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import flash.geom.Point;
    import flash.geom.Matrix;
    import flash.display.BlendMode;
    import flash.utils.Timer;
    import flash.events.TimerEvent;

    [SWF(backgroundColor="#005500", width="465", height="465", frameRate="30")]

    public class Main extends Sprite {
        private var bitmap:Bitmap;
        private var bitmapData:BitmapData;
        private var canvas:Sprite;
        private var seed:uint;
        private var timer:Timer;
        private static var interval:uint = 50;
        private static var radius:uint = 5;
        private static var thickness:uint = 10;
        private static var color:uint = 0xFFFFFF;
        private static var xPos:uint = 232;
        private static var yPos:uint = 216;
        private static var range:uint = 200;
        private static var radian:Number = Math.PI/180;
        private var x2:Number = 0;
        private var y2:Number = 0;
        private var matrix:Matrix;

        public function Main() {
            //Wonderfl.capture_delay(1);
            init();
        }

        private function init():void {
            graphics.beginFill(0x005500);
            graphics.drawRect(0, 0, 465, 435);
            graphics.endFill();
            graphics.beginFill(0x996633);
            graphics.drawRect(0, 435, 465, 30);
            graphics.endFill();
            //
            bitmapData = new BitmapData(465, 435, true, 0x00000000);
            bitmap = new Bitmap(bitmapData);
            addChild(bitmap);
            canvas = new Sprite();
            seed = uint(Math.random()*10000);
            matrix = new Matrix();
            matrix.translate(xPos, yPos);
            //
            start();
        }
        private function start():void {
            reset();
            timer = new Timer(interval);
            timer.addEventListener(TimerEvent.TIMER, update, false, 0, true);
            timer.start();
        }
        private function stop():void {
            clear();
            if (timer) {
                timer.stop();
                timer.removeEventListener(TimerEvent.TIMER, update);
            }
        }
        private function reset():void {
            canvas.graphics.lineStyle(thickness, color);
            canvas.graphics.moveTo(0, 0);
        }
        private function update(evt:TimerEvent):void {
            var count:uint = evt.target.currentCount;
            if (count%60 == 0) {
                clear();
                reset();
            }
            var a1:Number = Math.random()*360;
            var r1:Number = Math.random();
            r1 = 1 - r1*r1*r1*r1*r1*r1;
            var x1:Number = x2;
            var y1:Number = y2;
            var a2:Number = Math.random()*360;
            var r2:Number = Math.random();
            r2 = 1 - r2*r2*r2*r2*r2*r2;
            x2 = Math.cos(a2)*range*r2;
            y2 = Math.sin(a2)*range*r2;
            canvas.graphics.curveTo(x1, y1, (x1 + x2)/2, (y1 + y2)/2);
            draw();
        }
        private function draw():void {
            bitmapData.lock();
            var bd:BitmapData = bitmapData.clone();
            bd.lock();
            bd.draw(canvas, matrix);
            bd.unlock();
            bitmapData.pixelDissolve(bd, bd.rect, new Point(), seed, 465*435*0.4);
            bd.dispose();
            bitmapData.draw(bitmapData.clone(), null, null, BlendMode.ADD);
            bitmapData.unlock();
        }
        private function clear():void {
            bitmapData.lock();
            bitmapData.fillRect(bitmapData.rect, 0x00000000);
            bitmapData.unlock();
            //
            canvas.graphics.clear();
        }
        
    }

}