follow
Trail
I was talking with a friend about the old “duplicateMovieClip()” stuff we used to do with as2 and this idea popped into my head. Enjoy:
package { import gs.TweenMax; import org.papervision3d.lights.PointLight3D; import org.papervision3d.materials.shadematerials.PhongMaterial; import org.papervision3d.objects.DisplayObject3D; import org.papervision3d.objects.primitives.Sphere; import org.papervision3d.view.BasicView; import flash.events.TimerEvent; import flash.utils.Timer; /** * @author John Lindquist */ [SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")] public class Trail extends BasicView { private const NUM_FOLLOWERS:int = 200; //range of movement private const MAX_X:Number = 1000; private const MAX_Y:Number = 1000; private const MAX_Z:Number = 1000; private const MOVE_BACK:Number = 25; //light private const LIGHT_COLOR:Number = 0x0000cc; private const AMBIENT:Number = 0x000000; private const SPECULAR:int = 3; //timing private const LEADER_TIME:Number = 2; //3 seconds private const GENERATE_TIME:Number = 50; private const SCALE_TIME:Number = GENERATE_TIME * NUM_FOLLOWERS / 1000; //sphere props private const SPHERE_RADIUS:Number = 100; private const SEGMENTS:int = 1; //display object 3ds private var followers:Array = []; private var followersIndex:int = 0; private var leader:DisplayObject3D; public function Trail() { camera.z = -2000; var light:PointLight3D = new PointLight3D(); var material:PhongMaterial = new PhongMaterial(light, LIGHT_COLOR, AMBIENT, SPECULAR); leader = new Sphere(material, SPHERE_RADIUS, SEGMENTS, SEGMENTS); //built-in to BasicView scene.addChild(leader); startRendering(); //move the leader around however you wish moveLeader(); //setup a timer for creating followers var timer:Timer = new Timer(GENERATE_TIME); timer.addEventListener(TimerEvent.TIMER, timerHandler); timer.start(); } private function moveLeader():void { var targetX:Number = Math.random() * MAX_X * 2 - MAX_X; var targetY:Number = Math.random() * MAX_Y * 2 - MAX_Y; var targetZ:Number = Math.random() * MAX_Z * 2 - MAX_Z; var bezierX:Number = targetX * -1; var bezierY:Number = targetY * -1; var bezierZ:Number = targetZ * -1; var bezier:Object = {x:bezierX, y:bezierY, z:bezierZ}; TweenMax.to(leader, LEADER_TIME, {x:targetX, y:targetY, z:targetZ, bezierThrough:[bezier], onComplete:moveLeader}); } private function timerHandler(event:TimerEvent):void { var follower:DisplayObject3D; if(followers.length < NUM_FOLLOWERS) { follower = DisplayObject3D(leader.clone()); scene.addChild(follower); followers.push(follower); } else { followersIndex = (followersIndex < followers.length) ? followersIndex : 0; follower = followers[followersIndex]; followersIndex++; } follower.copyTransform(leader); follower.moveBackward(MOVE_BACK); follower.scale = 1; TweenMax.to(follower, SCALE_TIME, {scale:0}); } } }
Search
Recommended Books
Speaking at FITC Toronto
Recent Posts
- Moving to johnlindquist.com
- AsyncCommand with Robotlegs, Signals, Flight, MinimalComps
- Search Widget – Robotlegs, Signals, Flight, Minimal Comps, Yahoo Astra
- FDT Super Awesome March Deal
- FDT Theme Designer
- haXe Tutorial
- AS3 Signals Tutorial
- Preferred Video Tutorial Resolution?
- TweenMax – Tweening a timeline (Advanced Tweening)
- Robotlegs + Flight + Union Platform
- Back in the saddle
- Eclipse Theme Designer Preview
- RobotLegs Hello World Video Tutorial
- 10 Things Every Senior Flash Developer Should Know
- Efflex – 3D Effects for Flex
Recent Comments
- Hosting company on archive
- aanbae on Back in the saddle
- Domain registration on Looking around the inside of a Sphere
- website designing company on Looking around the inside of a Sphere
- Honda Motor on Augmented Reality – Recursive Webcam
- Zena on Augmented Reality – Recursive Webcam
- web hosting on Augmented Reality – Recursive Webcam
- web hosting on Twitter + Papervision3D (using Tweetr)
- web hosting on Efflex – 3D Effects for Flex
- web hosting on TweenMax – Tweening a timeline (Advanced Tweening)
Categories
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « May | ||||||
| 1 | 2 | 3 | 4 | 5 | ||
| 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
| 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| 27 | 28 | 29 | ||||
Archives
Preferred Video Tutorial Resolution
- 1024x768 (53%, 85 Votes)
- 1280x1024 (15%, 24 Votes)
- 1920x1080 (15%, 24 Votes)
- 800x600 (13%, 20 Votes)
- 480x320 (4%, 6 Votes)
- 640x480 (0%, 2 Votes)
Total Voters: 160

