tracerstar

Lorenz swarm animations

Added a swarm to follow the lorenz attractor

import hype.framework.rhythm.SimpleRhythm;
import hype.framework.core.TimeType;
import hype.framework.display.BitmapCanvas;
import hype.extended.rhythm.FilterCanvasRhythm;
import hype.extended.layout.LorenzAttractorLayout;
import hype.extended.behavior.Swarm;
import hype.framework.core.ObjectPool;
import hype.framework.behavior.BehaviorStore;
import hype.extended.color.ColorPool;

function resetSwarm(r:SimpleRhythm) {
	swarmPoint = layout.getNextPoint();
	pool.activeSet.forEach(changeSwarmGoal);
	colorClip.x = swarmPoint.x;
	colorClip.y = swarmPoint.y;
}

function changeSwarmGoal(clip) {
	var swarm:Swarm = BehaviorStore.retrieve(clip, "swarm") as Swarm;
	swarm.point = swarmPoint;
}

var myWidth = stage.stageWidth;
var myHeight = stage.stageHeight;

//bitmap and container
var bmc:BitmapCanvas = new BitmapCanvas(myWidth, myHeight);
addChild(bmc);
var clipContainer:Sprite = new Sprite();
clipContainer.visible = false;
addChild(clipContainer);

//our layout, swarm and object pools
var layout:LorenzAttractorLayout = new LorenzAttractorLayout('z');
var pool:ObjectPool = new ObjectPool(MyCircle, 5);
var swarmPoint:Point;

//color pool
var color:ColorPool = new ColorPool(0xFF3300, 0xFF6600, 0xFF6600, 0xFF9900);

//colorClip
var colorClip:MyCircle = new MyCircle();
colorClip.x = -100;
colorClip.y = -100;
//color.colorChildren(colorClip);
clipContainer.addChild(colorClip);


//what to do with an object from pool
pool.onRequestObject = function(clip) {
	clip.x = myWidth / 2;
	clip.y = myHeight / 2;
	clip.scaleX = clip.scaleY = (Math.random() * 1.0) + 0.5;
	clip.alpha = Math.random() * 0.05 + 0.05;
	
	color.colorChildren(clip);
	
	var swarm:Swarm = new Swarm(clip, layout.getNextPoint(), 5, 0.05, 5);
	swarm.start();
	swarm.store("swarm");
	clipContainer.addChild(clip);
}
pool.requestAll();

//capture and optional blur
bmc.startCapture(clipContainer, true);
//var blur:FilterCanvasRhythm = new FilterCanvasRhythm([new BlurFilter(1.5, 1.5, 1)], bmc);
//blur.start(TimeType.TIME, 200);

//start the rythm to update the swarm
var resetPoint:SimpleRhythm = new SimpleRhythm(resetSwarm);
resetPoint.start(TimeType.TIME, 50);

2 Responses to Lorenz swarm animations

Leave a Reply