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: flash on 2010-3-15

Get Adobe Flash player
by koshitarou 15 Mar 2012
/**
 * Copyright koshitarou ( http://wonderfl.net/user/koshitarou )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/biXx
 */

// forked from matacat's flash on 2010-3-15
package
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.ColorTransform;
    import flash.geom.Matrix;
    import flash.geom.Point;
    import flash.geom.Rectangle;
    
    public class hoge extends Sprite
    {
        public function hoge()
        {
            var wz:int    = stage.stageWidth;
            var hi:int    = stage.stageHeight;
            var ox:Number = -wz / 2;
            var oy:Number = -hi / 2;
            var inic:uint = hue2rgb(0);
            
            var gc:Function = graphics.clear;
            var gf:Function = graphics.beginFill;
            var gr:Function = graphics.drawRect;
            var a:Number    = -wz * 1.41;
            var b:Number    = -hi * 1.41;
            var c:Number    =  wz * 2.83;
            var d:Number    =  hi * 2.83;
            
            x = -ox;
            y = -oy;
            gf(inic);
            gr(a, b, c, d);
            
            var bmp:Bitmap    = new Bitmap( new BitmapData(wz * 0.9, hi * 0.9, false, inic) );
            var copy:Function = bmp.bitmapData.copyPixels;
            
            bmp.x = -bmp.width  / 2;
            bmp.y = -bmp.height / 2;
            addChild(bmp);
            
            var cp:BitmapData = bmp.bitmapData.clone();
            var draw:Function = cp.draw;
            
            var mx:Matrix         = new Matrix(0.9, 0, 0, 0.9);
            var ct:ColorTransform = new ColorTransform(1, 1, 1, 1, -7, -7, -7);
            var rc:Rectangle      = cp.rect;
            var pt:Point          = new Point();
            var cx:int            = wz >> 1;
            var cnt:uint          = 0;
            
            addEventListener(Event.ENTER_FRAME, function(e:Event):void {
                s = 0.4 - (cnt % 40) / 40 * 0.3;
                v = 0.8 + (cnt % 40) / 40 * 0.2;
                
                gc();
                gf(hue2rgb(cnt % 360));
                gr(a, b, c, d);
                
                draw(stage, mx, ct);
                copy(cp, rc, pt);
                
                cnt++;
            });
            
            stage.addEventListener(MouseEvent.MOUSE_MOVE, function(e:MouseEvent):void {
                rotation = e.stageX / cx - 1;
                bmp.x    = ox + e.stageX * 0.1;
                bmp.y    = oy + e.stageY * 0.1;
            });
        }
        
        
        private static var s:Number = 0.1;
        private static var v:Number = 1;
        
        private static function hue2rgb(h:Number):uint
        {
            var i:int = int(h / 60);
            var f:Number = h / 60 - i;
            var p:Number = v * (1 - s);
            var q:Number = v * (1 - s * f);
            var t:Number = v * (1 - s * (1 - f));
            
            switch (i) {
                case 0: return 0xFF * v << 16 | 0xFF * t << 8 | 0xFF * p << 0;
                case 1: return 0xFF * q << 16 | 0xFF * v << 8 | 0xFF * p << 0;
                case 2: return 0xFF * p << 16 | 0xFF * v << 8 | 0xFF * t << 0;
                case 3: return 0xFF * p << 16 | 0xFF * q << 8 | 0xFF * v << 0;
                case 4: return 0xFF * t << 16 | 0xFF * p << 8 | 0xFF * v << 0;
                case 5: return 0xFF * v << 16 | 0xFF * p << 8 | 0xFF * q << 0;
            }
            
            return 0;
        }
    }
}