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

Graphing 2D Equations

Processing Example Graphing 2D Equations から AS3に移植
Get Adobe Flash player
by ton 26 Dec 2008
    Embed
//Processing Example Graphing 2D Equations から AS3に移植
package 
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.events.Event;
	
    [SWF(width=200, height=200)]
    public class Graphing2DEquations extends Sprite 
    {
    private const WIDTH:int = stage.stageWidth;
    private const HEIGHT:int = stage.stageHeight;
    private const W:int = 16;
    private const H:int = 16;
		
    private var bmd:BitmapData = new BitmapData(WIDTH, HEIGHT);
    public function Graphing2DEquations():void 
    {
        addChild(new Bitmap(bmd));
        addEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
    }

    private function onEnterFrameHandler(e:Event):void 
    {
        var n:Number = (mouseX * 10) / WIDTH;
        var dx:Number = W / WIDTH;
        var dy:Number = H / HEIGHT;
        var x:Number = -W / 2;
			
        bmd.lock();
        for (var i:int = 0; i < WIDTH; i++) {
            var y:Number = -H / 2;
            for (var j:int = 0; j < HEIGHT; j++) {
                var r:Number = Math.sqrt((x * x) + (y * y));
                var theta:Number = Math.atan2(y, x);
                var val:Number = Math.sin(n * Math.cos(r) + 5 * theta);
                var gray:uint = (val + 1) * 255.0 / 2.0;
                bmd.setPixel(i, j, gray<<16|gray<<8|gray);
                y += dy;
            }
            x += dx;
        }
        bmd.unlock();
    }
}
}