Attractor
座標算出の数式は下記を参考
Peter de Jong Attractors:
http://local.wasp.uwa.edu.au/~pbourke/fractals/peterdejong/
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
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 const CX:int = 370;
private const CY:int = 410;
//増幅
private const RATE:Number = 200;
//パラメータ
private const A:Number = 1.01;
private const B:Number = 1.08;
private const C:Number = 2.01;
private const D:Number = -1.23;
//色
private const SC:uint = 0;
private const EC:uint = 60;
private const CR:Number = 0.0003;
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 = SC;
addEventListener(Event.ENTER_FRAME, _enterFrameHandler);
}
private function _enterFrameHandler(e:Event):void
{
var tx:Number,ty:Number;
_canvas.lock();
for(var i:int = 0;i<300;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(int(_nx*RATE + CX) , int(_ny*RATE +CY), _hsv.value);
_hsv.h += CR;
}
_canvas.unlock();
if(_hsv.h > EC) {
removeEventListener(Event.ENTER_FRAME, _enterFrameHandler);
}
}
}
}