package { import org.cove.ape.*; import com.mrdoob.display.Blobalise; //import com.mrdoob.utils.Tracer; import flash.display.Sprite; import flash.display.BlendMode; import flash.events.Event; import flash.events.MouseEvent; [SWF( backgroundColor='0xFFFFFF', frameRate='30', width='600', height='600')] public class Main extends Sprite { private var circle :CircleParticle; private var square :RectangleParticle; private var addingParticles :Boolean = false; private var squareGroup :Group; private var squareComposite :Composite; private var circleGroup :Group; private var stageSize :Number = 600; private var container :Sprite; private var blobsRender :Blobalise; private var particleLimit :Number = 100; public function Main() { stage.quality = "LOW"; container = new Sprite(); addChild(container); APEngine.init(1/4); APEngine.container = container; APEngine.addMasslessForce(new Vector(0, 3)); circleGroup = new Group(); for (var i:Number = 0; i < 100; i++) { addParticle(Math.random()*stageSize,-Math.random()*100-50); } squareGroup = new Group(); for (var i:Number = 0; i < 10; i++) { square = new RectangleParticle(Math.random()*stageSize,Math.random()*stageSize,200,20,Math.random()*180,true,1,0,0); //square.alwaysRepaint = true; square.setStyle(0,0x000000,0,0xE0E0E0,1); square.sprite.cacheAsBitmap = true; squareGroup.addParticle(square); squareGroup.removeParticle } APEngine.addGroup(squareGroup); APEngine.addGroup(circleGroup); circleGroup.addCollidable(squareGroup); circleGroup.collideInternal = true; addEventListener(MouseEvent.MOUSE_DOWN, startAdding); addEventListener(MouseEvent.MOUSE_UP, stopAdding); addEventListener(Event.ENTER_FRAME, run); // Blobifying blobsRender = new Blobalise(container, stageSize, stageSize, true); blobsRender.blendMode = BlendMode.MULTIPLY addChild(blobsRender); } private function startAdding(e:Event):void { addingParticles = true; } private function stopAdding(e:Event):void { addingParticles = false; } private function addParticle(_x,_y):void { circle = new CircleParticle(_x,_y,Math.random()*10+2,false,1,0.1,0.0); circle.setStyle(0,0x000000,0,0x000000,1); circle.sprite.cacheAsBitmap = true; circleGroup.addParticle(circle); if (circleGroup.particles.length > particleLimit) circleGroup.removeParticle(circleGroup.particles[0]); } private function run(e:Event):void { if(addingParticles) addParticle(mouseX,mouseY); for (var j:String in circleGroup.particles) { if (circleGroup.particles[j].py > (stageSize + 50)) { circleGroup.particles[j].py = -Math.random()*100-50; circleGroup.particles[j].px = Math.random()*50+(stageSize*.5); //stage.stageWidth } } APEngine.step(); APEngine.paint(); } } }