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: Attractor

座標算出の数式は下記を参考
Peter de Jong Attractors:
http://local.wasp.uwa.edu.au/~pbourke/fractals/peterdejong/
Get Adobe Flash player
by seikai 08 Feb 2010
// forked from seikai's Attractor
package
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filters.BlurFilter;
	import flash.geom.Point;
	
	import frocessing.color.ColorHSV;
	
	/**
	 * 座標算出の数式は下記を参考
	 * Peter de Jong Attractors:
	 * http://local.wasp.uwa.edu.au/~pbourke/fractals/peterdejong/
	 */
	[SWF(width = 465, height = 465, frameRate = 50, backgroundColor=0)]
	public class Attractors extends Sprite
	{
		private var _nx:Number = 1,_ny:Number = 1;
		
		private var _canvas:BitmapData;
		private var _bm:Bitmap;
		
		private var _hsv:ColorHSV;
		
		private var _d:Number=0;
		
		//中心位置補正
		private const CX:int = 250;
		private const CY:int = 250;
		
		//増幅
		private const RATE:Number = 100;
		
		//パラメータ
		private const A:Number = 1.02;
		private const B:Number = 2.21;
		private const C:Number = 2.12;
		private const D:Number = -1.75;
		
		//色の変化量
		private const CR:Number = 0.5;
		
		private const ZERO_P:Point = new Point(0, 0);
		
		private const BLUR:BlurFilter = new BlurFilter(2,2,2);
		
		public function Attractors()
		{
			if(stage){
				_init();
			}else {
				addEventListener(Event.ADDED_TO_STAGE, _init);
			}
		}
		
		private function _init(e:Event = null):void{
			_canvas = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0x000000);
			addChild(_bm = new Bitmap(_canvas));
			_hsv = new ColorHSV();
			_hsv.h = 0;
			addEventListener(Event.ENTER_FRAME, _enterFrameHandler);
		}

		private function _enterFrameHandler(e:Event):void
		{
			var tx:Number,ty:Number;
			var b:Number = B + Math.cos(_d)/4;
			var d:Number = D + Math.sin(_d)/2;
			var color:uint = _hsv.value;
			_canvas.lock();
			for(var i:int = 0;i<2500;i++){
				tx = _nx;
				ty = _ny;
				_nx = Math.sin(A * ty) - Math.cos(b * tx);
				_ny = Math.sin(C * tx) - Math.cos(d * ty);
				_canvas.setPixel(_nx*RATE + CX , _ny*RATE +CY, color);
			}
			_canvas.unlock();
			_canvas.applyFilter(_canvas, _canvas.rect, ZERO_P, BLUR);
			_d += 0.01;
			_hsv.h += CR;
		}
	}
}