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

[朝ワン] オーロラ

朝ワン(∪^ω^)ワン
何かきれいなのできた。
@author jc at bk-zen.com
Get Adobe Flash player
by bkzen 27 Aug 2009
/**
 * Copyright bkzen ( http://wonderfl.net/user/bkzen )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/5wIM
 */

package  
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.BlendMode;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.filters.BlurFilter;
    import flash.geom.ColorTransform;
    import flash.geom.Matrix;
    import flash.geom.Point;
    import net.hires.debug.Stats;
    
    /**
     * 朝ワン(∪^ω^)ワン
     * 何かきれいなのできた。
     * @author jc at bk-zen.com
     */
    [SWF (backgroundColor = "0x0", frameRate = "60", width = "465", height = "465")]
    public class Asawon13 extends Sprite
    {
        private var bmd: BitmapData;
        private var first: Particle;
        private var prev: Particle;
        private var cnt: int = 0;
        private var colCnt: int = 0;
        private var forceMap:BitmapData;
        private var seed: int;
        private var arr: Array;
        private var point1: Point = new Point();
        private var point2: Point = new Point();
        private var basePoint: Point = new Point();
        private var blur: BlurFilter = new BlurFilter(2, 2);
        private var baseMatrix: Matrix = new Matrix();
        private var canvas: BitmapData;
        private var colorTf: ColorTransform = new ColorTransform(1, 1, 1, 1, -8, -8, -8);
        
        public function Asawon13() 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }
        
        private function init(e: Event = null): void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            canvas = new BitmapData(465, 465, false, 0x0);
            addChild(new Bitmap(bmd = canvas.clone()));
            addChild(new Stats());
            forceMap = new BitmapData(10, 10, false);
            forceMap.perlinNoise(20, 20, 4, seed = Math.random() * 0xFFFF, false, true, 3, false, arr = [point1, point2]);
            addEventListener(Event.ENTER_FRAME, loopA);
        }
        
        private function loopA(e: Event ): void 
        {
            cnt ++;
            if (first == null) first = prev = new Particle();
            else prev = prev.next = new Particle();
            loopB();
            if (cnt == 10000) 
            {
                removeEventListener(Event.ENTER_FRAME, loopA);
                addEventListener(Event.ENTER_FRAME, loopB);
            }
        }
        
        private function loopB(e: Event = null): void 
        {
            var p: Particle = first, col: uint = forceMap.getPixel(5, 5), r: Number = (( col >> 16 & 0xff) - 128) * 0.0004, g: Number = (( col >>  8 & 0xff) - 128) * 0.0004;
            colCnt = (colCnt + 1) % 1440;
            col = getColor(colCnt / 4);
            if (colCnt % 2 == 0) point1.x = point2.y ++;
            forceMap.perlinNoise(20, 20, 4, seed, false, true, 3, false, arr);
            canvas.lock();
            while ((p = p.next) != null)
            {
                p.x += (p.vx = p.vx * (0.95 + p.r + (p.a * 0.0005)) + r);
                p.y += (p.vy = p.vy * (0.95 + p.r + (p.a * 0.0005)) + g);
                canvas.setPixel(p.x, p.y, col);
                p.a ++;
                if (p.a > 340) 
                {
                    p.x = p.y = 232;
                    p.vx = p.vy = p.a = 0;
                }
            }
            canvas.colorTransform(bmd.rect, colorTf);
            canvas.unlock();
            bmd.lock();
            bmd.draw(canvas, baseMatrix, null, BlendMode.ADD);
            bmd.applyFilter(bmd, bmd.rect, basePoint, blur);
            bmd.unlock();
        }
        private function getColor(h: Number): uint
        {
            var c: int = h < 180 ? 0x2FD - (h * 4.25) : (h - 180) * 4.25;
            var r: uint = (c > 0x1FE ? 0xFF : c < 0xFF ? 0 : c - 0xFF);
            c = h < 120 ? h * 4.25 + 0xFF : h < 300 ? 0x1FE - (h - 180) * 4.25 : 0;
            var g: uint = (c > 0x1FE ? 0xFF : c < 0xFF ? 0 : c - 0xFF);
            c = h < 120 ? 0 : h < 240 ? (h - 120) * 4.25 + 0xFF : 0x1FE - (h - 300) * 4.25;
            var b: uint = (c > 0x1FE ? 0xFF : c < 0xFF ? 0 : c - 0xFF);
            return (r << 16) | (g << 8) | b;
        }
    }
}
class Particle
{
    public var x: Number = 232;
    public var y: Number = 232;
    public var a: Number = 0;
    public var r: Number = Math.random() * 0.01;
    public var vx: Number = 0;
    public var vy: Number = 0;
    public var next: Particle;
}