STORY   LOOP   FURRY   PORN   GAMES
• C •   SERVICES [?] [R] RND   POPULAR
Archived flashes:
229455
/disc/ · /res/     /show/ · /fap/ · /gg/ · /swf/P0001 · P2574 · P5148

<div style="position:absolute;top:-99px;left:-99px;"><img src="http://swfchan.com:57475/86273344?noj=FRM86273344-5DC" width="1" height="1"></div>

Sketch-It.swf

This is the info page for
Flash #67281

(Click the ID number above for more basic data on this flash file.)


Text
Sketch it

*Draw shapes using your marker in order
to bring the red ball to the star.
*You can draw either rectangles, circles
or lines.
*Hold shift+click to delete a shape you've
drawn.
*Press R to reset a level

Sponsor.com

Developed by Pier-Jean Lizotte

Play

Play more games

Credits

Inspired by Petri Purho's Crayon Physics

Developed by Pier-Jean Lizotte

Music : 'Welcome to the future' by Khuskan

Back to menu

ActionScript [AS3]

Section 1
//DrawingsRenderer (classes.DrawingsRenderer) package classes { import flash.display.*; import org.generalrelativity.foam.dynamics.element.body.*; import flash.events.*; import org.generalrelativity.foam.util.*; import flash.geom.*; public class DrawingsRenderer extends Sprite { var DrawEnabled:Boolean;// = false var StartY:Number;// = 0 var Corner0X:Number; var Level; var StartX:Number;// = 0 var Corner0Y:Number; var StopY:Number;// = 0 var Corner1X:Number; var Canvas:MovieClip; var Corner1Y:Number; var StopX:Number;// = 0 var CornerCount:Number;// = 0 var Corner2X:Number; var Corner2Y:Number; public function DrawingsRenderer(_arg1, _arg2):void{ DrawEnabled = false; Canvas = new MovieClip(); CornerCount = 0; Corner0X = Corner1X; Corner0Y = Corner1Y; Corner1X = Corner2X; Corner1Y = Corner2Y; Corner2X = (mouseX - Canvas.x); Corner2Y = (mouseY - Canvas.y); StartX = 0; StartY = 0; StopX = 0; StopY = 0; super(); addEventListener(Event.ADDED, Init, false, 0, true); Level = _arg2; } private function Drawing(_arg1:MouseEvent):void{ var _local2:Number; var _local3:Number; var _local4:Number; var _local5:Number; var _local6:Number; var _local7:Number; var _local8:Number; var _local9:Number; var _local10:Number; var _local11:Number; var _local12:Number; var _local13:Number; var _local14:Number; var _local15:Number; var _local16:Number; var _local17:Number; var _local18:Number; Corner0X = Corner1X; Corner0Y = Corner1Y; Corner1X = Corner2X; Corner1Y = Corner2Y; Corner2X = (mouseX - Canvas.x); Corner2Y = (mouseY - Canvas.y); if (DrawEnabled){ _local2 = Corner2X; _local3 = Corner2Y; _local4 = Corner1X; _local5 = Corner1Y; _local6 = Corner0X; _local7 = Corner0Y; _local8 = (_local2 - _local4); _local9 = (_local3 - _local5); _local10 = Math.sqrt(((_local8 * _local8) + (_local9 * _local9))); _local11 = (_local4 - _local6); _local12 = (_local5 - _local7); _local13 = Math.sqrt(((_local11 * _local11) + (_local12 * _local12))); _local14 = (_local6 - _local2); _local15 = (_local7 - _local3); _local16 = Math.sqrt(((_local14 * _local14) + (_local15 * _local15))); _local17 = (-((((Math.sqrt(((_local14 * _local14) + (_local15 * _local15))) * _local16) - (_local13 * _local13)) - (_local10 * _local10))) / ((2 * _local13) * _local10)); _local18 = ((Math.acos(_local17) * 180) / 3.1416); if (!_local18){ _local18 = 180; }; if (_local18 < 160){ CornerCount++; }; Canvas.graphics.lineStyle(3, 0); Canvas.graphics.lineTo(Corner2X, Corner2Y); }; } private function Init(_arg1:Event):void{ stage.addEventListener(MouseEvent.MOUSE_MOVE, Drawing, false, 0, true); stage.addEventListener(MouseEvent.MOUSE_DOWN, StartDrawing, false, 0, true); stage.addEventListener(MouseEvent.MOUSE_UP, StopDrawing, false, 0, true); addChild(Canvas); } private function StartDrawing(_arg1:MouseEvent):void{ if (!_arg1.shiftKey){ StartX = mouseX; StartY = mouseY; Canvas.graphics.moveTo(mouseX, mouseY); DrawEnabled = true; }; } private function StopDrawing(_arg1:MouseEvent):void{ var _local2:int; var _local3:*; var _local4:Number; var _local5:Number; var _local6:Point; var _local7:Point; var _local8:Number; var _local9:Number; var _local10:RigidBody; var _local11:RigidBody; var _local12:Circle; _local2 = 0; StopX = mouseX; StopY = mouseY; _local3 = Canvas.getBounds(this); _local4 = (Canvas.width / 2); _local5 = (Canvas.height / 2); if ((((CornerCount > 0)) && ((((_local4 > 2)) || ((_local5 > 2)))))){ if (CornerCount <= 3){ _local2 = 0; } else { if ((((CornerCount > 3)) && ((CornerCount <= 9)))){ _local2 = 1; } else { _local2 = 2; }; }; CornerCount = 0; switch (_local2){ case 0: _local6 = new Point(StopX, StopY); _local7 = new Point(StartX, StartY); _local8 = Point.distance(_local6, _local7); _local9 = Math.atan2((StopY - StartY), (StopX - StartX)); _local10 = new RigidBody((_local3.x + _local4), (_local3.y + _local5), (_local8 / 2), ShapeUtil.createSymmetricPolygon(2, (_local8 / 2))); _local10.setRot(((_local9 * 180) / Math.PI)); _local10.tag = 2; Level.foam.addElement(_local10); break; case 1: _local11 = new RigidBody((_local3.x + _local4), (_local3.y + _local5), (_local4 + _local5), ShapeUtil.createRectangle((2 * _local4), (2 * _local5))); _local11.tag = 2; Level.foam.addElement(_local11); break; case 2: _local12 = new Circle((_local3.x + _local4), (_local3.y + _local5), ((_local4 + _local5) / 2)); _local12.tag = 2; Level.foam.addElement(_local12); break; }; }; Canvas.graphics.clear(); DrawEnabled = false; } } }//package classes
Section 2
//marker (classes.marker) package classes { import flash.display.*; public class marker extends Sprite { public function marker():void{ addChild(new markerMC()); } public function update():void{ x = stage.mouseX; y = stage.mouseY; rotation = (30 + (stage.mouseX / 10)); } } }//package classes
Section 3
//utils (classes.utils) package classes { import flash.display.*; import flash.events.*; import levels.*; import flash.geom.*; public class utils extends Sprite { public var NbLevel:Number; var Parent; public function utils(_arg1):void{ Parent = _arg1; NbLevel = Parent.nbLevel; } public function BitmapTransition():void{ var faded:Boolean; var bitmapdata:BitmapData; var bitmapdata2:BitmapData; var bitmap:*; var bitmap2:*; var bitmapMC:*; var bitmapMC2:*; var ef:Function; ef = function (_arg1:Event):void{ if (faded){ bitmapMC.alpha = (bitmapMC.alpha + 0.03); if (bitmapMC.alpha >= 1){ faded = false; stage.removeChild(bitmapMC2); }; } else { bitmapMC.alpha = (bitmapMC.alpha - 0.03); if (bitmapMC.alpha <= 0){ stage.removeChild(bitmapMC); bitmapMC.removeEventListener(Event.ENTER_FRAME, ef); }; }; }; faded = true; bitmapdata = new BitmapData(640, 480, false, 0); bitmapdata2 = new BitmapData(640, 480, false); bitmapdata2.draw(stage, new Matrix()); bitmap = new Bitmap(bitmapdata); bitmap2 = new Bitmap(bitmapdata2); bitmapMC = new MovieClip(); bitmapMC2 = new MovieClip(); bitmapMC2.addChild(bitmap2); bitmapMC.addChild(bitmap); stage.addChild(bitmapMC2); stage.addChild(bitmapMC); bitmapMC.alpha = 0; bitmapMC.addEventListener(Event.ENTER_FRAME, ef); } public function render():void{ var _local1:Boolean; var _local2:marker; var _local3:Sprite; var _local4:*; var _local5:DrawingsRenderer; var _local6:paperBG; BitmapTransition(); while (numChildren) { removeChildAt(0); }; _local1 = true; _local2 = new marker(); switch (NbLevel){ case 1: _local4 = new Level1(_local2, this); _local3 = new Level1MC(); break; case 2: _local4 = new Level2(_local2, this); _local3 = new Level2MC(); break; case 3: _local4 = new Level3(_local2, this); _local3 = new Level3MC(); break; case 4: _local4 = new Level4(_local2, this); _local3 = new Level4MC(); break; case 5: _local4 = new Level5(_local2, this); _local3 = new Level5MC(); break; case 6: _local4 = new Level6(_local2, this); _local3 = new Level6MC(); break; case 7: _local4 = new Level7(_local2, this); break; case 8: _local4 = new Level8(_local2, this); _local3 = new Level8MC(); break; case 9: _local4 = new Level9(_local2, this); _local3 = new Level9MC(); break; case 10: _local4 = new Level10(_local2, this); _local3 = new Level10MC(); break; default: Parent.gotoAndStop("CREDITS"); _local1 = false; break; }; if (_local1){ _local5 = new DrawingsRenderer(this, _local4); _local6 = new paperBG(); addChild(_local6); if (NbLevel != 7){ addChild(_local3); }; addChild(_local4); addChild(_local5); addChild(_local2); }; } } }//package classes
Section 4
//Level1 (levels.Level1) package levels { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.force.*; import flash.display.*; import org.generalrelativity.foam.dynamics.element.*; import org.generalrelativity.foam.view.*; import org.generalrelativity.foam.dynamics.element.body.*; import flash.events.*; import org.generalrelativity.foam.util.*; import org.generalrelativity.foam.dynamics.enum.*; import org.generalrelativity.foam.*; public class Level1 extends Sprite { const startX:Number = 520; const startY:Number = 100; const RENDER:Boolean = false; const FALL_LIMIT:int = 1000; const endX:Number = 100; const endY:Number = 380; var Marker; var ObjCircle:Circle; public var foam:Foam; var Parent; public function Level1(_arg1, _arg2){ var _local3:Circle; var _local4:RigidBody; var _local5:RigidBody; var _local6:RigidBody; ObjCircle = new Circle(startX, startY, 25); super(); Marker = _arg1; Parent = _arg2; foam = (addChild(new Foam()) as Foam); foam.useMouseDragger(true); foam.setRenderer(new DisplayObjectFoamRenderer()); foam.solverIterations = 2; foam.addGlobalForceGenerator(new Gravity(new Vector(0, 1.3))); foam.addGlobalForceGenerator(new Friction(0.02)); ObjCircle.tag = 1; foam.addElement(ObjCircle, true, true, new DisplayObjectData(ball, 1, 1)); _local3 = new Circle(endX, endY, 25, Simplification.INFINITE_MASS); _local3.tag = 1; foam.addElement(_local3, false, true, new DisplayObjectData(star, 0, 0)); _local4 = new RigidBody(0, 300, Simplification.INFINITE_MASS, ShapeUtil.createRectangle(20, 480)); foam.addElement(_local4, true, RENDER); _local4 = new RigidBody(640, 300, Simplification.INFINITE_MASS, ShapeUtil.createRectangle(20, 480)); foam.addElement(_local4, true, RENDER); _local5 = new RigidBody(310, 330, Simplification.INFINITE_MASS, ShapeUtil.createRectangle(350, 30)); _local5.setRot(-30); foam.addElement(_local5, true, RENDER); _local6 = new RigidBody(555, 243, Simplification.INFINITE_MASS, ShapeUtil.createRectangle(200, 30)); _local6.setRot(-0.2); foam.addElement(_local6, true, RENDER); _local6 = new RigidBody(20, 410, Simplification.INFINITE_MASS, ShapeUtil.createRectangle(300, 30)); _local6.setRot(-0.2); foam.addElement(_local6, true, RENDER); foam.addEventListener(Foam.STEP, onFoamStep, false, 0, true); foam.simulate(); addEventListener(Event.ADDED, init, false, 0, true); } private function init(_arg1:Event):void{ stage.addEventListener(KeyboardEvent.KEY_DOWN, reset, false, 0, true); removeEventListener(Event.REMOVED, init); } private function onFoamStep(_arg1:Event):void{ var _local2:Number; var _local3:Number; var _local4:ISimulatable; Marker.update(); _local2 = (ObjCircle.x - (endX - 25)); _local3 = (ObjCircle.y - (endY - 25)); if (Math.sqrt(((_local2 * _local2) + (_local3 * _local3))) < 45){ foam.stop(); Parent.NbLevel++; Parent.render(); }; for each (_local4 in foam.simulatables) { if (_local4.y > FALL_LIMIT){ if (_local4.tag == 1){ _local4.vy = 0; _local4.vx = 0; _local4.x = startX; _local4.y = startY; } else { foam.removeElement(_local4); }; }; }; } private function reset(_arg1:KeyboardEvent):void{ var _local2:ISimulatable; if (_arg1.keyCode == 82){ for each (_local2 in foam.simulatables) { if (_local2.tag == 1){ _local2.vy = 0; _local2.vx = 0; _local2.x = startX; _local2.y = startY; } else { foam.removeElement(_local2); }; }; }; } } }//package levels
Section 5
//Level10 (levels.Level10) package levels { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.force.*; import flash.display.*; import org.generalrelativity.foam.dynamics.element.*; import org.generalrelativity.foam.view.*; import org.generalrelativity.foam.dynamics.element.body.*; import flash.events.*; import org.generalrelativity.foam.util.*; import org.generalrelativity.foam.dynamics.enum.*; import org.generalrelativity.foam.*; public class Level10 extends Sprite { const startX:Number = 150; const startY:Number = 250; const RENDER:Boolean = true; const FALL_LIMIT:int = 1000; const endX:Number = 300; const endY:Number = 300; var Marker; var ObjCircle:Circle; public var foam:Foam; var Parent; public function Level10(_arg1, _arg2){ var _local3:Circle; var _local4:RigidBody; ObjCircle = new Circle(startX, startY, 25); super(); Marker = _arg1; Parent = _arg2; foam = (addChild(new Foam()) as Foam); foam.useMouseDragger(true); foam.setRenderer(new DisplayObjectFoamRenderer()); foam.solverIterations = 2; foam.addGlobalForceGenerator(new Gravity(new Vector(0, 1.3))); foam.addGlobalForceGenerator(new Friction(0.02)); ObjCircle.tag = 1; foam.addElement(ObjCircle, true, true, new DisplayObjectData(ball, 1, 1)); _local3 = new Circle(endX, endY, 25, Simplification.INFINITE_MASS); _local3.tag = 1; foam.addElement(_local3, false, true, new DisplayObjectData(star, 0, 0)); _local4 = new RigidBody(320, 400, Simplification.INFINITE_MASS, ShapeUtil.createRectangle(600, 30)); foam.addElement(_local4, true, RENDER); foam.addEventListener(Foam.STEP, onFoamStep, false, 0, true); foam.simulate(); addEventListener(Event.ADDED, init, false, 0, true); } private function init(_arg1:Event):void{ stage.addEventListener(KeyboardEvent.KEY_DOWN, reset, false, 0, true); removeEventListener(Event.REMOVED, init); } private function onFoamStep(_arg1:Event):void{ var _local2:Number; var _local3:Number; var _local4:ISimulatable; Marker.update(); _local2 = (ObjCircle.x - (endX - 25)); _local3 = (ObjCircle.y - (endY - 25)); if (Math.sqrt(((_local2 * _local2) + (_local3 * _local3))) < 45){ foam.stop(); Parent.NbLevel++; Parent.render(); }; for each (_local4 in foam.simulatables) { if (_local4.y > FALL_LIMIT){ if (_local4.tag == 1){ _local4.vy = 0; _local4.vx = 0; _local4.x = startX; _local4.y = startY; } else { foam.removeElement(_local4); }; }; }; } private function reset(_arg1:KeyboardEvent):void{ var _local2:ISimulatable; if (_arg1.keyCode == 82){ for each (_local2 in foam.simulatables) { if (_local2.tag == 1){ _local2.vy = 0; _local2.vx = 0; _local2.x = startX; _local2.y = startY; } else { foam.removeElement(_local2); }; }; }; } } }//package levels
Section 6
//Level2 (levels.Level2) package levels { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.force.*; import flash.display.*; import org.generalrelativity.foam.dynamics.element.*; import org.generalrelativity.foam.view.*; import org.generalrelativity.foam.dynamics.element.body.*; import flash.events.*; import org.generalrelativity.foam.util.*; import org.generalrelativity.foam.dynamics.enum.*; import org.generalrelativity.foam.*; public class Level2 extends Sprite { const startX:Number = 350; const startY:Number = 150; const RENDER:Boolean = false; const FALL_LIMIT:int = 1000; const endX:Number = 600; const endY:Number = 420; var Marker; var ObjCircle:Circle; public var foam:Foam; var Parent; public function Level2(_arg1, _arg2){ var _local3:Circle; var _local4:RigidBody; var _local5:RigidBody; var _local6:RigidBody; ObjCircle = new Circle(startX, startY, 25); super(); Marker = _arg1; Parent = _arg2; foam = (addChild(new Foam()) as Foam); foam.useMouseDragger(true); foam.setRenderer(new DisplayObjectFoamRenderer()); foam.solverIterations = 2; foam.addGlobalForceGenerator(new Gravity(new Vector(0, 1.3))); foam.addGlobalForceGenerator(new Friction(0.02)); ObjCircle.tag = 1; foam.addElement(ObjCircle, true, true, new DisplayObjectData(ball, 1, 1)); _local3 = new Circle(endX, endY, 25, Simplification.INFINITE_MASS); _local3.tag = 1; foam.addElement(_local3, false, true, new DisplayObjectData(star, 0, 0)); _local4 = new RigidBody(0, 240, Simplification.INFINITE_MASS, ShapeUtil.createRectangle(20, 480)); foam.addElement(_local4, true, RENDER); _local4 = new RigidBody(640, 240, Simplification.INFINITE_MASS, ShapeUtil.createRectangle(20, 480)); foam.addElement(_local4, true, RENDER); _local5 = new RigidBody(100, 350, Simplification.INFINITE_MASS, ShapeUtil.createRectangle(300, 30)); _local5.setRot(45); foam.addElement(_local5, true, RENDER); _local6 = new RigidBody(400, 438, Simplification.INFINITE_MASS, ShapeUtil.createRectangle(500, 30)); _local6.setRot(0.2); foam.addElement(_local6, true, RENDER); foam.addEventListener(Foam.STEP, onFoamStep, false, 0, true); foam.simulate(); addEventListener(Event.ADDED, init, false, 0, true); } private function init(_arg1:Event):void{ stage.addEventListener(KeyboardEvent.KEY_DOWN, reset, false, 0, true); removeEventListener(Event.REMOVED, init); } private function onFoamStep(_arg1:Event):void{ var _local2:Number; var _local3:Number; var _local4:ISimulatable; Marker.update(); _local2 = (ObjCircle.x - (endX - 25)); _local3 = (ObjCircle.y - (endY - 25)); if (Math.sqrt(((_local2 * _local2) + (_local3 * _local3))) < 45){ foam.stop(); Parent.NbLevel++; Parent.render(); }; for each (_local4 in foam.simulatables) { if (_local4.y > FALL_LIMIT){ if (_local4.tag == 1){ _local4.vy = 0; _local4.vx = 0; _local4.x = startX; _local4.y = startY; } else { foam.removeElement(_local4); }; }; }; } private function reset(_arg1:KeyboardEvent):void{ var _local2:ISimulatable; if (_arg1.keyCode == 82){ for each (_local2 in foam.simulatables) { if (_local2.tag == 1){ _local2.vy = 0; _local2.vx = 0; _local2.x = startX; _local2.y = startY; } else { foam.removeElement(_local2); }; }; }; } } }//package levels
Section 7
//Level3 (levels.Level3) package levels { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.force.*; import flash.display.*; import org.generalrelativity.foam.dynamics.element.*; import org.generalrelativity.foam.view.*; import org.generalrelativity.foam.dynamics.element.body.*; import flash.events.*; import org.generalrelativity.foam.util.*; import org.generalrelativity.foam.dynamics.enum.*; import org.generalrelativity.foam.*; public class Level3 extends Sprite { const startX:Number = 120; const startY:Number = 100; const RENDER:Boolean = false; const FALL_LIMIT:int = 1000; const endX:Number = 600; const endY:Number = 380; var Marker; var ObjCircle:Circle; public var foam:Foam; var Parent; public function Level3(_arg1, _arg2){ var _local3:Circle; var _local4:RigidBody; ObjCircle = new Circle(startX, startY, 25); super(); Marker = _arg1; Parent = _arg2; foam = (addChild(new Foam()) as Foam); foam.useMouseDragger(true); foam.setRenderer(new DisplayObjectFoamRenderer()); foam.solverIterations = 2; foam.addGlobalForceGenerator(new Gravity(new Vector(0, 1.3))); foam.addGlobalForceGenerator(new Friction(0.02)); ObjCircle.tag = 1; foam.addElement(ObjCircle, true, true, new DisplayObjectData(ball, 1, 1)); _local3 = new Circle(endX, endY, 25, Simplification.INFINITE_MASS); _local3.tag = 1; foam.addElement(_local3, false, true, new DisplayObjectData(star, 0, 0)); _local4 = new RigidBody(120, 400, Simplification.INFINITE_MASS, ShapeUtil.createRectangle(200, 30)); foam.addElement(_local4, true, RENDER); _local4 = new RigidBody(320, 430, Simplification.INFINITE_MASS, ShapeUtil.createRectangle(200, 30)); foam.addElement(_local4, true, RENDER); _local4 = new RigidBody(520, 400, Simplification.INFINITE_MASS, ShapeUtil.createRectangle(200, 30)); foam.addElement(_local4, true, RENDER); foam.addEventListener(Foam.STEP, onFoamStep, false, 0, true); foam.simulate(); addEventListener(Event.ADDED, init, false, 0, true); } private function init(_arg1:Event):void{ stage.addEventListener(KeyboardEvent.KEY_DOWN, reset, false, 0, true); removeEventListener(Event.REMOVED, init); } private function onFoamStep(_arg1:Event):void{ var _local2:Number; var _local3:Number; var _local4:ISimulatable; Marker.update(); _local2 = (ObjCircle.x - (endX - 25)); _local3 = (ObjCircle.y - (endY - 25)); if (Math.sqrt(((_local2 * _local2) + (_local3 * _local3))) < 45){ foam.stop(); Parent.NbLevel++; Parent.render(); }; for each (_local4 in foam.simulatables) { if (_local4.y > FALL_LIMIT){ if (_local4.tag == 1){ _local4.vy = 0; _local4.vx = 0; _local4.x = startX; _local4.y = startY; } else { foam.removeElement(_local4); }; }; }; } private function reset(_arg1:KeyboardEvent):void{ var _local2:ISimulatable; if (_arg1.keyCode == 82){ for each (_local2 in foam.simulatables) { if (_local2.tag == 1){ _local2.vy = 0; _local2.vx = 0; _local2.x = startX; _local2.y = startY; } else { foam.removeElement(_local2); }; }; }; } } }//package levels
Section 8
//Level4 (levels.Level4) package levels { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.force.*; import flash.display.*; import org.generalrelativity.foam.dynamics.element.*; import org.generalrelativity.foam.view.*; import org.generalrelativity.foam.dynamics.element.body.*; import org.generalrelativity.foam.dynamics.force.spring.*; import flash.events.*; import org.generalrelativity.foam.util.*; import org.generalrelativity.foam.dynamics.enum.*; import org.generalrelativity.foam.*; public class Level4 extends Sprite { const startX:Number = 480; const startY:Number = 70; const RENDER:Boolean = false; const FALL_LIMIT:int = 1000; const endX:Number = 500; const endY:Number = 400; var Marker; var ObjCircle:Circle; public var foam:Foam; var Parent; public function Level4(_arg1, _arg2){ var _local3:RigidBody; var _local4:RigidBody; var _local5:RigidBody; var _local6:RigidBody; var _local7:RigidBodyBungee; var _local8:Circle; ObjCircle = new Circle(startX, startY, 25); super(); Marker = _arg1; Parent = _arg2; foam = (addChild(new Foam()) as Foam); foam.useMouseDragger(true); foam.setRenderer(new DisplayObjectFoamRenderer()); foam.solverIterations = 2; foam.addGlobalForceGenerator(new Gravity(new Vector(0, 1.3))); foam.addGlobalForceGenerator(new Friction(0.02)); _local3 = new RigidBody(230, 380, Simplification.INFINITE_MASS, ShapeUtil.createRectangle(400, 30)); _local3.setRot(25); foam.addElement(_local3, true, RENDER); _local3 = new RigidBody(600, 665, Simplification.INFINITE_MASS, ShapeUtil.createRectangle(200, 30)); _local3.setRot(320); foam.addElement(_local3, true, RENDER); _local4 = new RigidBody(400, 50, Simplification.INFINITE_MASS, ShapeUtil.createSymmetricPolygon(3, 30)); _local5 = new RigidBody(600, 50, Simplification.INFINITE_MASS, ShapeUtil.createSymmetricPolygon(3, 30)); foam.addElement(_local4, false, false); foam.addElement(_local5, false, false); _local6 = new RigidBody(500, 100, 900, ShapeUtil.createRectangle(200, 30)); foam.addElement(_local6, true, true, new DisplayObjectData(Rectangle1, 0, 5)); _local7 = new RigidBodyBungee(_local6, new Vector(-95, 0), _local4, new Vector(0, 1), 0.05); foam.addRenderable(new Renderable(_local7)); _local7 = new RigidBodyBungee(_local6, new Vector(95, 0), _local5, new Vector(0, 1), 0.05); foam.addRenderable(new Renderable(_local7)); ObjCircle.tag = 1; foam.addElement(ObjCircle, true, true, new DisplayObjectData(ball, 1, 1)); _local8 = new Circle(endX, endY, 25, Simplification.INFINITE_MASS); _local8.tag = 1; foam.addElement(_local8, false, true, new DisplayObjectData(star, 0, 0)); foam.addEventListener(Foam.STEP, onFoamStep, false, 0, true); foam.simulate(); addEventListener(Event.ADDED, init, false, 0, true); } private function init(_arg1:Event):void{ stage.addEventListener(KeyboardEvent.KEY_DOWN, reset, false, 0, true); removeEventListener(Event.REMOVED, init); } private function onFoamStep(_arg1:Event):void{ var _local2:Number; var _local3:Number; var _local4:ISimulatable; Marker.update(); _local2 = (ObjCircle.x - (endX - 25)); _local3 = (ObjCircle.y - (endY - 25)); if (Math.sqrt(((_local2 * _local2) + (_local3 * _local3))) < 45){ foam.stop(); Parent.NbLevel++; Parent.render(); }; for each (_local4 in foam.simulatables) { if (_local4.y > FALL_LIMIT){ if (_local4.tag == 1){ _local4.vy = 0; _local4.vx = 0; _local4.x = startX; _local4.y = startY; } else { foam.removeElement(_local4); }; }; }; } private function reset(_arg1:KeyboardEvent):void{ var _local2:ISimulatable; if (_arg1.keyCode == 82){ for each (_local2 in foam.simulatables) { if (_local2.tag == 1){ _local2.vy = 0; _local2.vx = 0; _local2.x = startX; _local2.y = startY; } else { foam.removeElement(_local2); }; }; }; } } }//package levels
Section 9
//Level5 (levels.Level5) package levels { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.force.*; import flash.display.*; import org.generalrelativity.foam.dynamics.element.*; import org.generalrelativity.foam.view.*; import org.generalrelativity.foam.dynamics.element.body.*; import flash.events.*; import org.generalrelativity.foam.util.*; import org.generalrelativity.foam.dynamics.enum.*; import org.generalrelativity.foam.*; public class Level5 extends Sprite { const startX:Number = 120; const startY:Number = 200; const RENDER:Boolean = false; const FALL_LIMIT:int = 1000; const endX:Number = 600; const endY:Number = 380; var Marker; var ObjCircle:Circle; public var foam:Foam; var Parent; public function Level5(_arg1, _arg2){ var _local3:Circle; var _local4:RigidBody; ObjCircle = new Circle(startX, startY, 25); super(); Marker = _arg1; Parent = _arg2; foam = (addChild(new Foam()) as Foam); foam.useMouseDragger(true); foam.setRenderer(new DisplayObjectFoamRenderer()); foam.solverIterations = 2; foam.addGlobalForceGenerator(new Gravity(new Vector(0, 1.3))); foam.addGlobalForceGenerator(new Friction(0.02)); ObjCircle.tag = 1; foam.addElement(ObjCircle, true, true, new DisplayObjectData(ball, 1, 1)); _local3 = new Circle(endX, endY, 25, Simplification.INFINITE_MASS); _local3.tag = 1; foam.addElement(_local3, false, true, new DisplayObjectData(star, 0, 0)); _local4 = new RigidBody(120, 390, Simplification.INFINITE_MASS, ShapeUtil.createRectangle(200, 30)); foam.addElement(_local4, true, RENDER); _local4 = new RigidBody(520, 420, Simplification.INFINITE_MASS, ShapeUtil.createRectangle(200, 30)); foam.addElement(_local4, true, RENDER); foam.addEventListener(Foam.STEP, onFoamStep, false, 0, true); foam.simulate(); addEventListener(Event.ADDED, init, false, 0, true); } private function init(_arg1:Event):void{ stage.addEventListener(KeyboardEvent.KEY_DOWN, reset, false, 0, true); removeEventListener(Event.REMOVED, init); } private function onFoamStep(_arg1:Event):void{ var _local2:Number; var _local3:Number; var _local4:ISimulatable; Marker.update(); _local2 = (ObjCircle.x - (endX - 25)); _local3 = (ObjCircle.y - (endY - 25)); if (Math.sqrt(((_local2 * _local2) + (_local3 * _local3))) < 45){ foam.stop(); Parent.NbLevel++; Parent.render(); }; for each (_local4 in foam.simulatables) { if (_local4.y > FALL_LIMIT){ if (_local4.tag == 1){ _local4.vy = 0; _local4.vx = 0; _local4.x = startX; _local4.y = startY; } else { foam.removeElement(_local4); }; }; }; } private function reset(_arg1:KeyboardEvent):void{ var _local2:ISimulatable; if (_arg1.keyCode == 82){ for each (_local2 in foam.simulatables) { if (_local2.tag == 1){ _local2.vy = 0; _local2.vx = 0; _local2.x = startX; _local2.y = startY; } else { foam.removeElement(_local2); }; }; }; } } }//package levels
Section 10
//Level6 (levels.Level6) package levels { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.force.*; import flash.display.*; import org.generalrelativity.foam.dynamics.element.*; import org.generalrelativity.foam.view.*; import org.generalrelativity.foam.dynamics.element.body.*; import flash.events.*; import org.generalrelativity.foam.util.*; import org.generalrelativity.foam.dynamics.enum.*; import org.generalrelativity.foam.*; public class Level6 extends Sprite { const startX:Number = 120; const startY:Number = 100; const RENDER:Boolean = false; const FALL_LIMIT:int = 1000; const endX:Number = 600; const endY:Number = 380; var Marker; var ObjCircle:Circle; public var foam:Foam; var Parent; public function Level6(_arg1, _arg2){ var _local3:Circle; var _local4:RigidBody; var _local5:RigidBody; ObjCircle = new Circle(startX, startY, 25); super(); Marker = _arg1; Parent = _arg2; foam = (addChild(new Foam()) as Foam); foam.useMouseDragger(true); foam.setRenderer(new DisplayObjectFoamRenderer()); foam.solverIterations = 2; foam.addGlobalForceGenerator(new Gravity(new Vector(0, 1.3))); foam.addGlobalForceGenerator(new Friction(0.02)); ObjCircle.tag = 1; foam.addElement(ObjCircle, true, true, new DisplayObjectData(ball, 1, 1)); _local3 = new Circle(endX, endY, 25, Simplification.INFINITE_MASS); _local3.tag = 1; foam.addElement(_local3, false, true, new DisplayObjectData(star, 0, 0)); _local4 = new RigidBody(320, 400, Simplification.INFINITE_MASS, ShapeUtil.createRectangle(600, 30)); foam.addElement(_local4, true, RENDER); _local5 = new RigidBody(320, 290, 100, ShapeUtil.createRectangle(30, 200)); foam.addElement(_local5, true, true, new DisplayObjectData(Rectangle2, 3)); foam.addEventListener(Foam.STEP, onFoamStep, false, 0, true); foam.simulate(); addEventListener(Event.ADDED, init, false, 0, true); } private function init(_arg1:Event):void{ stage.addEventListener(KeyboardEvent.KEY_DOWN, reset, false, 0, true); removeEventListener(Event.REMOVED, init); } private function onFoamStep(_arg1:Event):void{ var _local2:Number; var _local3:Number; var _local4:ISimulatable; Marker.update(); _local2 = (ObjCircle.x - (endX - 25)); _local3 = (ObjCircle.y - (endY - 25)); if (Math.sqrt(((_local2 * _local2) + (_local3 * _local3))) < 45){ foam.stop(); Parent.NbLevel++; Parent.render(); }; for each (_local4 in foam.simulatables) { if (_local4.y > FALL_LIMIT){ if (_local4.tag == 1){ _local4.vy = 0; _local4.vx = 0; _local4.x = startX; _local4.y = startY; } else { foam.removeElement(_local4); }; }; }; } private function reset(_arg1:KeyboardEvent):void{ var _local2:ISimulatable; var _local3:RigidBody; if (_arg1.keyCode == 82){ for each (_local2 in foam.simulatables) { if (_local2.tag == 1){ _local2.vy = 0; _local2.vx = 0; _local2.x = startX; _local2.y = startY; } else { foam.removeElement(_local2); }; }; _local3 = new RigidBody(320, 290, 100, ShapeUtil.createRectangle(30, 200)); foam.addElement(_local3, true, RENDER); }; } } }//package levels
Section 11
//Level7 (levels.Level7) package levels { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.force.*; import flash.display.*; import org.generalrelativity.foam.dynamics.element.*; import org.generalrelativity.foam.view.*; import org.generalrelativity.foam.dynamics.element.body.*; import org.generalrelativity.foam.dynamics.force.spring.*; import flash.events.*; import org.generalrelativity.foam.util.*; import org.generalrelativity.foam.dynamics.enum.*; import org.generalrelativity.foam.*; public class Level7 extends Sprite { const startX:Number = 480; const startY:Number = 70; const RENDER:Boolean = true; const FALL_LIMIT:int = 1000; const endX:Number = 150; const endY:Number = 250; var Marker; var ObjCircle:Circle; public var foam:Foam; var Parent; public function Level7(_arg1, _arg2){ var _local3:RigidBody; var _local4:RigidBody; var _local5:RigidBody; var _local6:RigidBodyBungee; var _local7:Circle; ObjCircle = new Circle(startX, startY, 25); super(); Marker = _arg1; Parent = _arg2; foam = (addChild(new Foam()) as Foam); foam.useMouseDragger(true); foam.setRenderer(new DisplayObjectFoamRenderer()); foam.solverIterations = 2; foam.addGlobalForceGenerator(new Gravity(new Vector(0, 1.3))); foam.addGlobalForceGenerator(new Friction(0.02)); _local3 = new RigidBody(400, 150, Simplification.INFINITE_MASS, ShapeUtil.createSymmetricPolygon(3, 30)); _local4 = new RigidBody(600, 150, Simplification.INFINITE_MASS, ShapeUtil.createSymmetricPolygon(3, 30)); foam.addElement(_local3, false, false); foam.addElement(_local4, false, false); _local5 = new RigidBody(500, 200, 900, ShapeUtil.createRectangle(200, 30)); foam.addElement(_local5, true, true, new DisplayObjectData(Rectangle3, 0, 5)); _local6 = new RigidBodyBungee(_local5, new Vector(-95, 0), _local3, new Vector(0, 1), 0.05); foam.addRenderable(new Renderable(_local6)); _local6 = new RigidBodyBungee(_local5, new Vector(95, 0), _local4, new Vector(0, 1), 0.05); foam.addRenderable(new Renderable(_local6)); _local3 = new RigidBody(40, 150, Simplification.INFINITE_MASS, ShapeUtil.createSymmetricPolygon(3, 30)); _local4 = new RigidBody(240, 150, Simplification.INFINITE_MASS, ShapeUtil.createSymmetricPolygon(3, 30)); foam.addElement(_local3, false, false); foam.addElement(_local4, false, false); _local5 = new RigidBody(140, 200, 900, ShapeUtil.createRectangle(200, 30)); foam.addElement(_local5, true, true, new DisplayObjectData(Rectangle4, 0, 5)); _local6 = new RigidBodyBungee(_local5, new Vector(-95, 0), _local3, new Vector(0, 1), 0.05); foam.addRenderable(new Renderable(_local6)); _local6 = new RigidBodyBungee(_local5, new Vector(95, 0), _local4, new Vector(0, 1), 0.05); foam.addRenderable(new Renderable(_local6)); ObjCircle.tag = 1; foam.addElement(ObjCircle, true, true, new DisplayObjectData(ball, 1, 1)); _local7 = new Circle(endX, endY, 25, Simplification.INFINITE_MASS); _local7.tag = 1; foam.addElement(_local7, false, true, new DisplayObjectData(star, 0, 0)); foam.addEventListener(Foam.STEP, onFoamStep, false, 0, true); foam.simulate(); addEventListener(Event.ADDED, init, false, 0, true); } private function init(_arg1:Event):void{ stage.addEventListener(KeyboardEvent.KEY_DOWN, reset, false, 0, true); removeEventListener(Event.REMOVED, init); } private function onFoamStep(_arg1:Event):void{ var _local2:Number; var _local3:Number; var _local4:ISimulatable; Marker.update(); _local2 = (ObjCircle.x - (endX - 25)); _local3 = (ObjCircle.y - (endY - 25)); if (Math.sqrt(((_local2 * _local2) + (_local3 * _local3))) < 45){ foam.stop(); Parent.NbLevel++; Parent.render(); }; for each (_local4 in foam.simulatables) { if (_local4.y > FALL_LIMIT){ if (_local4.tag == 1){ _local4.vy = 0; _local4.vx = 0; _local4.x = startX; _local4.y = startY; } else { foam.removeElement(_local4); }; }; }; } private function reset(_arg1:KeyboardEvent):void{ var _local2:ISimulatable; if (_arg1.keyCode == 82){ for each (_local2 in foam.simulatables) { if (_local2.tag == 1){ _local2.vy = 0; _local2.vx = 0; _local2.x = startX; _local2.y = startY; } else { foam.removeElement(_local2); }; }; }; } } }//package levels
Section 12
//Level8 (levels.Level8) package levels { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.force.*; import flash.display.*; import org.generalrelativity.foam.dynamics.element.*; import org.generalrelativity.foam.view.*; import org.generalrelativity.foam.dynamics.element.body.*; import flash.events.*; import org.generalrelativity.foam.util.*; import org.generalrelativity.foam.dynamics.enum.*; import org.generalrelativity.foam.*; public class Level8 extends Sprite { const startX:Number = 185; const startY:Number = 60; const RENDER:Boolean = false; const FALL_LIMIT:int = 1000; const endX:Number = 120; const endY:Number = 350; var Marker; var ObjCircle:Circle; public var foam:Foam; var Parent; public function Level8(_arg1, _arg2){ var _local3:Circle; var _local4:RigidBody; ObjCircle = new Circle(startX, startY, 25); super(); Marker = _arg1; Parent = _arg2; foam = (addChild(new Foam()) as Foam); foam.useMouseDragger(true); foam.setRenderer(new DisplayObjectFoamRenderer()); foam.solverIterations = 2; foam.addGlobalForceGenerator(new Gravity(new Vector(0, 1.3))); foam.addGlobalForceGenerator(new Friction(0.02)); ObjCircle.tag = 1; foam.addElement(ObjCircle, true, true, new DisplayObjectData(ball, 1, 1)); _local3 = new Circle(endX, endY, 25, Simplification.INFINITE_MASS); _local3.tag = 1; foam.addElement(_local3, false, true, new DisplayObjectData(star, 0, 0)); _local4 = new RigidBody(320, 150, Simplification.INFINITE_MASS, ShapeUtil.createRectangle(320, 20)); _local4.setRot(12); foam.addElement(_local4, true, RENDER); _local4 = new RigidBody(400, 350, Simplification.INFINITE_MASS, ShapeUtil.createRectangle(320, 20)); _local4.setRot(330); foam.addElement(_local4, true, RENDER); _local4 = new RigidBody(155, 430, Simplification.INFINITE_MASS, ShapeUtil.createRectangle(260, 20)); foam.addElement(_local4, true, RENDER); foam.addEventListener(Foam.STEP, onFoamStep, false, 0, true); foam.simulate(); addEventListener(Event.ADDED, init, false, 0, true); } private function init(_arg1:Event):void{ stage.addEventListener(KeyboardEvent.KEY_DOWN, reset, false, 0, true); removeEventListener(Event.REMOVED, init); } private function onFoamStep(_arg1:Event):void{ var _local2:Number; var _local3:Number; var _local4:ISimulatable; Marker.update(); _local2 = (ObjCircle.x - (endX - 25)); _local3 = (ObjCircle.y - (endY - 25)); if (Math.sqrt(((_local2 * _local2) + (_local3 * _local3))) < 45){ foam.stop(); Parent.NbLevel++; Parent.render(); }; for each (_local4 in foam.simulatables) { if (_local4.y > FALL_LIMIT){ if (_local4.tag == 1){ _local4.vy = 0; _local4.vx = 0; _local4.x = startX; _local4.y = startY; } else { foam.removeElement(_local4); }; }; }; } private function reset(_arg1:KeyboardEvent):void{ var _local2:ISimulatable; if (_arg1.keyCode == 82){ for each (_local2 in foam.simulatables) { if (_local2.tag == 1){ _local2.vy = 0; _local2.vx = 0; _local2.x = startX; _local2.y = startY; } else { foam.removeElement(_local2); }; }; }; } } }//package levels
Section 13
//Level9 (levels.Level9) package levels { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.force.*; import flash.display.*; import org.generalrelativity.foam.dynamics.element.*; import org.generalrelativity.foam.view.*; import org.generalrelativity.foam.dynamics.element.body.*; import flash.events.*; import org.generalrelativity.foam.util.*; import org.generalrelativity.foam.dynamics.enum.*; import org.generalrelativity.foam.*; public class Level9 extends Sprite { const startX:Number = 120; const startY:Number = 100; const RENDER:Boolean = true; const FALL_LIMIT:int = 1000; const endX:Number = 600; const endY:Number = 380; var Marker; var ObjCircle:Circle; public var foam:Foam; var Parent; public function Level9(_arg1, _arg2){ var _local3:RigidBody; var _local4:*; var _local5:Circle; var _local6:Circle; ObjCircle = new Circle(startX, startY, 25); super(); Marker = _arg1; Parent = _arg2; foam = (addChild(new Foam()) as Foam); foam.useMouseDragger(true); foam.setRenderer(new DisplayObjectFoamRenderer()); foam.solverIterations = 2; foam.addGlobalForceGenerator(new Gravity(new Vector(0, 1.3))); foam.addGlobalForceGenerator(new Friction(0.02)); _local3 = new RigidBody(320, 400, Simplification.INFINITE_MASS, ShapeUtil.createRectangle(600, 30)); foam.addElement(_local3, true, RENDER); _local4 = 0; while (_local4 < 6) { _local6 = new Circle((320 + (Math.random() * 2)), (-(_local4) * 100), 32); foam.addElement(_local6, true, true, new DisplayObjectData(Circle1)); _local4++; }; ObjCircle.tag = 1; foam.addElement(ObjCircle, true, true, new DisplayObjectData(ball, 1, 1)); _local5 = new Circle(endX, endY, 25, Simplification.INFINITE_MASS); _local5.tag = 1; foam.addElement(_local5, false, true, new DisplayObjectData(star, 0, 0)); foam.addEventListener(Foam.STEP, onFoamStep, false, 0, true); foam.simulate(); addEventListener(Event.ADDED, init, false, 0, true); } private function init(_arg1:Event):void{ stage.addEventListener(KeyboardEvent.KEY_DOWN, reset, false, 0, true); removeEventListener(Event.REMOVED, init); } private function onFoamStep(_arg1:Event):void{ var _local2:Number; var _local3:Number; var _local4:ISimulatable; Marker.update(); _local2 = (ObjCircle.x - (endX - 25)); _local3 = (ObjCircle.y - (endY - 25)); if (Math.sqrt(((_local2 * _local2) + (_local3 * _local3))) < 45){ foam.stop(); Parent.NbLevel++; Parent.render(); }; for each (_local4 in foam.simulatables) { if (_local4.y > FALL_LIMIT){ if (_local4.tag == 1){ _local4.vy = 0; _local4.vx = 0; _local4.x = startX; _local4.y = startY; } else { foam.removeElement(_local4); }; }; }; } private function reset(_arg1:KeyboardEvent):void{ var _local2:ISimulatable; var _local3:*; var _local4:Circle; if (_arg1.keyCode == 82){ for each (_local2 in foam.simulatables) { if (_local2.tag == 1){ _local2.vy = 0; _local2.vx = 0; _local2.x = startX; _local2.y = startY; } else { foam.removeElement(_local2); }; }; _local3 = 0; while (_local3 < 6) { _local4 = new Circle((320 + (Math.random() * 2)), (-(_local3) * 100), 32); foam.addElement(_local4, true, true, new DisplayObjectData(Circle1)); _local3++; }; }; } } }//package levels
Section 14
//AABRDetector (org.generalrelativity.foam.dynamics.collision.coarse.AABRDetector) package org.generalrelativity.foam.dynamics.collision.coarse { import org.generalrelativity.foam.dynamics.element.*; import org.generalrelativity.foam.dynamics.collision.*; import org.generalrelativity.foam.dynamics.collision.geom.*; import org.generalrelativity.foam.dynamics.collision.fine.sat.*; import org.generalrelativity.foam.dynamics.enum.*; import flash.utils.*; public class AABRDetector implements ICoarseCollisionDetector { private var _staticAABRCache:Dictionary; private var _dynamicLength:int; private var _factory:ICollisionFactory; private var _dynamicCollidables:Array; private var _staticCollidables:Array; private var _dynamicAABRCache:Dictionary; private var _collidablesLength:int; public function AABRDetector(){ _staticAABRCache = new Dictionary(true); _dynamicAABRCache = new Dictionary(true); _staticCollidables = new Array(); _dynamicCollidables = new Array(); _factory = new SATCollisionFactory(); } public function getCandidates():Array{ var _local1:Array; var _local2:AABR; var _local3:AABR; var _local4:int; var _local5:int; var _local6:Array; _dynamicAABRCache = new Dictionary(true); _local1 = new Array(); _local4 = -1; _local6 = _dynamicCollidables.concat(_staticCollidables); while (++_local4 < _dynamicLength) { _local2 = getBoundedAABR(_dynamicCollidables[_local4]); _local5 = _local4; while (++_local5 < _collidablesLength) { _local3 = getBoundedAABR(_local6[_local5]); if (_local2.hasCollision(_local3)){ _local1.push(_factory.getCollisionDetector(_local6[_local4], _local6[_local5])); }; }; }; return (_local1); } private function getBoundedAABR(_arg1:IBody):AABR{ var _local2:AABR; if (_dynamicAABRCache[_arg1]){ return (AABR(_dynamicAABRCache[_arg1])); }; if (_staticAABRCache[_arg1]){ return (AABR(_staticAABRCache[_arg1])); }; _local2 = new AABR(); _local2.bound(_arg1); return (_local2); } public function set factory(_arg1:ICollisionFactory):void{ _factory = _arg1; } public function removeCollidable(_arg1:ISimulatable):void{ var _local2:int; _local2 = _dynamicCollidables.indexOf(_arg1); if (_local2 > -1){ _dynamicCollidables.splice(_dynamicCollidables.indexOf(_arg1), 1); } else { _local2 = _staticCollidables.indexOf(_arg1); if (_local2 > -1){ _staticCollidables.splice(_staticCollidables.indexOf(_arg1), 1); }; }; _dynamicLength = _dynamicCollidables.length; _collidablesLength = (_dynamicLength + _staticCollidables.length); } public function addCollidable(_arg1:ISimulatable):void{ if (_arg1.mass == Simplification.INFINITE_MASS){ _staticCollidables.push(_arg1); } else { _dynamicCollidables.push(_arg1); _dynamicLength++; }; _collidablesLength++; } public function getDynamicCollidables():Array{ return (_dynamicCollidables); } } }//package org.generalrelativity.foam.dynamics.collision.coarse
Section 15
//CollisionType (org.generalrelativity.foam.dynamics.collision.enum.CollisionType) package org.generalrelativity.foam.dynamics.collision.enum { public class CollisionType { public static const CIRCLE:String = "circle"; public static const ABSTRACT_PARTICLE:String = "abstract_particle"; public static const CUBIC_BEZIER_CURVE:String = "cubic_bezier_curve"; public static const RIGID_BODY:String = "rigid_body"; } }//package org.generalrelativity.foam.dynamics.collision.enum
Section 16
//AxisProjection (org.generalrelativity.foam.dynamics.collision.fine.sat.AxisProjection) package org.generalrelativity.foam.dynamics.collision.fine.sat { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.element.*; public class AxisProjection { public var min:Number; public var max:Number; public function AxisProjection(_arg1:IBody, _arg2:Vector){ project(_arg1, _arg2); } protected function project(_arg1:IBody, _arg2:Vector):void{ var _local3:RotationMatrix; var _local4:Number; var _local5:Number; _local3 = _arg1.rotation; _local4 = _arg2.dot(_local3.getVectorProduct(Vector(_arg1.vertices[0])).plus(_arg1.position)); min = _local4; max = _local4; _local5 = 0; while (++_local5 < _arg1.vertices.length) { _local4 = _arg2.dot(_local3.getVectorProduct(Vector(_arg1.vertices[_local5])).plus(_arg1.position)); if (_local4 < min){ min = _local4; } else { if (_local4 > max){ max = _local4; }; }; }; } public function getDistance(_arg1:AxisProjection):Number{ if (min < _arg1.min){ return ((_arg1.min - max)); }; return ((min - _arg1.max)); } } }//package org.generalrelativity.foam.dynamics.collision.fine.sat
Section 17
//BezierDetector (org.generalrelativity.foam.dynamics.collision.fine.sat.BezierDetector) package org.generalrelativity.foam.dynamics.collision.fine.sat { import org.generalrelativity.foam.dynamics.element.*; import org.generalrelativity.foam.dynamics.collision.*; import org.generalrelativity.foam.dynamics.element.body.*; public class BezierDetector implements IFineCollisionDetector { protected var detectors:Array; protected var body2:IBody; protected var curve:CubicBezierCurve; public function BezierDetector(_arg1:CubicBezierCurve, _arg2:IBody){ this.curve = _arg1; this.body2 = _arg2; } public function getContacts():Array{ var _local1:Array; _local1 = new Array(); while (detectors.length) { _local1 = _local1.concat(IFineCollisionDetector(detectors.pop()).getContacts()); }; return (_local1); } public function hasCollision():Boolean{ var _local1:IFineCollisionDetector; var _local2:IBody; detectors = new Array(); for each (_local2 in curve.lines) { if ((body2 is Circle)){ _local1 = new CirclePolygonDetector(Circle(body2), _local2); } else { _local1 = new PolygonPolygonDetector(_local2, body2); }; if (_local1.hasCollision()){ detectors.push(_local1); }; }; return ((detectors.length > 0)); } } }//package org.generalrelativity.foam.dynamics.collision.fine.sat
Section 18
//CircleAxisProjection (org.generalrelativity.foam.dynamics.collision.fine.sat.CircleAxisProjection) package org.generalrelativity.foam.dynamics.collision.fine.sat { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.element.*; import org.generalrelativity.foam.dynamics.element.body.*; public class CircleAxisProjection extends AxisProjection { public function CircleAxisProjection(_arg1:Circle, _arg2:Vector){ super(_arg1, _arg2); } override protected function project(_arg1:IBody, _arg2:Vector):void{ var _local3:Circle; var _local4:Number; _local3 = Circle(_arg1); _local4 = _arg2.dot(_local3.position); min = (_local4 - _local3.radius); max = (_local4 + _local3.radius); } } }//package org.generalrelativity.foam.dynamics.collision.fine.sat
Section 19
//CircleCircleDetector (org.generalrelativity.foam.dynamics.collision.fine.sat.CircleCircleDetector) package org.generalrelativity.foam.dynamics.collision.fine.sat { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.collision.*; import org.generalrelativity.foam.dynamics.element.body.*; public class CircleCircleDetector implements IFineCollisionDetector { public var circle1:Circle; public var dist:Number; public var circle2:Circle; public function CircleCircleDetector(_arg1:Circle, _arg2:Circle){ this.circle1 = _arg1; this.circle2 = _arg2; } public function getContacts():Array{ var _local1:Vector; var _local2:Number; var _local3:Vector; var _local4:Vector; dist = Math.sqrt(dist); _local1 = circle1.position.minus(circle2.position); _local2 = ((circle1.radius + circle2.radius) - dist); _local1.normalize(); _local3 = _local1.times(_local2); _local3.dividedByEquals((circle1.inverseMass + circle2.inverseMass)); circle1.x = (circle1.x + (_local3.x * circle1.inverseMass)); circle1.y = (circle1.y + (_local3.y * circle1.inverseMass)); circle2.x = (circle2.x - (_local3.x * circle2.inverseMass)); circle2.y = (circle2.y - (_local3.y * circle2.inverseMass)); _local4 = circle1.position.minus(_local1.times(circle1.radius)); return ([new Contact(_local4, circle1, circle2, _local1)]); } public function hasCollision():Boolean{ var _local1:Vector; _local1 = circle1.position.minus(circle2.position); dist = _local1.dot(_local1); return ((dist <= ((circle1.radius + circle2.radius) * (circle1.radius + circle2.radius)))); } } }//package org.generalrelativity.foam.dynamics.collision.fine.sat
Section 20
//CirclePolygonDetector (org.generalrelativity.foam.dynamics.collision.fine.sat.CirclePolygonDetector) package org.generalrelativity.foam.dynamics.collision.fine.sat { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.element.*; import org.generalrelativity.foam.dynamics.collision.*; import org.generalrelativity.foam.dynamics.element.body.*; public class CirclePolygonDetector implements IFineCollisionDetector { public var body:IBody; public var minDistance:Number; public var penetrationAxis:Vector; public var circle:Circle; public function CirclePolygonDetector(_arg1:Circle, _arg2:IBody){ this.circle = _arg1; this.body = _arg2; } public function getContacts():Array{ var _local1:Vector; var _local2:Vector; var _local3:Vector; _local1 = circle.position.minus(body.position); if (_local1.dot(penetrationAxis) < 0){ penetrationAxis.negate(); }; _local2 = penetrationAxis.times(minDistance); _local2.dividedByEquals((circle.inverseMass + body.inverseMass)); circle.x = (circle.x + (_local2.x * circle.inverseMass)); circle.y = (circle.y + (_local2.y * circle.inverseMass)); body.x = (body.x - (_local2.x * body.inverseMass)); body.y = (body.y - (_local2.y * body.inverseMass)); _local3 = circle.position.minus(penetrationAxis.times(circle.radius)); return ([new Contact(_local3, circle, body, penetrationAxis)]); } public function hasCollision():Boolean{ var _local1:Vector; var _local2:CircleAxisProjection; var _local3:AxisProjection; var _local4:RotationMatrix; var _local5:Array; var _local6:int; var _local7:Number; var _local8:Vector; var _local9:Number; var _local10:Vector; var _local11:Vector; var _local12:Number; var _local13:Vector; var _local14:Number; if ((((circle.inverseMass == 0)) && ((body.inverseMass == 0)))){ return (false); }; _local4 = body.rotation; minDistance = Number.MAX_VALUE; _local5 = body.edges; _local6 = _local5.length; _local7 = -1; while (++_local7 < _local6) { _local1 = _local4.getVectorProduct((_local5[_local7] as Vector)); _local11 = new Vector(-(_local1.y), _local1.x); _local11.normalize(); _local2 = new CircleAxisProjection(circle, _local11); _local3 = new AxisProjection(body, _local11); _local12 = _local2.getDistance(_local3); if (_local12 > 0){ return (false); }; _local12 = Math.abs(_local12); if (_local12 < minDistance){ minDistance = _local12; penetrationAxis = _local11; }; }; _local9 = Number.MAX_VALUE; for each (_local10 in body.vertices) { _local8 = body.rotation.getVectorProduct(_local10).plus(body.position); _local13 = circle.position.minus(_local8); _local14 = ((_local13.x * _local13.x) + (_local13.y * _local13.y)); if (_local14 < _local9){ _local9 = _local14; _local11 = _local13; }; }; _local11.normalize(); _local2 = new CircleAxisProjection(circle, _local11); _local3 = new AxisProjection(body, _local11); _local12 = _local3.getDistance(_local2); if (_local12 > 0){ return (false); }; _local12 = Math.abs(_local12); if (_local12 < minDistance){ minDistance = _local12; penetrationAxis = _local11; }; return (true); } } }//package org.generalrelativity.foam.dynamics.collision.fine.sat
Section 21
//PointPolygonDetector (org.generalrelativity.foam.dynamics.collision.fine.sat.PointPolygonDetector) package org.generalrelativity.foam.dynamics.collision.fine.sat { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.element.*; import org.generalrelativity.foam.dynamics.element.body.*; public class PointPolygonDetector { protected var point:Vector; protected var body:IBody; protected static const EPSILON:Number = 15; public function PointPolygonDetector(_arg1:IBody, _arg2:Vector){ this.body = _arg1; this.point = _arg2; } public function hasCollision():Boolean{ var _local1:Vector; var _local2:RotationMatrix; var _local3:int; var _local4:Vector; var _local5:AxisProjection; var _local6:Number; var _local7:Number; var _local8:Number; if ((body is Circle)){ _local8 = point.minus(body.position).magnitude; if (_local8 <= Circle(body).radius){ return (true); }; return (false); }; _local2 = body.rotation; _local3 = body.edges.length; _local7 = -1; while (++_local7 < _local3) { _local1 = _local2.getVectorProduct((body.edges[_local7] as Vector)); _local4 = new Vector(-(_local1.y), _local1.x); _local4.normalize(); _local5 = new AxisProjection(body, _local4); _local6 = _local4.dot(point); if (((((_local6 + PointPolygonDetector.EPSILON) < _local5.min)) || (((_local6 - PointPolygonDetector.EPSILON) > _local5.max)))){ return (false); }; }; _local4 = point.minus(body.position); _local4.normalize(); _local5 = new AxisProjection(body, _local4); _local6 = _local4.dot(point); if (((((_local6 + PointPolygonDetector.EPSILON) < _local5.min)) || (((_local6 - PointPolygonDetector.EPSILON) > _local5.max)))){ return (false); }; return (true); } } }//package org.generalrelativity.foam.dynamics.collision.fine.sat
Section 22
//PolygonPolygonDetector (org.generalrelativity.foam.dynamics.collision.fine.sat.PolygonPolygonDetector) package org.generalrelativity.foam.dynamics.collision.fine.sat { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.element.*; import org.generalrelativity.foam.dynamics.collision.*; import flash.utils.*; public class PolygonPolygonDetector implements IFineCollisionDetector { public var penetrationAxis:Vector; public var body2:IBody; public var body1:IBody; private var swapBodies:Boolean; public var minDistance:Number; public static const EPSILON:Number = 0.1; public function PolygonPolygonDetector(_arg1:IBody, _arg2:IBody){ this.body1 = _arg1; this.body2 = _arg2; swapBodies = true; } public function getContacts():Array{ var _local1:Vector; var _local2:Vector; var _local3:Number; var _local4:Array; var _local5:Vector; var _local6:RotationMatrix; var _local7:Vector; var _local8:Array; var _local9:Array; var _local10:IBody; var _local11:Vector; var _local12:Number; var _local13:Vector; var _local14:Dictionary; var _local15:Number; var _local16:Number; var _local17:Number; var _local18:Number; var _local19:Array; if (swapBodies){ _local10 = body1; body1 = body2; body2 = _local10; }; _local1 = body1.position.minus(body2.position); if (_local1.dot(penetrationAxis) < 0){ penetrationAxis.negate(); }; _local2 = penetrationAxis.times(minDistance); _local2.dividedByEquals((body1.inverseMass + body2.inverseMass)); body1.x = (body1.x + (_local2.x * body1.inverseMass)); body1.y = (body1.y + (_local2.y * body1.inverseMass)); body2.x = (body2.x - (_local2.x * body2.inverseMass)); body2.y = (body2.y - (_local2.y * body2.inverseMass)); _local3 = Number.MAX_VALUE; _local5 = penetrationAxis.clone(); _local6 = body1.rotation; for each (_local7 in body1.vertices) { _local11 = _local6.getVectorProduct(_local7).plus(body1.position); _local12 = _local5.dot(_local11); if (_local12 < (_local3 + PolygonPolygonDetector.EPSILON)){ if (Math.abs((_local3 - _local12)) < PolygonPolygonDetector.EPSILON){ _local4 = [_local4[0], _local11]; } else { _local4 = [_local11]; _local3 = _local12; }; }; }; if (_local4.length == 1){ return ([new Contact(_local4[0], body1, body2, penetrationAxis)]); }; _local3 = Number.MAX_VALUE; _local5.negate(); _local6 = body2.rotation; for each (_local7 in body2.vertices) { _local11 = _local6.getVectorProduct(_local7).plus(body2.position); _local12 = _local5.dot(_local11); if (_local12 < (_local3 + PolygonPolygonDetector.EPSILON)){ if (Math.abs((_local3 - _local12)) < PolygonPolygonDetector.EPSILON){ _local8 = [_local8[0], _local11]; } else { _local8 = [_local11]; _local3 = _local12; }; }; }; _local9 = new Array(); if (_local8.length == 2){ _local13 = penetrationAxis.getPerp().getUnit(); _local14 = new Dictionary(true); _local15 = _local13.dot((_local4[0] as Vector)); _local16 = _local13.dot((_local4[1] as Vector)); _local17 = _local13.dot((_local8[0] as Vector)); _local18 = _local13.dot((_local8[1] as Vector)); _local14[_local15] = _local4[0]; _local14[_local16] = _local4[1]; _local14[_local17] = _local8[0]; _local14[_local18] = _local8[1]; _local19 = [_local15, _local16, _local17, _local18]; _local19.sort(Array.DESCENDING); _local9.push(new Contact(_local14[_local19[1]], body1, body2, penetrationAxis), new Contact(_local14[_local19[2]], body1, body2, penetrationAxis)); } else { _local9.push(new Contact(_local8[0], body1, body2, penetrationAxis)); }; return (_local9); } public function hasCollision():Boolean{ var _local1:Vector; var _local2:AxisProjection; var _local3:AxisProjection; var _local4:RotationMatrix; var _local5:Array; var _local6:int; var _local7:Number; var _local8:Vector; var _local9:Number; if ((((body1.inverseMass == 0)) && ((body2.inverseMass == 0)))){ return (false); }; _local4 = body1.rotation; minDistance = Number.MAX_VALUE; _local5 = body1.edges.concat(body2.edges); _local6 = _local5.length; _local7 = -1; while (++_local7 < _local6) { if (_local7 == body1.edges.length){ _local4 = body2.rotation; }; _local1 = _local4.getVectorProduct((_local5[_local7] as Vector)); _local8 = new Vector(-(_local1.y), _local1.x); _local8.normalize(); _local2 = new AxisProjection(body1, _local8); _local3 = new AxisProjection(body2, _local8); _local9 = _local2.getDistance(_local3); if (_local9 > 0){ return (false); }; _local9 = ((_local9 < 0)) ? -(_local9) : _local9; if (_local9 < minDistance){ minDistance = _local9; penetrationAxis = _local8; if (((swapBodies) && ((_local7 > body1.edges.length)))){ swapBodies = false; }; }; }; return (true); } } }//package org.generalrelativity.foam.dynamics.collision.fine.sat
Section 23
//SATCollisionFactory (org.generalrelativity.foam.dynamics.collision.fine.sat.SATCollisionFactory) package org.generalrelativity.foam.dynamics.collision.fine.sat { import org.generalrelativity.foam.dynamics.element.*; import org.generalrelativity.foam.dynamics.collision.*; import org.generalrelativity.foam.dynamics.element.body.*; import org.generalrelativity.foam.dynamics.collision.enum.*; import flash.utils.*; public class SATCollisionFactory implements ICollisionFactory { private var detectorMap:Dictionary; public function SATCollisionFactory(){ buildDetectorMap(); } public function getCollisionDetector(_arg1:ISimulatable, _arg2:ISimulatable):IFineCollisionDetector{ var _local3:Class; _local3 = detectorMap[_arg1.collisionTypeID][_arg2.collisionTypeID]; if ((((_arg2 is Circle)) || ((_arg2 is CubicBezierCurve)))){ return (IFineCollisionDetector(new _local3(_arg2, _arg1))); }; return (IFineCollisionDetector(new _local3(_arg1, _arg2))); } private function buildDetectorMap():void{ var _local1:Dictionary; var _local2:Dictionary; var _local3:Dictionary; detectorMap = new Dictionary(true); _local1 = new Dictionary(true); _local1[CollisionType.CIRCLE] = CirclePolygonDetector; _local1[CollisionType.CUBIC_BEZIER_CURVE] = BezierDetector; _local1[CollisionType.RIGID_BODY] = PolygonPolygonDetector; _local2 = new Dictionary(true); _local2[CollisionType.RIGID_BODY] = CirclePolygonDetector; _local2[CollisionType.CIRCLE] = CircleCircleDetector; _local2[CollisionType.CUBIC_BEZIER_CURVE] = BezierDetector; _local3 = new Dictionary(true); _local3[CollisionType.RIGID_BODY] = BezierDetector; _local3[CollisionType.CIRCLE] = BezierDetector; detectorMap[CollisionType.RIGID_BODY] = _local1; detectorMap[CollisionType.CIRCLE] = _local2; detectorMap[CollisionType.CUBIC_BEZIER_CURVE] = _local3; } } }//package org.generalrelativity.foam.dynamics.collision.fine.sat
Section 24
//AABR (org.generalrelativity.foam.dynamics.collision.geom.AABR) package org.generalrelativity.foam.dynamics.collision.geom { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.element.*; import org.generalrelativity.foam.dynamics.element.body.*; public class AABR { public var minX:Number; public var minY:Number; public var maxX:Number; public var maxY:Number; private function updateBounds(_arg1:Vector):void{ if (_arg1.x < minX){ minX = _arg1.x; } else { if (_arg1.x > maxX){ maxX = _arg1.x; }; }; if (_arg1.y < minY){ minY = _arg1.y; } else { if (_arg1.y > maxY){ maxY = _arg1.y; }; }; } public function hasCollision(_arg1:AABR):Boolean{ if (maxX < _arg1.minX){ return (false); }; if (maxY < _arg1.minY){ return (false); }; if (_arg1.maxX < minX){ return (false); }; if (_arg1.maxY < minY){ return (false); }; return (true); } public function bound(_arg1:IBody):void{ var _local2:Number; var _local3:RotationMatrix; var _local4:int; var _local5:Vector; if ((_arg1 is Circle)){ _local2 = Circle(_arg1).radius; minX = (_arg1.x - _local2); maxX = (_arg1.x + _local2); minY = (_arg1.y - _local2); maxY = (_arg1.y + _local2); } else { minX = (maxX = _arg1.x); minY = (maxY = _arg1.y); _local3 = _arg1.rotation; _local4 = -1; for each (_local5 in _arg1.vertices) { updateBounds(_arg1.position.plus(_local3.getVectorProduct(_local5))); }; }; } } }//package org.generalrelativity.foam.dynamics.collision.geom
Section 25
//CollisionResolver (org.generalrelativity.foam.dynamics.collision.CollisionResolver) package org.generalrelativity.foam.dynamics.collision { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.element.*; public class CollisionResolver { public static function resolve(_arg1:Array):void{ var _local2:IBody; var _local3:IBody; var _local4:Contact; var _local5:Vector; var _local6:Vector; var _local7:Vector; var _local8:Vector; var _local9:Number; var _local10:Number; var _local11:Number; var _local12:Vector; var _local13:Vector; var _local14:Vector; var _local15:Number; var _local16:Number; var _local17:Number; var _local18:Vector; var _local19:Number; var _local20:Vector; var _local21:Number; var _local22:Vector; var _local23:Number; var _local24:Number; var _local25:Number; for each (_local4 in _arg1) { _local2 = _local4.body1; _local3 = _local4.body2; _local5 = _local4.position.minus(_local4.body1.position); _local6 = _local4.position.minus(_local4.body2.position); _local7 = _local5.getPerp(); _local8 = _local6.getPerp(); _local9 = _local7.dot(_local4.normal); _local10 = _local8.dot(_local4.normal); _local11 = _local4.normal.dot(_local4.normal.times((_local2.inverseMass + _local3.inverseMass))); _local11 = (_local11 + ((_local9 * _local9) * _local2.inverseI)); _local11 = (_local11 + ((_local10 * _local10) * _local3.inverseI)); _local12 = _local7.times(_local2.av).plus(_local2.velocity); _local13 = _local8.times(_local3.av).plus(_local3.velocity); _local14 = _local12.minus(_local13); _local15 = _local14.dot(_local4.normal); _local16 = ((_local2.elasticity + _local3.elasticity) * 0.5); _local17 = ((-((1 + _local16)) * _local15) / _local11); _local18 = _local4.normal.times((_local17 * _local2.inverseMass)); _local19 = (_local7.dot(_local4.normal.times(_local17)) * _local2.inverseI); _local20 = _local4.normal.times((-(_local17) * _local3.inverseMass)); _local21 = (_local8.dot(_local4.normal.times(-(_local17))) * _local3.inverseI); _local22 = _local4.normal.getPerp(); _local23 = _local7.dot(_local22); _local24 = _local8.dot(_local22); _local11 = _local22.dot(_local22.times((_local2.inverseMass + _local3.inverseMass))); _local11 = (_local11 + ((_local23 * _local23) * _local2.inverseI)); _local11 = (_local11 + ((_local24 * _local24) * _local3.inverseI)); _local25 = _local14.dot(_local22); _local17 = (((-(_local25) / _local11) * (_local2.friction + _local3.friction)) * 0.5); _local18.plusEquals(_local22.times((_local17 * _local2.inverseMass))); _local19 = (_local19 + (_local7.dot(_local22.times(_local17)) * _local2.inverseI)); _local20.plusEquals(_local22.times((-(_local17) * _local3.inverseMass))); _local21 = (_local21 + (_local8.dot(_local22.times(-(_local17))) * _local3.inverseI)); _local2.vx = (_local2.vx + _local18.x); _local2.vy = (_local2.vy + _local18.y); _local2.av = (_local2.av + _local19); _local3.vx = (_local3.vx + _local20.x); _local3.vy = (_local3.vy + _local20.y); _local3.av = (_local3.av + _local21); }; } } }//package org.generalrelativity.foam.dynamics.collision
Section 26
//Contact (org.generalrelativity.foam.dynamics.collision.Contact) package org.generalrelativity.foam.dynamics.collision { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.element.*; public class Contact { public var normal:Vector; public var position:Vector; public var body2:IBody; public var body1:IBody; public function Contact(_arg1:Vector, _arg2:IBody, _arg3:IBody, _arg4:Vector){ this.position = _arg1; this.body1 = _arg2; this.body2 = _arg3; this.normal = _arg4; } } }//package org.generalrelativity.foam.dynamics.collision
Section 27
//ICoarseCollisionDetector (org.generalrelativity.foam.dynamics.collision.ICoarseCollisionDetector) package org.generalrelativity.foam.dynamics.collision { import org.generalrelativity.foam.dynamics.element.*; public interface ICoarseCollisionDetector { function addCollidable(_arg1:ISimulatable):void; function set factory(_arg1:ICollisionFactory):void; function removeCollidable(_arg1:ISimulatable):void; function getCandidates():Array; function getDynamicCollidables():Array; } }//package org.generalrelativity.foam.dynamics.collision
Section 28
//ICollisionFactory (org.generalrelativity.foam.dynamics.collision.ICollisionFactory) package org.generalrelativity.foam.dynamics.collision { import org.generalrelativity.foam.dynamics.element.*; public interface ICollisionFactory { function getCollisionDetector(_arg1:ISimulatable, _arg2:ISimulatable):IFineCollisionDetector; } }//package org.generalrelativity.foam.dynamics.collision
Section 29
//IFineCollisionDetector (org.generalrelativity.foam.dynamics.collision.IFineCollisionDetector) package org.generalrelativity.foam.dynamics.collision { public interface IFineCollisionDetector { function hasCollision():Boolean; function getContacts():Array; } }//package org.generalrelativity.foam.dynamics.collision
Section 30
//Circle (org.generalrelativity.foam.dynamics.element.body.Circle) package org.generalrelativity.foam.dynamics.element.body { import org.generalrelativity.foam.dynamics.enum.*; import org.generalrelativity.foam.dynamics.collision.enum.*; public class Circle extends RigidBody { public var radius:Number; public function Circle(_arg1:Number, _arg2:Number, _arg3:Number, _arg4:Number=100, _arg5:Number=0, _arg6:Number=0, _arg7:Number=0.5, _arg8:Number=0.15, _arg9:Number=0, _arg10:Number=0){ this.radius = _arg3; super(_arg1, _arg2, _arg4, null, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10); } override public function get collisionTypeID():String{ return (CollisionType.CIRCLE); } override protected function calculateInertiaTensor():void{ if (mass == Simplification.INFINITE_MASS){ _I = Simplification.INFINITE_MASS; _inverseI = 0; return; }; _I = ((radius * radius) * mass); _inverseI = (1 / _I); } } }//package org.generalrelativity.foam.dynamics.element.body
Section 31
//CubicBezierCurve (org.generalrelativity.foam.dynamics.element.body.CubicBezierCurve) package org.generalrelativity.foam.dynamics.element.body { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.enum.*; import org.generalrelativity.foam.dynamics.collision.enum.*; public class CubicBezierCurve extends RigidBody { public var lines:Array; protected var anchor1:Vector; protected var anchor2:Vector; protected var height:Number; protected var control1:Vector; protected var control2:Vector; protected var resolution:int; public function CubicBezierCurve(_arg1:Number, _arg2:Number, _arg3:Vector, _arg4:Vector, _arg5:Vector, _arg6:Vector, _arg7:int=7, _arg8:Number=INF, _arg9:Number=0, _arg10:Number=0, _arg11:Number=0, _arg12:Number=0, _arg13:Number=0.2, _arg14:Number=0.15, _arg15:Number=150){ super(_arg1, _arg2, _arg8, null, _arg9, _arg10, _arg13, _arg14, _arg11, _arg12); this.height = _arg15; this.resolution = _arg7; this.control1 = _arg3; this.control2 = _arg5; this.anchor1 = _arg4; this.anchor2 = _arg6; createLines(); } protected function createLines():void{ var _local1:int; var _local2:Number; var _local3:Number; var _local4:Number; var _local5:Number; var _local6:Number; var _local7:Number; var _local8:Number; var _local9:Number; var _local10:Number; var _local11:Number; var _local12:Number; var _local13:Number; var _local14:Number; var _local15:RigidBody; _local8 = (1 / resolution); _local11 = control1.x; _local12 = control1.y; lines = new Array(); while (++_local1 <= resolution) { _local2 = (_local8 * _local1); _local3 = (_local2 * _local2); _local4 = (_local3 * _local2); _local5 = (1 - _local2); _local6 = ((1 - _local2) * _local5); _local7 = (_local6 * _local5); _local9 = ((((_local7 * control1.x) + (((3 * _local2) * _local6) * anchor1.x)) + (((3 * anchor2.x) * _local3) * _local5)) + (control2.x * _local4)); _local10 = ((((_local7 * control1.y) + (((3 * _local2) * _local6) * anchor1.y)) + (((3 * anchor2.y) * _local3) * _local5)) + (control2.y * _local4)); _local13 = (_local9 - _local11); _local14 = (_local10 - _local12); _local15 = new RigidBody(((x + _local11) + (_local13 / 2)), ((y + _local12) + (_local14 / 2)), Simplification.INFINITE_MASS, [new Vector((_local13 / 2), (_local14 / 2)), new Vector((-(_local13) / 2), (-(_local14) / 2))], 0, 0, 0, 0, friction); _local11 = _local9; _local12 = _local10; lines.push(_local15); }; } override public function get collisionTypeID():String{ return (CollisionType.CUBIC_BEZIER_CURVE); } override protected function calculateInertiaTensor():void{ if (mass == Simplification.INFINITE_MASS){ _I = Simplification.INFINITE_MASS; _inverseI = 0; return; }; _I = ((control1.magnitude * mass) / 3); _I = (_I + ((control2.magnitude * mass) / 3)); _I = (_I + (((anchor1.magnitude * mass) / 3) * 0.5)); _I = (_I + (((anchor2.magnitude * mass) / 3) * 0.5)); _inverseI = (1 / _I); } } }//package org.generalrelativity.foam.dynamics.element.body
Section 32
//RigidBody (org.generalrelativity.foam.dynamics.element.body.RigidBody) package org.generalrelativity.foam.dynamics.element.body { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.element.*; import org.generalrelativity.foam.dynamics.ode.*; import org.generalrelativity.foam.util.*; import org.generalrelativity.foam.dynamics.enum.*; import org.generalrelativity.foam.dynamics.collision.enum.*; import org.generalrelativity.foam.dynamics.element.particle.*; public class RigidBody extends SimpleParticle implements IODE, ISimulatable, IBody { protected var _torque:Number; protected var _edges:Array; protected var _vertices:Array; protected var _inverseI:Number; protected var _I:Number; protected var _rotation:RotationMatrix; public function RigidBody(_arg1:Number, _arg2:Number, _arg3:Number=100, _arg4:Array=null, _arg5:Number=0, _arg6:Number=0, _arg7:Number=0.2, _arg8:Number=0.25, _arg9:Number=0, _arg10:Number=0){ if (_arg4){ _vertices = _arg4; _edges = ShapeUtil.getEdges(_arg4); }; super(_arg1, _arg2, _arg5, _arg6, _arg3, _arg7, _arg8, 6); this.q = _arg9; this.av = _arg10; _rotation = new RotationMatrix(_arg9); clearTorque(); calculateInertiaTensor(); } public function get vertices():Array{ return (_vertices); } public function addForceAtPoint(_arg1:Vector, _arg2:Vector):void{ addForce(_arg2); addTorque(_arg1.getPerp().dot(_arg2)); } public function addTorque(_arg1:Number):void{ _torque = (_torque + _arg1); } public function get torque():Number{ return (_torque); } public function setRot(_arg1:Number):void{ q = ((_arg1 * Math.PI) / 180); } public function get inverseI():Number{ return (_inverseI); } public function get av():Number{ return (_state[5]); } public function get I():Number{ return (_I); } public function getVelocityAtPoint(_arg1:Vector):Vector{ var _local2:Vector; _local2 = _arg1.minus(position).getPerp(); _local2.normalize(); return (velocity.plus(_local2.times(av))); } public function get edges():Array{ return (_edges); } public function set av(_arg1:Number):void{ _state[5] = _arg1; } public function get q():Number{ return (_state[4]); } override public function getDerivative(_arg1:Array, _arg2:Array):void{ this._state = _arg1; accumulateForces(); _arg2[0] = _arg1[2]; _arg2[1] = _arg1[3]; _arg2[2] = (_force.x * _inverseMass); _arg2[3] = (_force.y * _inverseMass); _arg2[4] = _arg1[5]; _arg2[5] = (_torque * _inverseI); clearForces(); clearTorque(); } public function get rotation():RotationMatrix{ if (_rotation.theta != q){ _rotation = new RotationMatrix(q); }; return (_rotation); } override public function get collisionTypeID():String{ return (CollisionType.RIGID_BODY); } public function clearTorque():void{ _torque = 0; } public function set q(_arg1:Number):void{ _state[4] = _arg1; } protected function calculateInertiaTensor():void{ var _local1:Number; var _local2:Vector; if (mass == Simplification.INFINITE_MASS){ _I = Simplification.INFINITE_MASS; _inverseI = 0; return; }; _I = 0; _local1 = (mass / _vertices.length); for each (_local2 in _vertices) { _I = (_I + (_local2.dot(_local2) * _local1)); }; _inverseI = (1 / _I); } } }//package org.generalrelativity.foam.dynamics.element.body
Section 33
//SimpleParticle (org.generalrelativity.foam.dynamics.element.particle.SimpleParticle) package org.generalrelativity.foam.dynamics.element.particle { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.force.*; import org.generalrelativity.foam.dynamics.element.*; import org.generalrelativity.foam.dynamics.ode.*; import org.generalrelativity.foam.util.*; import org.generalrelativity.foam.dynamics.enum.*; import org.generalrelativity.foam.dynamics.collision.enum.*; public class SimpleParticle implements IODE, ISimulatable { protected var _inverseMass:Number; protected var _state:Array; protected var _generators:Array; protected var _mass:Number; protected var _elasticity:Number; protected var _friction:Number; protected var _tag:Number; protected var _force:Vector; public function SimpleParticle(_arg1:Number, _arg2:Number, _arg3:Number=0, _arg4:Number=0, _arg5:Number=100, _arg6:Number=0.2, _arg7:Number=0.25, _arg8:uint=4){ _state = new Array(_arg8); _generators = new Array(); this.x = _arg1; this.y = _arg2; this.vx = _arg3; this.vy = _arg4; this.mass = _arg5; this.friction = _arg6; this.elasticity = _arg7; clearForces(); } public function set friction(_arg1:Number):void{ _friction = MathUtil.clamp(0, 1, _arg1); } public function set vx(_arg1:Number):void{ _state[2] = _arg1; } public function set vy(_arg1:Number):void{ _state[3] = _arg1; } public function get friction():Number{ return (_friction); } public function set y(_arg1:Number):void{ _state[1] = _arg1; } public function set elasticity(_arg1:Number):void{ _elasticity = MathUtil.clamp(0, 1, _arg1); } public function clearForces():void{ _force = new Vector(); } public function get state():Array{ return (_state); } public function get tag():Number{ return (_tag); } public function get collisionTypeID():String{ return (CollisionType.ABSTRACT_PARTICLE); } public function addForceGenerator(_arg1:IForceGenerator):void{ if (_generators.indexOf(_arg1) == -1){ _generators.push(_arg1); }; } public function set tag(_arg1:Number):void{ _tag = _arg1; } public function get elasticity():Number{ return (_elasticity); } public function get position():Vector{ return (new Vector(x, y)); } public function get vx():Number{ return (_state[2]); } public function get vy():Number{ return (_state[3]); } public function get inverseMass():Number{ return (_inverseMass); } public function addForce(_arg1:Vector):void{ _force.plusEquals(_arg1); } public function removeForceGenerator(_arg1:IForceGenerator):void{ var _local2:int; _local2 = _generators.indexOf(_arg1); if (_local2 > -1){ _generators.splice(_generators.indexOf(_arg1), 1); }; } public function get velocity():Vector{ return (new Vector(vx, vy)); } public function set mass(_arg1:Number):void{ _mass = _arg1; if (_mass == Simplification.INFINITE_MASS){ _inverseMass = 0; } else { _inverseMass = (1 / _arg1); }; } public function accumulateForces():void{ var _local1:IForceGenerator; for each (_local1 in _generators) { _local1.generate(this); }; } public function get force():Vector{ return (_force); } public function get mass():Number{ return (_mass); } public function set x(_arg1:Number):void{ _state[0] = _arg1; } public function get x():Number{ return (_state[0]); } public function get y():Number{ return (_state[1]); } public function getDerivative(_arg1:Array, _arg2:Array):void{ this._state = _arg1; accumulateForces(); _arg2[0] = _arg1[2]; _arg2[1] = _arg1[3]; _arg2[2] = (_force.x * inverseMass); _arg2[3] = (_force.y * inverseMass); clearForces(); } } }//package org.generalrelativity.foam.dynamics.element.particle
Section 34
//IBody (org.generalrelativity.foam.dynamics.element.IBody) package org.generalrelativity.foam.dynamics.element { import org.generalrelativity.foam.math.*; public interface IBody extends ISimulatable { function get vertices():Array; function get I():Number; function getVelocityAtPoint(_arg1:Vector):Vector; function addTorque(_arg1:Number):void; function set av(_arg1:Number):void; function get inverseI():Number; function set q(_arg1:Number):void; function get edges():Array; function get q():Number; function addForceAtPoint(_arg1:Vector, _arg2:Vector):void; function get av():Number; function clearTorque():void; function get rotation():RotationMatrix; } }//package org.generalrelativity.foam.dynamics.element
Section 35
//ISimulatable (org.generalrelativity.foam.dynamics.element.ISimulatable) package org.generalrelativity.foam.dynamics.element { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.force.*; public interface ISimulatable { function get y():Number; function get vx():Number; function get vy():Number; function set vx(_arg1:Number):void; function set vy(_arg1:Number):void; function addForce(_arg1:Vector):void; function get inverseMass():Number; function removeForceGenerator(_arg1:IForceGenerator):void; function set y(_arg1:Number):void; function clearForces():void; function set tag(_arg1:Number):void; function get tag():Number; function get velocity():Vector; function get collisionTypeID():String; function set mass(_arg1:Number):void; function addForceGenerator(_arg1:IForceGenerator):void; function accumulateForces():void; function get force():Vector; function set x(_arg1:Number):void; function set elasticity(_arg1:Number):void; function get mass():Number; function get position():Vector; function get elasticity():Number; function get friction():Number; function set friction(_arg1:Number):void; function get x():Number; } }//package org.generalrelativity.foam.dynamics.element
Section 36
//Simplification (org.generalrelativity.foam.dynamics.enum.Simplification) package org.generalrelativity.foam.dynamics.enum { public class Simplification { public static const INFINITE_MASS:Number = INF; } }//package org.generalrelativity.foam.dynamics.enum
Section 37
//Bungee (org.generalrelativity.foam.dynamics.force.spring.Bungee) package org.generalrelativity.foam.dynamics.force.spring { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.element.*; public class Bungee extends Spring { public function Bungee(_arg1:ISimulatable, _arg2:ISimulatable, _arg3:Number=0.01, _arg4:Number=0.4){ super(_arg1, _arg2, _arg3, _arg4); } override public function generate(_arg1:ISimulatable):void{ var _local2:Vector; var _local3:Number; _local2 = new Vector((element1.x - element2.x), (element1.y - element2.y)); _local3 = _local2.magnitude; if (_local3 <= _restLength){ return; }; _force = _local2.times((-(k) * (_local3 - _restLength))); _force.minusEquals(new Vector(element1.vx, element1.vy).times(damp)); element1.addForce(_force); } } }//package org.generalrelativity.foam.dynamics.force.spring
Section 38
//MouseSpring (org.generalrelativity.foam.dynamics.force.spring.MouseSpring) package org.generalrelativity.foam.dynamics.force.spring { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.force.*; import flash.display.*; import org.generalrelativity.foam.dynamics.element.*; public class MouseSpring extends SimpleForceGenerator implements IForceGenerator { protected var body:IBody; protected var displayObject:DisplayObject; protected var k:Number; protected var damp:Number; protected var point:Vector; protected var restLength:Number; public function MouseSpring(_arg1:IBody, _arg2:Vector, _arg3:DisplayObject){ this.body = _arg1; this.point = _arg1.rotation.getTransposeVectorProduct(_arg2); this.displayObject = _arg3; restLength = 40; k = 0.001; damp = 0.3; _arg1.addForceGenerator(this); } public function getPointInWorldSpace():Vector{ var _local1:RotationMatrix; var _local2:Vector; _local1 = body.rotation; _local2 = _local1.getVectorProduct(point); return (_local2.plus(body.position)); } public function destroy():void{ body.removeForceGenerator(this); } override public function generate(_arg1:ISimulatable):void{ var _local2:RotationMatrix; var _local3:Vector; var _local4:Vector; var _local5:Vector; _local2 = body.rotation; _local3 = _local2.getVectorProduct(point); _local4 = getPointInWorldSpace(); _local5 = new Vector((_local4.x - displayObject.mouseX), (_local4.y - displayObject.mouseY)); if (_local5.magnitude < restLength){ return; }; _force = _local5.times((-(k) * (_local5.magnitude - restLength))); _force.minusEquals(body.velocity.times(damp)); body.addForceAtPoint(_local3, _force); } } }//package org.generalrelativity.foam.dynamics.force.spring
Section 39
//RigidBodyBungee (org.generalrelativity.foam.dynamics.force.spring.RigidBodyBungee) package org.generalrelativity.foam.dynamics.force.spring { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.element.*; public class RigidBodyBungee extends RigidBodySpring { public function RigidBodyBungee(_arg1:IBody, _arg2:Vector, _arg3:IBody, _arg4:Vector, _arg5:Number=0.01, _arg6:Number=0.01){ super(_arg1, _arg2, _arg3, _arg4, _arg5, _arg6); } override public function clone(_arg1:Boolean=true):Spring{ if (_arg1){ return (new RigidBodyBungee(IBody(element2), point2, IBody(element1), point1, k, damp)); }; return (new RigidBodyBungee(IBody(element1), point1, IBody(element2), point2, k, damp)); } override public function generate(_arg1:ISimulatable):void{ var _local2:RotationMatrix; var _local3:Vector; var _local4:Vector; var _local5:RotationMatrix; var _local6:Vector; var _local7:Vector; var _local8:Vector; var _local9:Number; _local2 = IBody(element1).rotation; _local3 = _local2.getVectorProduct(point1); _local4 = _local3.plus(element1.position); _local5 = IBody(element2).rotation; _local6 = _local5.getVectorProduct(point2); _local7 = _local6.plus(element2.position); _local8 = new Vector((_local4.x - _local7.x), (_local4.y - _local7.y)); _local9 = _local8.magnitude; if (_local9 <= _restLength){ return; }; _force = _local8.times((-(k) * (_local8.magnitude - _restLength))); _force.minusEquals(IBody(element1).getVelocityAtPoint(_local3).times(damp)); IBody(element1).addForceAtPoint(_local3, _force); } } }//package org.generalrelativity.foam.dynamics.force.spring
Section 40
//RigidBodySpring (org.generalrelativity.foam.dynamics.force.spring.RigidBodySpring) package org.generalrelativity.foam.dynamics.force.spring { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.element.*; import org.generalrelativity.foam.util.*; public class RigidBodySpring extends Spring { protected var point1:Vector; protected var point2:Vector; public function RigidBodySpring(_arg1:IBody, _arg2:Vector, _arg3:IBody, _arg4:Vector, _arg5:Number=0.01, _arg6:Number=0.01){ var _local7:Vector; var _local8:Vector; super(_arg1, _arg3, _arg5, _arg6); this.point1 = _arg2; this.point2 = _arg4; _local7 = _arg1.rotation.getVectorProduct(_arg2); _local8 = _arg3.rotation.getVectorProduct(_arg4); restLength = MathUtil.distance((_arg1.x + _local7.x), (_arg3.x + _local8.x), (_arg1.y + _local7.y), (_arg3.y + _local8.y)); } override public function getPoint1InWorldSpace():Vector{ var _local1:RotationMatrix; var _local2:Vector; _local1 = IBody(element1).rotation; _local2 = _local1.getVectorProduct(point1); return (_local2.plus(element1.position)); } override public function getPoint2InWorldSpace():Vector{ var _local1:RotationMatrix; var _local2:Vector; _local1 = IBody(element2).rotation; _local2 = _local1.getVectorProduct(point2); return (_local2.plus(element2.position)); } override public function clone(_arg1:Boolean=true):Spring{ if (_arg1){ return (new RigidBodySpring(IBody(element2), point2, IBody(element1), point1, k, damp)); }; return (new RigidBodySpring(IBody(element1), point1, IBody(element2), point2, k, damp)); } override public function generate(_arg1:ISimulatable):void{ var _local2:RotationMatrix; var _local3:Vector; var _local4:Vector; var _local5:RotationMatrix; var _local6:Vector; var _local7:Vector; var _local8:Vector; _local2 = IBody(element1).rotation; _local3 = _local2.getVectorProduct(point1); _local4 = _local3.plus(new Vector(element1.x, element1.y)); _local5 = IBody(element2).rotation; _local6 = _local5.getVectorProduct(point2); _local7 = _local6.plus(new Vector(element2.x, element2.y)); _local8 = new Vector((_local4.x - _local7.x), (_local4.y - _local7.y)); _force = _local8.times((-(k) * (_local8.magnitude - _restLength))); _force.minusEquals(IBody(element1).getVelocityAtPoint(_local3).times(damp)); IBody(element1).addForceAtPoint(_local3, _force); } } }//package org.generalrelativity.foam.dynamics.force.spring
Section 41
//Spring (org.generalrelativity.foam.dynamics.force.spring.Spring) package org.generalrelativity.foam.dynamics.force.spring { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.force.*; import org.generalrelativity.foam.dynamics.element.*; import org.generalrelativity.foam.util.*; public class Spring extends SimpleForceGenerator implements IForceGenerator { protected var damp:Number; protected var element1:ISimulatable; protected var k:Number; protected var element2:ISimulatable; protected var _restLength:Number; public function Spring(_arg1:ISimulatable, _arg2:ISimulatable, _arg3:Number=0.01, _arg4:Number=0.4){ this.element1 = _arg1; this.element2 = _arg2; this.k = _arg3; this.damp = _arg4; _arg1.addForceGenerator(this); restLength = MathUtil.distance(_arg1.x, _arg2.x, _arg1.y, _arg2.y); } public function invert():void{ var _local1:ISimulatable; element1.removeForceGenerator(this); _local1 = ISimulatable(element2); element2 = element1; element1 = _local1; element1.addForceGenerator(this); } public function getPoint1InWorldSpace():Vector{ return (element1.position); } public function getPoint2InWorldSpace():Vector{ return (element2.position); } public function set restLength(_arg1:Number):void{ _restLength = _arg1; } override public function generate(_arg1:ISimulatable):void{ var _local2:Vector; _local2 = new Vector((element1.x - element2.x), (element1.y - element2.y)); _force = _local2.times((-(k) * (_local2.magnitude - _restLength))); _force.minusEquals(new Vector(element1.vx, element1.vy).times(damp)); element1.addForce(_force); } public function clone(_arg1:Boolean=true):Spring{ if (_arg1){ return (new Spring(element2, element1, k, damp)); }; return (new Spring(element1, element2, k, damp)); } public static function createDoubleSidedSpring(_arg1:ISimulatable, _arg2:ISimulatable, _arg3:Number=0.01, _arg4:Number=0.1):void{ var _local5:Spring; _local5 = new Spring(_arg1, _arg2, _arg3, _arg4); _local5 = new Spring(_arg2, _arg1, _arg3, _arg4); } } }//package org.generalrelativity.foam.dynamics.force.spring
Section 42
//Friction (org.generalrelativity.foam.dynamics.force.Friction) package org.generalrelativity.foam.dynamics.force { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.element.*; public class Friction extends SimpleForceGenerator implements IForceGenerator { protected var coefficient:Number; public function Friction(_arg1:Number=0.1){ this.coefficient = _arg1; } override public function generate(_arg1:ISimulatable):void{ var _local2:IBody; _arg1.addForce(new Vector(((-(_arg1.vx) * coefficient) * _arg1.mass), ((-(_arg1.vy) * coefficient) * _arg1.mass))); if ((_arg1 is IBody)){ _local2 = IBody(_arg1); _local2.addTorque(((-(_local2.av) * coefficient) * _local2.I)); }; } } }//package org.generalrelativity.foam.dynamics.force
Section 43
//Gravity (org.generalrelativity.foam.dynamics.force.Gravity) package org.generalrelativity.foam.dynamics.force { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.element.*; public class Gravity extends SimpleForceGenerator implements IForceGenerator { public function Gravity(_arg1:Vector){ super(_arg1); } override public function generate(_arg1:ISimulatable):void{ _arg1.addForce(_force.times(_arg1.mass)); } } }//package org.generalrelativity.foam.dynamics.force
Section 44
//IForceGenerator (org.generalrelativity.foam.dynamics.force.IForceGenerator) package org.generalrelativity.foam.dynamics.force { import org.generalrelativity.foam.dynamics.element.*; public interface IForceGenerator { function generate(_arg1:ISimulatable):void; } }//package org.generalrelativity.foam.dynamics.force
Section 45
//SimpleForceGenerator (org.generalrelativity.foam.dynamics.force.SimpleForceGenerator) package org.generalrelativity.foam.dynamics.force { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.element.*; public class SimpleForceGenerator implements IForceGenerator { protected var _force:Vector; public function SimpleForceGenerator(_arg1:Vector=null):void{ _force = _arg1; } public function generate(_arg1:ISimulatable):void{ _arg1.addForce(_force); } } }//package org.generalrelativity.foam.dynamics.force
Section 46
//AbstractSolver (org.generalrelativity.foam.dynamics.ode.solver.AbstractSolver) package org.generalrelativity.foam.dynamics.ode.solver { import org.generalrelativity.foam.dynamics.ode.*; public class AbstractSolver implements IODESolver { protected var _ode:IODE; public function AbstractSolver(_arg1:IODE):void{ _ode = _arg1; } public function get ode():IODE{ return (_ode); } public function step(_arg1:Number):void{ throw (new Error("AbstractSolver.step must be overridden")); } } }//package org.generalrelativity.foam.dynamics.ode.solver
Section 47
//RK4 (org.generalrelativity.foam.dynamics.ode.solver.RK4) package org.generalrelativity.foam.dynamics.ode.solver { import org.generalrelativity.foam.dynamics.ode.*; public class RK4 extends AbstractSolver implements IODESolver { private var k1:Array; private var k3:Array; private var k4:Array; private var k2:Array; public function RK4(_arg1:IODE){ var ode = _arg1; super(ode); try { k1 = new Array(ode.state.length); k2 = new Array(ode.state.length); k3 = new Array(ode.state.length); k4 = new Array(ode.state.length); } catch(error:Error) { k1 = new Array(); k2 = new Array(); k3 = new Array(); k4 = new Array(); }; } override public function step(_arg1:Number):void{ var _local2:Array; var _local3:Array; var _local4:int; _local2 = new Array(_ode.state.length); _local3 = _ode.state; _local4 = -1; _ode.getDerivative(_local3, k1); while (++_local4 < _local3.length) { _local2[_local4] = (_local3[_local4] + ((k1[_local4] * _arg1) * 0.5)); }; _local4 = -1; _ode.getDerivative(_local2, k2); while (++_local4 < _local3.length) { _local2[_local4] = (_local3[_local4] + ((k2[_local4] * _arg1) * 0.5)); }; _local4 = -1; _ode.getDerivative(_local2, k3); while (++_local4 < _local3.length) { _local2[_local4] = (_local3[_local4] + (k3[_local4] * _arg1)); }; _local4 = -1; _ode.getDerivative(_local2, k4); while (++_local4 < _local3.length) { _local3[_local4] = (_local3[_local4] + ((_arg1 * (((k1[_local4] + (2 * k2[_local4])) + (2 * k3[_local4])) + k4[_local4])) / 6)); }; } } }//package org.generalrelativity.foam.dynamics.ode.solver
Section 48
//IODE (org.generalrelativity.foam.dynamics.ode.IODE) package org.generalrelativity.foam.dynamics.ode { public interface IODE { function get state():Array; function getDerivative(_arg1:Array, _arg2:Array):void; } }//package org.generalrelativity.foam.dynamics.ode
Section 49
//IODESolver (org.generalrelativity.foam.dynamics.ode.IODESolver) package org.generalrelativity.foam.dynamics.ode { public interface IODESolver { function get ode():IODE; function step(_arg1:Number):void; } }//package org.generalrelativity.foam.dynamics.ode
Section 50
//PhysicsEngine (org.generalrelativity.foam.dynamics.PhysicsEngine) package org.generalrelativity.foam.dynamics { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.element.*; import org.generalrelativity.foam.dynamics.ode.*; import org.generalrelativity.foam.dynamics.collision.*; import org.generalrelativity.foam.dynamics.collision.fine.sat.*; import org.generalrelativity.foam.dynamics.collision.coarse.*; public class PhysicsEngine { private var _solverIterations:int; private var _odeSolvers:Array; private var _coarseDetector:ICoarseCollisionDetector; private var _numODESolvers:int; public static const SOLVER_ITERATIONS:int = 3; public static const DEFAULT_COARSE_COLLISION_DETECTOR:Class = AABRDetector; public function PhysicsEngine(){ _odeSolvers = new Array(); _solverIterations = PhysicsEngine.SOLVER_ITERATIONS; } public function setCoarseCollisionDetector(_arg1:ICoarseCollisionDetector):void{ _coarseDetector = _arg1; } public function addODESolver(_arg1:IODESolver):void{ _odeSolvers.push(_arg1); _numODESolvers = _odeSolvers.length; } public function removeCollidable(_arg1:ISimulatable):void{ _coarseDetector.removeCollidable(_arg1); } public function addCollidable(_arg1:ISimulatable):void{ if (!_coarseDetector){ _coarseDetector = new PhysicsEngine.DEFAULT_COARSE_COLLISION_DETECTOR(); }; _coarseDetector.addCollidable(_arg1); } public function step(_arg1:Number=1):void{ var _local2:int; var _local3:int; var _local4:Number; _local3 = 0; _local4 = (_arg1 / _solverIterations); while (++_local3 <= _solverIterations) { _local2 = _numODESolvers; while (--_local2 > -1) { IODESolver(_odeSolvers[_local2]).step(_local4); }; if (_coarseDetector){ resolveCollisions(); }; }; } private function resolveCollisions():void{ var _local1:Array; var _local2:IFineCollisionDetector; _local1 = _coarseDetector.getCandidates(); for each (_local2 in _local1) { if (_local2.hasCollision()){ CollisionResolver.resolve(_local2.getContacts()); }; }; } public function set solverIterations(_arg1:int):void{ _solverIterations = Math.max(Math.abs(_arg1), 1); } public function setCollisionFactory(_arg1:ICollisionFactory):void{ _coarseDetector.factory = _arg1; } public function getBodyUnderPoint(_arg1:Vector):IBody{ var _local2:PointPolygonDetector; var _local3:IODESolver; for each (_local3 in _odeSolvers) { if ((_local3.ode is IBody)){ _local2 = new PointPolygonDetector(IBody(_local3.ode), _arg1); if (_local2.hasCollision()){ return (IBody(_local3.ode)); }; }; }; return (null); } public function removeODESolver(_arg1:IODESolver):void{ var _local2:int; _local2 = _odeSolvers.indexOf(_arg1); if (_local2 > -1){ _odeSolvers.splice(_odeSolvers.indexOf(_arg1), 1); }; _numODESolvers = _odeSolvers.length; } } }//package org.generalrelativity.foam.dynamics
Section 51
//RotationMatrix (org.generalrelativity.foam.math.RotationMatrix) package org.generalrelativity.foam.math { public class RotationMatrix { protected var r21:Number; protected var r11:Number; protected var r12:Number; protected var r22:Number; protected var _theta:Number; public function RotationMatrix(_arg1:Number=0){ this.theta = _arg1; } public function get theta():Number{ return (_theta); } public function getTransposeVectorProduct(_arg1:Vector):Vector{ return (new Vector(((r11 * _arg1.x) + (r21 * _arg1.y)), ((r12 * _arg1.x) + (r22 * _arg1.y)))); } public function getVectorProduct(_arg1:Vector):Vector{ return (new Vector(((r11 * _arg1.x) + (r12 * _arg1.y)), ((r21 * _arg1.x) + (r22 * _arg1.y)))); } public function set theta(_arg1:Number):void{ _theta = _arg1; r11 = Math.cos(theta); r21 = Math.sin(theta); r12 = -(r21); r22 = r11; } } }//package org.generalrelativity.foam.math
Section 52
//Vector (org.generalrelativity.foam.math.Vector) package org.generalrelativity.foam.math { public class Vector { public var y:Number; public var x:Number; public function Vector(_arg1:Number=0, _arg2:Number=0){ this.x = _arg1; this.y = _arg2; } public function cross(_arg1:Vector):Number{ return (((x * _arg1.y) - (y * _arg1.x))); } public function dividedBy(_arg1:Number):Vector{ return (new Vector((x / _arg1), (y / _arg1))); } public function times(_arg1:Number):Vector{ return (new Vector((x * _arg1), (y * _arg1))); } public function dot(_arg1:Vector):Number{ return (((x * _arg1.x) + (y * _arg1.y))); } public function crossScalar(_arg1:Number):Vector{ return (new Vector((-(_arg1) * y), (_arg1 * x))); } public function normalize():void{ dividedByEquals(magnitude); } public function minusEquals(_arg1:Vector):void{ x = (x - _arg1.x); y = (y - _arg1.y); } public function get magnitude():Number{ return (Math.sqrt(((x * x) + (y * y)))); } public function negate():void{ x = (x * -1); y = (y * -1); } public function plus(_arg1:Vector):Vector{ return (new Vector((x + _arg1.x), (y + _arg1.y))); } public function clone():Vector{ return (new Vector(x, y)); } public function dividedByEquals(_arg1:Number):void{ x = (x / _arg1); y = (y / _arg1); } public function getAngle(_arg1:Vector):Number{ return (Math.atan2((_arg1.y - y), (_arg1.x - x))); } public function timesEquals(_arg1:Number):void{ x = (x * _arg1); y = (y * _arg1); } public function getPerp():Vector{ return (new Vector(-(y), x)); } public function minus(_arg1:Vector):Vector{ return (new Vector((x - _arg1.x), (y - _arg1.y))); } public function plusEquals(_arg1:Vector):void{ x = (x + _arg1.x); y = (y + _arg1.y); } public function getUnit():Vector{ return (dividedBy(magnitude)); } public static function project(_arg1:Number, _arg2:Number):Vector{ return (new Vector((Math.cos(_arg1) * _arg2), (Math.sin(_arg1) * _arg2))); } } }//package org.generalrelativity.foam.math
Section 53
//MathUtil (org.generalrelativity.foam.util.MathUtil) package org.generalrelativity.foam.util { public class MathUtil { public static function clamp(_arg1:Number, _arg2:Number, _arg3:Number):Number{ if (_arg3 < _arg1){ return (_arg1); }; if (_arg3 > _arg2){ return (_arg2); }; return (_arg3); } public static function distance(_arg1:Number, _arg2:Number, _arg3:Number, _arg4:Number):Number{ var _local5:Number; var _local6:Number; _local5 = (_arg1 - _arg2); _local6 = (_arg3 - _arg4); return (Math.sqrt(((_local5 * _local5) + (_local6 * _local6)))); } } }//package org.generalrelativity.foam.util
Section 54
//ShapeUtil (org.generalrelativity.foam.util.ShapeUtil) package org.generalrelativity.foam.util { import org.generalrelativity.foam.math.*; public class ShapeUtil { public static function getEdges(_arg1:Array):Array{ var _local2:Array; var _local3:Vector; var _local4:Vector; var _local5:int; _local2 = new Array(); _local5 = -1; while (++_local5 < _arg1.length) { _local3 = (_arg1[_local5] as Vector); if ((_local5 + 1) == _arg1.length){ _local4 = (_arg1[0] as Vector); } else { _local4 = (_arg1[(_local5 + 1)] as Vector); }; _local2.push(_local3.minus(_local4)); }; return (_local2); } public static function createRectangle(_arg1:Number, _arg2:Number):Array{ return ([new Vector((-(_arg1) / 2), (-(_arg2) / 2)), new Vector((_arg1 / 2), (-(_arg2) / 2)), new Vector((_arg1 / 2), (_arg2 / 2)), new Vector((-(_arg1) / 2), (_arg2 / 2))]); } public static function createSymmetricPolygon(_arg1:int=3, _arg2:Number=50, _arg3:Number=0):Array{ var _local4:Array; var _local5:Number; var _local6:int; _local4 = new Array(); _local5 = (((360 / _arg1) * Math.PI) / 180); _local6 = _arg1; while (_local6--) { _local4.push(new Vector((Math.cos(_arg3) * _arg2), (Math.sin(_arg3) * _arg2))); _arg3 = (_arg3 + _local5); }; return (_local4); } } }//package org.generalrelativity.foam.util
Section 55
//SimpleMap (org.generalrelativity.foam.util.SimpleMap) package org.generalrelativity.foam.util { public class SimpleMap { protected var _values:Array; protected var _keys:Array; public function SimpleMap(){ _keys = new Array(); _values = new Array(); } public function remove(_arg1):void{ var _local2:int; _local2 = getKeyIndex(_arg1); if (_local2 > -1){ _keys.splice(_local2, 1); _values.splice(_local2, 1); }; } public function getKey(_arg1){ var _local2:int; _local2 = getValueIndex(_arg1); if (_local2 > -1){ return (_keys[_local2]); }; } public function get length():int{ return (_keys.length); } public function put(_arg1, _arg2):void{ var _local3:int; _local3 = getKeyIndex(_arg1); if (_local3 > -1){ _values[_local3] = _arg2; } else { _keys.push(_arg1); _values.push(_arg2); }; } public function getKeyIndex(_arg1):int{ return (_keys.indexOf(_arg1)); } public function get values():Array{ return (_values.slice()); } public function has(_arg1):Boolean{ return ((getKeyIndex(_arg1) > -1)); } public function get keys():Array{ return (_keys.slice()); } public function getValueIndex(_arg1):int{ return (_values.indexOf(_arg1)); } public function getValue(_arg1){ var _local2:int; _local2 = getKeyIndex(_arg1); if (_local2 > -1){ return (_values[_local2]); }; } } }//package org.generalrelativity.foam.util
Section 56
//DisplayObjectData (org.generalrelativity.foam.view.DisplayObjectData) package org.generalrelativity.foam.view { import flash.display.*; public dynamic class DisplayObjectData { protected var _displayObject:DisplayObject; public var autoCenter:Boolean; public var offsetX:Number; public var offsetY:Number; public var hasBeenDisplayed:Boolean; public function DisplayObjectData(_arg1, _arg2:Number=0, _arg3:Number=0, _arg4:Boolean=true){ this.displayObject = _arg1; this.offsetX = _arg2; this.offsetY = _arg3; this.autoCenter = _arg4; } public function set displayObject(_arg1):void{ if ((_arg1 is DisplayObject)){ _displayObject = _arg1; } else { if ((_arg1 is Class)){ _displayObject = new (_arg1); } else { throw (new ArgumentError("DisplayObjectData.displayObject must be a DisplayObject or DisplayObject Class")); }; }; } public function get displayObject():DisplayObject{ return (_displayObject); } } }//package org.generalrelativity.foam.view
Section 57
//DisplayObjectFoamRenderer (org.generalrelativity.foam.view.DisplayObjectFoamRenderer) package org.generalrelativity.foam.view { import flash.display.*; import org.generalrelativity.foam.dynamics.element.*; import org.generalrelativity.foam.util.*; public class DisplayObjectFoamRenderer extends SimpleFoamRenderer implements IFoamRenderer { protected var _containerMap:SimpleMap; public function DisplayObjectFoamRenderer(){ _containerMap = new SimpleMap(); } override public function draw():void{ var _local1:DisplayObject; var _local2:Renderable; staticCanvas.graphics.clear(); currentCanvas = staticCanvas; for each (_local2 in _staticRenderables) { if (_containerMap.has(_local2)){ _local1 = (_containerMap.getValue(_local2) as DisplayObject); if ((_local2.element is ISimulatable)){ _local1.x = ISimulatable(_local2.element).x; _local1.y = ISimulatable(_local2.element).y; if ((_local2.element is IBody)){ _local1.rotation = ((IBody(_local2.element).q * 180) / Math.PI); }; }; } else { proxy(_local2, 0, null); }; }; } override public function addRenderable(_arg1:Renderable):void{ var _local2:Sprite; var _local3:DisplayObject; if (_arg1.data.displayObject){ _local2 = (addChild(new Sprite()) as Sprite); _local3 = _local2.addChild(_arg1.data.displayObject); if (!_arg1.data.hasBeenDisplayed){ if (_arg1.data.offsetX){ _local3.x = (_local3.x + _arg1.data.offsetX); }; if (_arg1.data.offsetY){ _local3.y = (_local3.y + _arg1.data.offsetY); }; if (_arg1.data.autoCenter){ _local3.x = (_local3.x - (_local3.width / 2)); _local3.y = (_local3.y - (_local3.height / 2)); }; _arg1.data.hasBeenDisplayed = true; }; _containerMap.put(_arg1, _local2); }; super.addRenderable(_arg1); draw(); redraw(); } override public function removeRenderable(_arg1:Renderable):void{ var _local2:Sprite; if (_containerMap.has(_arg1)){ _local2 = (_containerMap.getValue(_arg1) as Sprite); removeChild(_local2); }; super.removeRenderable(_arg1); } override public function getDisplayObject(_arg1:Renderable):DisplayObject{ return (this); } override public function redraw():void{ var _local1:DisplayObject; var _local2:Renderable; auxillaryCanvas.graphics.clear(); dynamicCanvas.graphics.clear(); currentCanvas = dynamicCanvas; for each (_local2 in _dynamicRenderables) { if (_containerMap.has(_local2)){ _local1 = (_containerMap.getValue(_local2) as DisplayObject); if ((_local2.element is ISimulatable)){ _local1.x = ISimulatable(_local2.element).x; _local1.y = ISimulatable(_local2.element).y; if ((_local2.element is IBody)){ _local1.rotation = ((IBody(_local2.element).q * 180) / Math.PI); }; }; } else { proxy(_local2, 0, null); }; }; } } }//package org.generalrelativity.foam.view
Section 58
//IFoamRenderer (org.generalrelativity.foam.view.IFoamRenderer) package org.generalrelativity.foam.view { import flash.display.*; public interface IFoamRenderer { function addRenderable(_arg1:Renderable):void; function draw():void; function removeRenderable(_arg1:Renderable):void; function copy(_arg1:IFoamRenderer):void; function get renderables():Array; function getDisplayObject(_arg1:Renderable):DisplayObject; function redraw():void; } }//package org.generalrelativity.foam.view
Section 59
//Renderable (org.generalrelativity.foam.view.Renderable) package org.generalrelativity.foam.view { import flash.utils.*; public class Renderable { public var renderMethodKey:Class; public var data; public var isDynamic:Boolean; public var element; public function Renderable(_arg1, _arg2:Boolean=true, _arg3=null){ this.element = _arg1; this.isDynamic = _arg2; if (_arg3){ this.data = _arg3; } else { this.data = new Object(); }; this.renderMethodKey = (getDefinitionByName(getQualifiedClassName(_arg1)) as Class); } } }//package org.generalrelativity.foam.view
Section 60
//SimpleFoamRenderer (org.generalrelativity.foam.view.SimpleFoamRenderer) package org.generalrelativity.foam.view { import org.generalrelativity.foam.math.*; import flash.display.*; import org.generalrelativity.foam.dynamics.element.body.*; import org.generalrelativity.foam.dynamics.force.spring.*; public class SimpleFoamRenderer extends Sprite implements IFoamRenderer { protected var auxillaryCanvas:Sprite; protected var currentCanvas:Sprite; protected var _dynamicRenderables:Array; protected var staticCanvas:Sprite; protected var dynamicCanvas:Sprite; protected var _staticRenderables:Array; public function SimpleFoamRenderer(){ staticCanvas = (addChild(new Sprite()) as Sprite); dynamicCanvas = (addChild(new Sprite()) as Sprite); auxillaryCanvas = (addChild(new Sprite()) as Sprite); _staticRenderables = new Array(); _dynamicRenderables = new Array(); } protected function drawMouseSpring(_arg1:MouseSpring):void{ var _local2:Vector; currentCanvas.graphics.lineStyle(2, 0xFF0000); _local2 = _arg1.getPointInWorldSpace(); currentCanvas.graphics.moveTo(_local2.x, _local2.y); currentCanvas.graphics.lineTo(mouseX, mouseY); } protected function drawCircle(_arg1:Circle, _arg2:uint=0xFFFFFF):void{ currentCanvas.graphics.lineStyle(3, 0); currentCanvas.graphics.drawCircle(_arg1.x, _arg1.y, _arg1.radius); } public function draw():void{ currentCanvas = staticCanvas; currentCanvas.graphics.clear(); _staticRenderables.forEach(proxy); redraw(); } protected function drawPolygon(_arg1:RigidBody, _arg2:uint=0xFFFFFF):void{ var _local3:RotationMatrix; var _local4:Vector; var _local5:Vector; var _local6:int; currentCanvas.graphics.lineStyle(3, 0); _local3 = _arg1.rotation; _local4 = _local3.getVectorProduct((_arg1.vertices[0] as Vector)); _local5 = _local4; currentCanvas.graphics.moveTo((_arg1.x + _local5.x), (_arg1.y + _local5.y)); _local6 = 0; while (++_local6 < _arg1.vertices.length) { _local4 = _local3.getVectorProduct((_arg1.vertices[_local6] as Vector)); currentCanvas.graphics.lineTo((_arg1.x + _local4.x), (_arg1.y + _local4.y)); }; currentCanvas.graphics.lineTo((_arg1.x + _local5.x), (_arg1.y + _local5.y)); } protected function proxy(_arg1:Renderable, _arg2:int, _arg3:Array):void{ switch (_arg1.renderMethodKey){ case Circle: drawCircle(Circle(_arg1.element)); break; case RigidBody: drawPolygon(RigidBody(_arg1.element)); break; case Spring: currentCanvas = auxillaryCanvas; drawSpring(Spring(_arg1.element)); currentCanvas = dynamicCanvas; break; case Bungee: currentCanvas = auxillaryCanvas; drawSpring(Spring(_arg1.element)); currentCanvas = dynamicCanvas; break; case RigidBodySpring: currentCanvas = auxillaryCanvas; drawSpring(Spring(_arg1.element)); currentCanvas = dynamicCanvas; break; case RigidBodyBungee: currentCanvas = auxillaryCanvas; drawSpring(Spring(_arg1.element)); currentCanvas = dynamicCanvas; break; case MouseSpring: currentCanvas = auxillaryCanvas; drawMouseSpring(MouseSpring(_arg1.element)); currentCanvas = dynamicCanvas; break; }; } public function addRenderable(_arg1:Renderable):void{ if (_arg1.isDynamic){ _dynamicRenderables.push(_arg1); } else { _staticRenderables.push(_arg1); }; } public function copy(_arg1:IFoamRenderer):void{ var _local2:Array; var _local3:Renderable; _local2 = renderables; for each (_local3 in _local2) { _arg1.addRenderable(_local3); }; } public function get renderables():Array{ return (_staticRenderables.concat(_dynamicRenderables)); } public function removeRenderable(_arg1:Renderable):void{ if (!_arg1.isDynamic){ _staticRenderables.splice(_staticRenderables.indexOf(_arg1), 1); } else { _dynamicRenderables.splice(_dynamicRenderables.indexOf(_arg1), 1); }; } protected function drawSpring(_arg1:Spring):void{ var _local2:Vector; var _local3:Vector; currentCanvas.graphics.lineStyle(3, 0); _local2 = _arg1.getPoint1InWorldSpace(); _local3 = _arg1.getPoint2InWorldSpace(); currentCanvas.graphics.moveTo(_local2.x, _local2.y); currentCanvas.graphics.lineTo(_local3.x, _local3.y); } public function getDisplayObject(_arg1:Renderable):DisplayObject{ if (_staticRenderables.indexOf(_arg1) != -1){ return (staticCanvas); }; if (_dynamicRenderables.indexOf(_arg1) != -1){ return (dynamicCanvas); }; return (null); } public function redraw():void{ auxillaryCanvas.graphics.clear(); dynamicCanvas.graphics.clear(); currentCanvas = dynamicCanvas; _dynamicRenderables.forEach(proxy); } } }//package org.generalrelativity.foam.view
Section 61
//Foam (org.generalrelativity.foam.Foam) package org.generalrelativity.foam { import org.generalrelativity.foam.math.*; import org.generalrelativity.foam.dynamics.force.*; import flash.display.*; import org.generalrelativity.foam.dynamics.element.*; import org.generalrelativity.foam.view.*; import org.generalrelativity.foam.dynamics.ode.*; import org.generalrelativity.foam.dynamics.collision.*; import org.generalrelativity.foam.dynamics.force.spring.*; import flash.events.*; import org.generalrelativity.foam.dynamics.*; import org.generalrelativity.foam.util.*; import org.generalrelativity.foam.dynamics.enum.*; import org.generalrelativity.foam.dynamics.ode.solver.*; public class Foam extends Sprite { private var _renderer:IFoamRenderer; private var _useMouseDragger:Boolean; private var _globalForceGenerators:Array; private var _callOnAddedToStage:Array; private var _mouseSpring:MouseSpring; private var _renderMap:SimpleMap; private var _engine:PhysicsEngine; private var _timestep:Number; private var _isSimulating:Boolean; private var _defaultSolver:Class; private var _solverMap:SimpleMap; public static const DEFAULT_ODE_SOLVER:Class = RK4; public static const STEP:String = "step"; public function Foam(){ _solverMap = new SimpleMap(); _renderMap = new SimpleMap(); _engine = new PhysicsEngine(); _globalForceGenerators = new Array(); _callOnAddedToStage = new Array(); _defaultSolver = Foam.DEFAULT_ODE_SOLVER; _timestep = 1; addEventListener(Event.ADDED_TO_STAGE, onAddedToStage, false, 0, true); } public function setCollisionFactory(_arg1:ICollisionFactory):void{ _engine.setCollisionFactory(_arg1); } public function addGlobalForceGenerator(_arg1:IForceGenerator, _arg2:Boolean=true):void{ var _local3:ISimulatable; if (_arg2){ for each (_local3 in _solverMap.keys) { _local3.addForceGenerator(_arg1); }; }; _globalForceGenerators.push(_arg1); } public function stop():void{ if (_isSimulating){ _isSimulating = false; removeEventListener(Event.ENTER_FRAME, stepForward); }; } public function get timestep():Number{ return (_timestep); } private function mouseUp(_arg1:MouseEvent):void{ _mouseSpring.destroy(); stopDrawing(_mouseSpring); stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUp); } public function simulate():void{ if (((!(_isSimulating)) && (_solverMap.length))){ _isSimulating = true; _renderer.draw(); addEventListener(Event.ENTER_FRAME, stepForward, false, 0, true); }; } public function set timestep(_arg1:Number):void{ _timestep = _arg1; } public function setRenderer(_arg1:IFoamRenderer):void{ if (_renderer){ _renderer.copy(_arg1); removeChild(DisplayObject(_renderer)); }; _renderer = _arg1; addChild(DisplayObject(_renderer)); } public function addElement(_arg1:ISimulatable, _arg2:Boolean=true, _arg3:Boolean=true, _arg4=null, _arg5:IODESolver=null):void{ var _local6:IForceGenerator; if (((!((_arg1.mass == Simplification.INFINITE_MASS))) && ((_arg1 is IODE)))){ if (!_arg5){ _arg5 = new _defaultSolver(_arg1); }; _solverMap.put(_arg1, _arg5); _engine.addODESolver(_arg5); for each (_local6 in _globalForceGenerators) { _arg1.addForceGenerator(_local6); }; }; if (_arg2){ _engine.addCollidable(_arg1); }; if (_arg3){ if (!_renderer){ _renderer = new SimpleFoamRenderer(); addChild(DisplayObject(_renderer)); }; addRenderable(new Renderable(_arg1, !((_arg1.mass == Simplification.INFINITE_MASS)), _arg4)); }; } public function get engine():PhysicsEngine{ return (_engine); } public function useMouseDragger(_arg1:Boolean):void{ if (!stage){ if (_callOnAddedToStage.indexOf(useMouseDragger) == -1){ _callOnAddedToStage.push(useMouseDragger, [_arg1]); }; return; }; if (_useMouseDragger != _arg1){ _useMouseDragger = _arg1; if (_useMouseDragger){ stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown, false, 0, true); } else { stage.removeEventListener(MouseEvent.MOUSE_DOWN, mouseDown); }; }; } public function setCoarseCollisionDetector(_arg1:ICoarseCollisionDetector):void{ _engine.setCoarseCollisionDetector(_arg1); } public function set defaultSolver(_arg1:Class):void{ _defaultSolver = _arg1; } public function removeGlobalForceGenerator(_arg1:IForceGenerator, _arg2:Boolean=false):void{ var _local3:int; var _local4:ISimulatable; _local3 = _globalForceGenerators.indexOf(_arg1); if (_local3 > -1){ if (!_arg2){ for each (_local4 in _solverMap.keys) { _local4.removeForceGenerator(_arg1); }; }; _globalForceGenerators.splice(_globalForceGenerators.indexOf(_arg1), 1); }; } public function set solverIterations(_arg1:int):void{ _engine.solverIterations = _arg1; } public function stepForward(_arg1:Event=null):void{ _engine.step(_timestep); _renderer.redraw(); dispatchEvent(new Event(Foam.STEP)); } public function stopSimulating(_arg1:ISimulatable):void{ if (_solverMap.has(_arg1)){ _engine.removeODESolver(IODESolver(_solverMap.getValue(_arg1))); _solverMap.remove(_arg1); stopColliding(_arg1); }; if (!_solverMap.keys.length){ stop(); }; } public function get simulatables():Array{ return (_solverMap.keys); } public function stopColliding(_arg1:ISimulatable):void{ _engine.removeCollidable(_arg1); } private function onAddedToStage(_arg1:Event):void{ var _local2:Array; var _local3:Function; while (_callOnAddedToStage.length) { _local2 = _callOnAddedToStage.pop(); _local3 = _callOnAddedToStage.pop(); _local3.apply(this, _local2); }; } public function addRenderable(_arg1:Renderable):void{ _renderMap.put(_arg1.element, _arg1); _renderer.addRenderable(_arg1); } public function stopDrawing(_arg1):void{ if (_renderMap.has(_arg1)){ _renderer.removeRenderable(Renderable(_renderMap.getValue(_arg1))); _renderMap.remove(_arg1); if (_isSimulating){ _renderer.draw(); }; }; } public function stepBackward(_arg1:Event=null):void{ _engine.step(-(_timestep)); _renderer.redraw(); dispatchEvent(new Event(Foam.STEP)); } private function mouseDown(_arg1:MouseEvent):void{ var _local2:Vector; var _local3:IBody; var _local4:ISimulatable; _local2 = new Vector(mouseX, mouseY); _local3 = _engine.getBodyUnderPoint(_local2); _local4 = _engine.getBodyUnderPoint(_local2); if (((((_local3) && (_arg1.shiftKey))) && ((_local4.tag == 2)))){ removeElement(_local4); }; } public function removeElement(_arg1:ISimulatable):void{ stopDrawing(_arg1); stopSimulating(_arg1); } } }//package org.generalrelativity.foam
Section 62
//doodle_26 (Sketchit_fla.doodle_26) package Sketchit_fla { import flash.display.*; public dynamic class doodle_26 extends MovieClip { public function doodle_26(){ addFrameScript(9, frame10); } function frame10(){ stop(); } } }//package Sketchit_fla
Section 63
//doodle2_27 (Sketchit_fla.doodle2_27) package Sketchit_fla { import flash.display.*; public dynamic class doodle2_27 extends MovieClip { public function doodle2_27(){ addFrameScript(9, frame10); } function frame10(){ stop(); } } }//package Sketchit_fla
Section 64
//loader_5 (Sketchit_fla.loader_5) package Sketchit_fla { import flash.display.*; public dynamic class loader_5 extends MovieClip { public function loader_5(){ addFrameScript(0, frame1); } function frame1(){ stop(); } } }//package Sketchit_fla
Section 65
//MainTimeline (Sketchit_fla.MainTimeline) package Sketchit_fla { import flash.display.*; import flash.events.*; import flash.utils.*; import classes.*; import flash.geom.*; import adobe.utils.*; import flash.accessibility.*; import flash.errors.*; import flash.external.*; import flash.filters.*; import flash.media.*; import flash.net.*; import flash.printing.*; import flash.system.*; import flash.text.*; import flash.ui.*; import flash.xml.*; public dynamic class MainTimeline extends MovieClip { public var nbLevel:Number; public var btn_playmoregames:SimpleButton; public var bgClip:MovieClip; public var btn_play:SimpleButton; public var preloader:MovieClip; public var Utils:utils; public var bgClip2:MovieClip; public var btn_backtomenu:SimpleButton; public function MainTimeline(){ addFrameScript(0, frame1, 1, frame2, 32, frame33, 212, frame213, 213, frame214, 214, frame215); } public function btn_backtomenu_CLICK(_arg1:MouseEvent):void{ Utils.BitmapTransition(); btn_backtomenu.removeEventListener(MouseEvent.ROLL_OUT, btn_ROLL_OUT); gotoAndStop("MENU"); } public function btn_ROLL_OVER(_arg1:MouseEvent):void{ bgClip.gotoAndStop(1); bgClip.x = _arg1.target.x; bgClip.y = _arg1.target.y; bgClip.play(); } public function preloading(_arg1:Event):void{ preloader.Mask.scaleX = (this.loaderInfo.bytesLoaded / this.loaderInfo.bytesTotal); if (this.loaderInfo.bytesLoaded == this.loaderInfo.bytesTotal){ Utils.BitmapTransition(); stage.frameRate = 40; gotoAndPlay(2); this.removeEventListener(Event.ENTER_FRAME, preloading); }; } function frame215(){ stop(); Mouse.show(); bgClip.gotoAndStop(1); bgClip2.gotoAndStop(10); btn_backtomenu.addEventListener(MouseEvent.ROLL_OVER, btn_ROLL_OVER, false, 0, true); btn_backtomenu.addEventListener(MouseEvent.ROLL_OUT, btn_ROLL_OUT, false, 0, true); btn_backtomenu.addEventListener(MouseEvent.CLICK, btn_backtomenu_CLICK, false, 0, true); btn_playmoregames.addEventListener(MouseEvent.ROLL_OVER, btn_ROLL_OVER, false, 0, true); btn_playmoregames.addEventListener(MouseEvent.ROLL_OUT, btn_ROLL_OUT, false, 0, true); btn_playmoregames.addEventListener(MouseEvent.CLICK, btn_playmoregames_CLICK, false, 0, true); } function frame214(){ stop(); Mouse.hide(); Utils.render(); } function frame213(){ stop(); stage.frameRate = 40; Mouse.show(); bgClip.gotoAndStop(1); bgClip2.gotoAndStop(10); btn_play.addEventListener(MouseEvent.CLICK, btn_play_CLICK, false, 0, true); btn_play.addEventListener(MouseEvent.ROLL_OVER, btn_ROLL_OVER, false, 0, true); btn_play.addEventListener(MouseEvent.ROLL_OUT, btn_ROLL_OUT, false, 0, true); btn_playmoregames.addEventListener(MouseEvent.ROLL_OVER, btn_ROLL_OVER, false, 0, true); btn_playmoregames.addEventListener(MouseEvent.ROLL_OUT, btn_ROLL_OUT, false, 0, true); btn_playmoregames.addEventListener(MouseEvent.CLICK, btn_playmoregames_CLICK, false, 0, true); } function frame1(){ stop(); stage.scaleMode = StageScaleMode.NO_SCALE; stage.frameRate = 100; nbLevel = 1; Utils = new utils(this); addChild(Utils); this.addEventListener(Event.ENTER_FRAME, preloading, false, 0, true); } function frame2(){ } public function btn_play_CLICK(_arg1:MouseEvent):void{ nbLevel = 1; Utils.BitmapTransition(); btn_play.removeEventListener(MouseEvent.ROLL_OUT, btn_ROLL_OUT); gotoAndStop("GAME"); } function frame33(){ stage.frameRate = 30; preloader.addEventListener(MouseEvent.CLICK, btn_playmoregames_CLICK, false, 0, true); preloader.buttonMode = true; preloader.useHandCursor = true; } public function btn_playmoregames_CLICK(_arg1:MouseEvent):void{ var _local2:URLRequest; _local2 = new URLRequest("http://www.neenja.com/"); navigateToURL(_local2); } public function btn_ROLL_OUT(_arg1:MouseEvent):void{ bgClip.gotoAndStop(1); bgClip2.gotoAndStop(1); bgClip2.x = _arg1.target.x; bgClip2.y = _arg1.target.y; bgClip2.play(); } } }//package Sketchit_fla
Section 66
//preloader_frame_2 (Sketchit_fla.preloader_frame_2) package Sketchit_fla { import flash.display.*; public dynamic class preloader_frame_2 extends MovieClip { public var Mask:MovieClip; } }//package Sketchit_fla
Section 67
//ball (ball) package { import flash.display.*; public dynamic class ball extends MovieClip { } }//package
Section 68
//Circle1 (Circle1) package { import flash.display.*; public dynamic class Circle1 extends MovieClip { } }//package
Section 69
//Level10MC (Level10MC) package { import flash.display.*; public dynamic class Level10MC extends MovieClip { } }//package
Section 70
//Level1MC (Level1MC) package { import flash.display.*; public dynamic class Level1MC extends MovieClip { } }//package
Section 71
//Level2MC (Level2MC) package { import flash.display.*; public dynamic class Level2MC extends MovieClip { } }//package
Section 72
//Level3MC (Level3MC) package { import flash.display.*; public dynamic class Level3MC extends MovieClip { } }//package
Section 73
//Level4MC (Level4MC) package { import flash.display.*; public dynamic class Level4MC extends MovieClip { } }//package
Section 74
//Level5MC (Level5MC) package { import flash.display.*; public dynamic class Level5MC extends MovieClip { } }//package
Section 75
//Level6MC (Level6MC) package { import flash.display.*; public dynamic class Level6MC extends MovieClip { } }//package
Section 76
//Level8MC (Level8MC) package { import flash.display.*; public dynamic class Level8MC extends MovieClip { } }//package
Section 77
//Level9MC (Level9MC) package { import flash.display.*; public dynamic class Level9MC extends MovieClip { } }//package
Section 78
//markerMC (markerMC) package { import flash.display.*; public dynamic class markerMC extends MovieClip { } }//package
Section 79
//paperBG (paperBG) package { import flash.display.*; public dynamic class paperBG extends MovieClip { } }//package
Section 80
//Rectangle1 (Rectangle1) package { import flash.display.*; public dynamic class Rectangle1 extends MovieClip { } }//package
Section 81
//Rectangle2 (Rectangle2) package { import flash.display.*; public dynamic class Rectangle2 extends MovieClip { } }//package
Section 82
//Rectangle3 (Rectangle3) package { import flash.display.*; public dynamic class Rectangle3 extends MovieClip { } }//package
Section 83
//Rectangle4 (Rectangle4) package { import flash.display.*; public dynamic class Rectangle4 extends MovieClip { } }//package
Section 84
//star (star) package { import flash.display.*; public dynamic class star extends MovieClip { } }//package

Library Items

Symbol 1 BitmapUsed by:2
Symbol 2 GraphicUses:1Used by:3  Timeline
Symbol 3 MovieClip {paperBG}Uses:2
Symbol 4 BitmapUsed by:5
Symbol 5 GraphicUses:4Used by:6
Symbol 6 MovieClipUses:5Used by:Timeline
Symbol 7 FontUsed by:8 19 51 103 109 111 114 115 116 117 118
Symbol 8 TextUses:7Used by:Timeline
Symbol 9 GraphicUsed by:10
Symbol 10 MovieClipUses:9Used by:14
Symbol 11 GraphicUsed by:12
Symbol 12 MovieClipUses:11Used by:14
Symbol 13 GraphicUsed by:14
Symbol 14 MovieClip {Sketchit_fla.preloader_frame_2}Uses:10 12 13Used by:Timeline
Symbol 15 GraphicUsed by:53
Symbol 16 GraphicUsed by:17
Symbol 17 MovieClip {Circle1}Uses:16Used by:53
Symbol 18 GraphicUsed by:21
Symbol 19 TextUses:7Used by:21
Symbol 20 GraphicUsed by:21
Symbol 21 MovieClip {Level1MC}Uses:18 19 20Used by:53
Symbol 22 GraphicUsed by:23
Symbol 23 MovieClip {Level2MC}Uses:22Used by:53
Symbol 24 GraphicUsed by:25
Symbol 25 MovieClip {Level3MC}Uses:24Used by:53
Symbol 26 GraphicUsed by:27
Symbol 27 MovieClip {Level4MC}Uses:26Used by:53
Symbol 28 GraphicUsed by:29
Symbol 29 MovieClip {Level5MC}Uses:28Used by:53
Symbol 30 GraphicUsed by:31
Symbol 31 MovieClip {Level6MC}Uses:30Used by:53
Symbol 32 GraphicUsed by:33
Symbol 33 MovieClip {Level8MC}Uses:32Used by:53
Symbol 34 GraphicUsed by:35
Symbol 35 MovieClip {Level9MC}Uses:34Used by:53
Symbol 36 GraphicUsed by:37
Symbol 37 MovieClip {Level10MC}Uses:36Used by:53
Symbol 38 GraphicUsed by:39
Symbol 39 MovieClip {Rectangle1}Uses:38Used by:53
Symbol 40 GraphicUsed by:41
Symbol 41 MovieClip {Rectangle2}Uses:40Used by:53
Symbol 42 GraphicUsed by:43
Symbol 43 MovieClip {Rectangle3}Uses:42Used by:53
Symbol 44 GraphicUsed by:45
Symbol 45 MovieClip {Rectangle4}Uses:44Used by:53
Symbol 46 GraphicUsed by:47
Symbol 47 MovieClip {ball}Uses:46Used by:53
Symbol 48 GraphicUsed by:49
Symbol 49 MovieClip {star}Uses:48Used by:53
Symbol 50 GraphicUsed by:52
Symbol 51 TextUses:7Used by:52
Symbol 52 MovieClip {markerMC}Uses:50 51Used by:53
Symbol 53 MovieClip {Sketchit_fla.loader_5}Uses:15 17 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 52Used by:Timeline
Symbol 54 BitmapUsed by:55
Symbol 55 GraphicUses:54Used by:77 102
Symbol 56 GraphicUsed by:102
Symbol 57 GraphicUsed by:102
Symbol 58 GraphicUsed by:102
Symbol 59 GraphicUsed by:102
Symbol 60 GraphicUsed by:102
Symbol 61 GraphicUsed by:102
Symbol 62 GraphicUsed by:102
Symbol 63 GraphicUsed by:102
Symbol 64 GraphicUsed by:102
Symbol 65 GraphicUsed by:102
Symbol 66 GraphicUsed by:102
Symbol 67 GraphicUsed by:102
Symbol 68 GraphicUsed by:102
Symbol 69 GraphicUsed by:102
Symbol 70 GraphicUsed by:102
Symbol 71 GraphicUsed by:102
Symbol 72 GraphicUsed by:102
Symbol 73 BitmapUsed by:74
Symbol 74 GraphicUses:73Used by:102
Symbol 75 GraphicUsed by:102
Symbol 76 GraphicUsed by:102
Symbol 77 MovieClipUses:55Used by:102
Symbol 78 BitmapUsed by:79
Symbol 79 GraphicUses:78Used by:102
Symbol 80 GraphicUsed by:102
Symbol 81 GraphicUsed by:100
Symbol 82 GraphicUsed by:100
Symbol 83 GraphicUsed by:100
Symbol 84 GraphicUsed by:100
Symbol 85 GraphicUsed by:100
Symbol 86 GraphicUsed by:100
Symbol 87 GraphicUsed by:100
Symbol 88 GraphicUsed by:100
Symbol 89 GraphicUsed by:100
Symbol 90 GraphicUsed by:100
Symbol 91 GraphicUsed by:100
Symbol 92 GraphicUsed by:100
Symbol 93 GraphicUsed by:100
Symbol 94 GraphicUsed by:100
Symbol 95 GraphicUsed by:100
Symbol 96 GraphicUsed by:100
Symbol 97 GraphicUsed by:100
Symbol 98 GraphicUsed by:100
Symbol 99 GraphicUsed by:100
Symbol 100 MovieClipUses:81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99Used by:102
Symbol 101 GraphicUsed by:102
Symbol 102 MovieClipUses:55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 74 75 76 77 79 80 100 101Used by:Timeline
Symbol 103 TextUses:7Used by:Timeline
Symbol 104 GraphicUsed by:106 107
Symbol 105 GraphicUsed by:106 107
Symbol 106 MovieClip {Sketchit_fla.doodle_26}Uses:104 105Used by:Timeline
Symbol 107 MovieClip {Sketchit_fla.doodle2_27}Uses:104 105Used by:Timeline
Symbol 108 GraphicUsed by:110 112 119
Symbol 109 TextUses:7Used by:110
Symbol 110 ButtonUses:108 109Used by:Timeline
Symbol 111 TextUses:7Used by:112
Symbol 112 ButtonUses:108 111Used by:Timeline
Symbol 113 SoundUsed by:Timeline
Symbol 114 TextUses:7Used by:Timeline
Symbol 115 TextUses:7Used by:Timeline
Symbol 116 TextUses:7Used by:Timeline
Symbol 117 TextUses:7Used by:Timeline
Symbol 118 TextUses:7Used by:119
Symbol 119 ButtonUses:108 118Used by:Timeline

Instance Names

"preloader"Frame 1Symbol 14 MovieClip {Sketchit_fla.preloader_frame_2}
"preloader"Frame 33Symbol 102 MovieClip
"bgClip"Frame 213Symbol 106 MovieClip {Sketchit_fla.doodle_26}
"bgClip2"Frame 213Symbol 107 MovieClip {Sketchit_fla.doodle2_27}
"btn_play"Frame 213Symbol 110 Button
"btn_playmoregames"Frame 213Symbol 112 Button
"bgClip"Frame 215Symbol 106 MovieClip {Sketchit_fla.doodle_26}
"bgClip2"Frame 215Symbol 107 MovieClip {Sketchit_fla.doodle2_27}
"btn_backtomenu"Frame 215Symbol 119 Button
"btn_playmoregames"Frame 215Symbol 112 Button
"Mask"Symbol 14 MovieClip {Sketchit_fla.preloader_frame_2} Frame 1Symbol 10 MovieClip

Special Tags

FileAttributes (69)Timeline Frame 1Access network only, Metadata not present, AS3.

Labels

"PRELOADER"Frame 1
"LOADER"Frame 2
"SPONSOR"Frame 33
"MENU"Frame 213
"GAME"Frame 214
"CREDITS"Frame 215




http://swfchan.com/14/67281/info.shtml
Created: 11/4 -2019 15:40:40 Last modified: 11/4 -2019 15:40:40 Server time: 05/11 -2024 06:37:03