Hello, seizure :)
package
{
import flash.display.*
import flash.events.*
import flash.filters.*
import flash.media.*
import flash.net.*
import flash.system.*
import flash.utils.*
import alternativ5.engine3d.controllers.*
import alternativ5.engine3d.core.*
import alternativ5.engine3d.display.*
import alternativ5.engine3d.materials.*
import alternativ5.engine3d.primitives.*
[SWF(backgroundColor="0")]
public class CubeSwarm extends Sprite
{
private var scene:Scene3D;
private var swarm:Array = [];
private var view:View;
private var s:Sound;
private var ba:ByteArray = new ByteArray ();
private var gf:GlowFilter = new GlowFilter (0xFF7F00, 1, 100, 100, 2);
public function CubeSwarm ()
{
// does it really help here?..
Security.loadPolicyFile("http://www.helpexamples.com/crossdomain.xml");
scene = new Scene3D; scene.root = new Object3D;
view = new View; view.camera = new Camera3D; scene.root.addChild (view.camera);
view.width = view.height = 465; view.camera.z = -100; addChild (view);
for (var i:int = 0; i < 3; i++)
for (var j:int = 0; j < 3; j++)
if ((i + j) % 2 == 0) {
var b:BoxElement = new BoxElement;
b.box = new Box (10, 10, 10);
b.box.x = b.x = (i - 1) * 10; b.box.y = b.y = (j - 1) * 10;
b.box.cloneMaterialToAllSurfaces (
new FillMaterial (0, 1, BlendMode.NORMAL, 2, 0xFF0000));
scene.root.addChild (b.box);
swarm.push (b);
}
addEventListener (Event.ENTER_FRAME, function (e:Event):void {
view.camera.rotationZ += 0.1;
SoundMixer.computeSpectrum (ba, true);
gf.color = (ba.readFloat () * 0xF0F0F + gf.color) & 0xFFFFFF;
view.filters = [ gf ];
var b:BoxElement, i:int, sc:Number;
for each (b in swarm) {
sc = 1 + ba.position * 0.02;
for (i = 0; i < 3; i++)
sc += Math.abs (ba.readFloat ()) * 0.6;
b.box.x = b.x * sc; b.box.rotationX += b.dx;
b.box.y = b.y * sc; b.box.rotationY += b.dy;
b.box.z = b.z * sc; b.box.rotationZ += b.dz;
b.box.scaleX = 1.5 * sc;
b.box.scaleY = 1.5 * sc;
b.box.scaleZ = 1.5 * sc;
}
scene.calculate ();
});
s = new Sound (); s.addEventListener (Event.COMPLETE, completeHandler);
s.load (new URLRequest ("http://www.helpexamples.com/flash/sound/song3.mp3"),
new SoundLoaderContext (1000, true));
}
private function completeHandler (event:Event):void {
// start & loop playback
var song:SoundChannel = s.play ();
song.addEventListener (Event.SOUND_COMPLETE, completeHandler);
}
}
}
import alternativ5.engine3d.primitives.Box;
class BoxElement {
public var box:Box;
public var x:Number = 0;
public var y:Number = 0;
public var z:Number = 0;
public var dx:Number = 0.1 * Math.random ();
public var dy:Number = 0.1 * Math.random ();
public var dz:Number = 0.1 * Math.random ();
}