Some random geometry
everybody is doing random geometry these days :)
// everybody is doing random geometry these days :)
package
{
import flash.display.*
import flash.events.*
import alternativ5.engine3d.controllers.*
import alternativ5.engine3d.core.*
import alternativ5.engine3d.display.*
import alternativ5.engine3d.materials.*
import alternativ5.engine3d.primitives.*
import alternativ5.types.*
[SWF(backgroundColor="0")]
public class RandomGeom extends Sprite
{
private var scene:Scene3D;
private var swarm:Array = [];
private var view:View;
private var camNode:Object3D;
private var m:Number = 0;
public function RandomGeom ()
{
scene = new Scene3D; scene.root = new Object3D;
view = new View; view.camera = new Camera3D; camNode = new Object3D;
camNode.addChild (view.camera); scene.root.addChild (camNode);
view.width = view.height = 465; view.camera.z = -100; addChild (view);
for (var i:int = 0; i < 10; i++)
{
var b:BoxElement = new BoxElement;
b.box = new Box (10, 10, 10);
b.box.rotationX = 2 * Math.PI * Math.random ();
b.box.rotationY = 2 * Math.PI * Math.random ();
b.box.rotationZ = 2 * Math.PI * Math.random ();
swarm.push (b);
}
addEventListener (Event.ENTER_FRAME, function (e:Event):void {
camNode.rotationX += 0.1;
camNode.rotationY += 0.1;
camNode.rotationZ += 0.1;
scene.calculate (); if (m > 40) return;
var b:BoxElement, i:int, sc:Number;
for each (b in swarm) {
var coords:Point3D = b.box.coords;
var angles:Point3D = new Point3D (
b.box.rotationX, b.box.rotationY, b.box.rotationZ);
sc = b.box.scaleX;
b.box = new Box (10, 10, 10);
b.box.cloneMaterialToAllSurfaces (
new FillMaterial (0, 1, BlendMode.NORMAL, 2,
(255 - 3*m) * 0x10000));
b.box.x = coords.x +
10 * Math.cos (angles.z);
b.box.y = coords.y +
10 * Math.sin (angles.z) * Math.sin (angles.x);
b.box.z = coords.z +
10 * Math.sin (angles.z) * Math.cos (angles.x);
b.box.rotationX = angles.x + b.drx;
b.box.rotationY = angles.y + b.dry;
b.box.rotationZ = angles.z + b.drz;
b.box.scaleX = b.ds * sc;
b.box.scaleY = b.ds * sc;
b.box.scaleZ = b.ds * sc;
b.box.mobility = m++; scene.root.addChild (b.box);
}
});
}
}
}
import alternativ5.engine3d.primitives.Box;
class BoxElement {
public var box:Box;
public var dx:Number;
public var dy:Number;
public var dz:Number;
public var drx:Number = 0.3 * Math.random ();
public var dry:Number = 0.3 * Math.random ();
public var drz:Number = 0.3 * Math.random ();
public var ds:Number = 0.4 + 0.4 * Math.random ();
}