Actionscript:
-
[SWF(backgroundColor=0x222222, width=500, height=500)]
-
var hsw:Number = stage.stageWidth / 2;
-
var hsh:Number = stage.stageHeight / 2;
-
var pointNum:int = 800
-
var points3D:Vector.<Number> = new Vector.<Number>();
-
var points3Dout:Vector.<Number> = new Vector.<Number>();
-
var points2D:Vector.<Number> = new Vector.<Number>();
-
var uvts:Vector.<Number> = new Vector.<Number>();
-
var sorted:Array = [];
-
var pnt:Point = new Point();
-
var m:Matrix3D = new Matrix3D();
-
var v:Vector3D = new Vector3D();
-
for (var i:int = 0; i<pointNum; i++){
-
v.y = i * 0.7 - 300
-
var t =Math.random()*6.28;
-
v.x = 200 * Math.cos(i * 2 * Math.PI / 180);
-
v.z = 200 * Math.sin(i * 2 * Math.PI / 180);
-
v = m.transformVector(v);
-
points3D.push(v.x, v.y, v.z);
-
points2D.push(0,0);
-
uvts.push(0,0,0);
-
sorted.push(new Vector3D());
-
}
-
points3D.fixed = true;
-
points2D.fixed = true;
-
uvts.fixed = true;
-
var p:PerspectiveProjection = new PerspectiveProjection();
-
var proj:Matrix3D = p.toMatrix3D();
-
var dx:Number = 0, dy:Number = 0;
-
addEventListener(Event.ENTER_FRAME, onLoop);
-
function onLoop(evt:Event):void {
-
var i:int, j:int;
-
dx += (mouseX - dx) / 4;
-
dy += (mouseY - dy) / 4;
-
m.identity();
-
m.appendRotation(getTimer() / 4, Vector3D.Y_AXIS);
-
m.transformVectors(points3D, points3Dout);
-
-
m.identity();
-
m.appendRotation(dx, Vector3D.Z_AXIS);
-
m.appendRotation(dy, Vector3D.X_AXIS);
-
m.appendTranslation(0, 0, 1000);
-
m.append(proj);
-
Utils3D.projectVectors(m, points3Dout, points2D, uvts);
-
for (i = 0, j = 0; i<points2D.length; i+=2, j++){
-
sorted[j].x = points2D[i] + hsw;
-
sorted[j].y = points2D[i + 1] + hsh;
-
sorted[j].z = uvts[j * 3 + 2];
-
}
-
sorted.sortOn("z", Array.NUMERIC);
-
graphics.clear();
-
for(i = 0; i<sorted.length; i++){
-
var zpos:Number = sorted[i].z * 10000;
-
var c:int = zpos * 14;
-
graphics.beginFill(c <<16 | c <<8 | c);
-
graphics.drawCircle(sorted[i].x, sorted[i].y, zpos);
-
graphics.endFill();
-
}
-
}
A variation on some recent posts... this snippet draws a rotating spring made up of 800 particles...
3 Comments
Very nice!
Thanks
Great, thanks!
Can anybody help me - how i can rotate matrix relate word axis, but not a local, object-axis?