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

適当にピクセルをまき散らしてみた

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

package  {
    import flash.display.Sprite;
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import flash.events.Event;
    import flash.geom.Point;
    import flash.geom.Matrix;
    import net.hires.debug.Stats;

    [SWF(width="465", height="465", backgroundColor="0", frameRate="30")]    
    public class Main extends Sprite{
        
        private static const PIX_NUM:int = 5000
        private static const GLOW_SET_NUM:int = 8
        private var _w:Number
        private var _h:Number
        private var _canvas:BitmapData
        private var _glow:BitmapData
        
        private var _pixels:Vector.<Point> = new Vector.<Point>()
        
        public function Main() {
            _w = stage.stageWidth
            _h = stage.stageHeight
            _canvas = new BitmapData(_w, _h, false, 0)
            _glow = new BitmapData(_w/GLOW_SET_NUM, _h/GLOW_SET_NUM, false, 0)
            var bm:Bitmap = addChild(new Bitmap(_canvas)) as Bitmap
            var glowBm:Bitmap = addChild(new Bitmap(_glow, "never", true)) as Bitmap
            glowBm.blendMode = "add"
            glowBm.scaleX = glowBm.scaleY = GLOW_SET_NUM
            //
            startPix()
        }
        
        private function startPix():void{
            for(var i:int=0; i<PIX_NUM; i++){
                var pix:Point = new Point()
                pix.x = Math.random()*_w
                pix.y = Math.random()*_h
                _pixels.push(pix)
            }
            stage.addEventListener(Event.ENTER_FRAME, update)
            addChild(new Stats());
        }
        
        private function update(e:Event):void{
            _canvas.lock()
            _canvas.fillRect(_canvas.rect, 0)
            for(var i:int=0; i<PIX_NUM; i++){
                var dist:Number = Math.sqrt((mouseX-_pixels[i].x)*(mouseX-_pixels[i].x)+(mouseY-_pixels[i].y)*(mouseY-_pixels[i].y));
                var rad:Number = Math.atan2(mouseY-_pixels[i].y, mouseX-_pixels[i].x);
                var rot:Number = rad*180/Math.PI;
                _pixels[i].x += Math.cos(rot*Math.PI/180)*200//(dist/100)
                _pixels[i].y += Math.sin(rot*Math.PI/180)*200//(dist/100)
                if(_pixels[i].x > _w || _pixels[i].x < 0) _pixels[i].x = Math.random()*_w
                if(_pixels[i].y > _h || _pixels[i].y < 0) _pixels[i].y = Math.random()*_h
                //
                _canvas.setPixel(_pixels[i].x, _pixels[i].y, 0x8BBFC2)
            }
            _canvas.unlock()
            _glow.draw(_canvas, new Matrix(1/GLOW_SET_NUM, 0, 0, 1/GLOW_SET_NUM))
        }
    }    
}