1 0 Tag Archives: actionscript3

Simple Particle System in PaperVision3D

I understand that PaperVision natively provides a ParticleSystem and there have been other Particle System code snippets lurking around the internet, but for people, who have been following my particle system tutorials, I’m going to tell you how to convert the same particle system into 3D using PaperVision3D. Here’s how it looks in PaperVision3D; you can use the mouse and the arrow keys to move the camera around:

Code rundown:

If you want to understand the code in the sources below, you can go through the tutorial, I posted about setting up projects in PV3D. The biggest change is to remove the particlesystem class and reduce the Parent Child Hierarchy. I have moved the ParticleSystem class into the main section of our project, such that all particles become direct children of the scene. This reduces the need to have a DisplayObject3D Container. It also helps in managing the particles easily.

You can grab the sources below and don’t forget to leave me some feedback ;) .

simpleparticlesystempv3d.zip

Read full story »

Crazy Flocking in PaperVision3D

UPDATE: I have released a complete working port of Opensteer for ActionScript 3. Please see this post.

As I told you earlier, I have been obsessed with making demos of emergent behavior and natural phenomena. This little demo shows how a flock of birds acts when they are crazy ;) . This code snippet was originally designed by Ira Ivanou and I translated it to PaperVision3D, just to give you a taste of how cool it is.

Grab the sources below.

crazyflockingbehavior.zip

Read full story »

Spring Physics in AS3

This little app is to show how you can create artificial physics in Flash using formulas. The principal is quite simple: A guiding hook has several springs attached to it. Each spring is attached to its parent, and thus if the parent spring is moved, the resulting physics is perpetuated to its children.

Here’s the code:

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import flash.display.*;
 
public class Spring extends Shape
{
var XVelocity:Number, YVelocity:Number = 0.0;
var Gravity:Number = 6.0;
var Mass:Number = 2.0;
var Radius:Number = 2.0;
var Stiffness:Number = 0.2;
var Damping:Number = 0.7;
 
public function Spring(XPosition_:Number, YPosition_:Number, Mass_:Number, Gravity_:Number)
{
XVelocity = 0.0;
YVelocity = 0.0;
Radius = 10.0;
Stiffness= 0.5;
Damping = 0.7;
x = XPosition_;
y = YPosition_;
Mass = Mass_;
Gravity = Gravity_;
}
 
public function UpdatePosition(XTarget:Number, YTarget:Number):void
{
var XForce:Number = (XTarget - x) * Stiffness;
var XFactor:Number = XForce / Mass;
 
XVelocity = Damping * (XVelocity + XFactor);
x += XVelocity;
 
var YForce:Number = (YTarget - y) * Stiffness;
YForce += Gravity;
 
var YFactor:Number = YForce / Mass;
 
YVelocity = Damping * (YVelocity + YFactor);
y += YVelocity;
}
 
public function RenderPosition(XNew:Number, yNew:Number)
{
graphics.clear();
graphics.beginFill(0xf5f4ea);
graphics.lineStyle(3,0xdfdfdf);
graphics.drawEllipse(0,0,Radius * 2,Radius * 2);
//graphics.moveTo(XNew,YNew);
//graphics.lineTo(x, y);
graphics.endFill();
}
}

Grab the sources below:

chain.zip

Read full story »
Page 1 of 212