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

Clifford Attractor

Get Adobe Flash player
by ton 26 Dec 2008
    Embed
package 
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.events.Event;
    
    public class CliffordAttractor extends Sprite 
    {
        private const A:Number = 1.5;
        private const B:Number = -1.8;
        private const C:Number = 1.6;
        private const D:Number = 0.9;
        private const CENTER:Number = stage.stageWidth/2;
        private const SCALE:int = stage.stageWidth/6;
        private var dx:Number;
        private var dy:Number;
        private var _x:Number = 0;
        private var _y:Number = 0;
	
        private var bmd:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight);
	
        public function CliffordAttractor():void 
        {
            addChild( new Bitmap(bmd));
            addEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
        }
        
        private function onEnterFrameHandler(e:Event):void 
        {
            for (var i:int = 0; i < 100; i++){
                dx = Math.sin(A * _y) + C * Math.cos(A * _x);
                dy = Math.sin(B * _x) + D * Math.cos(B * _y);
                _x = dx;
                _y = dy;
                bmd.setPixel(CENTER + _x * SCALE, CENTER - _y * SCALE, 0x000000);
            }
        }	
    }
}