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

にょろにょろした何か _30000 worms

パーティクルで何かやろうと適当に作ってたら、変なものができた。
Get Adobe Flash player
by shohei909 02 Oct 2010
/**
 * Copyright shohei909 ( http://wonderfl.net/user/shohei909 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/luQK
 */

//パーティクルで何かやろうと適当に作ってたら、変なものができた。

package {
    import flash.display.Sprite;
    import net.hires.debug.Stats;
    [SWF(backgroundColor=0x0, width=465, height=456, frameRate=30)]
    public class FlashTest extends Sprite {
        public function FlashTest() {
            addChild( new PixelMap(465,465) );
            addChild( new Stats() )
        }
    }
}
import flash.events.Event;
import flash.geom.Point;
import flash.display.BitmapData;
import flash.display.Bitmap;

class PixelMap extends Bitmap{
    private var black:BitmapData;
    private var size:int = 30000;
    private var pixels:Vector.<Pixel> = new Vector.<Pixel>();
    
    function PixelMap(width:int,height:int):void{
        black = new BitmapData(width,height,false,0x000000);
        super( new BitmapData(width,height,false,0x000000) );
        this.addEventListener("enterFrame",onFrame);
        for(var i:int=0;i<size;i++){
            new Pixel(pixels,width*Math.random(), height*Math.random(),0xD50000*Math.random());
        }
        pixels.fixed = true;
    }
    
    private function onFrame(e:Event):void{ drow(); move(); }
    private function drow():void{
        var b:BitmapData = bitmapData;
        b.lock();
        for each( var pixel:Pixel in pixels ){
            pixel.draw( b );
        }
        b.merge(black,b.rect,new Point(),10,10,8,255);
        b.unlock();
    }
    private function move():void{
        var mx:int = mouseX;
        var my:int = mouseY
        for each( var pixel:Pixel in pixels ){
            var deg:Number = Math.atan2(pixel.dx,pixel.dy);
            var x:Number = pixel.x-mx; var y:Number = pixel.y-my;
            var r:Number = Math.sqrt(x*x+y*y);
            deg = ( deg*15 + r ) /16
            pixel.dx = Math.sin(deg); pixel.dy = Math.cos(deg);
            pixel.move();
        }
    }
}



class Pixel{
    public var x:Number,y:Number,dx:Number = 0,dy:Number = 1;
    private var parent:Vector.<Pixel> = new Vector.<Pixel>();
    private var green:uint,blue:uint,red:uint,color:uint;
    
    public function Pixel(target:Vector.<Pixel>,x:int,y:int,color:uint){
        parent = target;
        parent.push( this );
        this.x = x; this.y = y;
        setColor(color);
    }
    public function draw( data:BitmapData ):void{ data.setPixel(x,y,color); }
    public function move():void{ x+=dx; y+=dy; }
    public function setColor( color:uint ):void{
        this.color = color;
        red = color >>> 16;
        green = (color - red) >>> 8
        blue = (color - red - green)
    }
}