Genesis
Genesis for wonderfl
// Genesis for wonderfl
package {
import flash.display.Sprite;
import flash.events.*;
[SWF(width="465", height="465", backgroundColor="0x000000", frameRate="30")]
public class GenesisFL extends Sprite {
public function GenesisFL() {
main = this;
initialize();
addEventListener(Event.ENTER_FRAME, update);
stage.addEventListener(MouseEvent.CLICK, mouseEvent);
}
}
}
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.filters.*;
import flash.geom.*;
import flash.utils.*;
const SCREEN_WIDTH:int = 465;
const SCREEN_HEIGHT:int = 465;
const MAX_RADIUS:int = 320;
const BASERECT_WIDTH:int = 30;
const BASERECT_HEIGHT:int = 30;
const LEVEL:int = 4;
var main:Sprite;
var buffer:BitmapData = new BitmapData(SCREEN_WIDTH, SCREEN_HEIGHT, false, 0);
var baseRect:BitmapData = new BitmapData(BASERECT_WIDTH, BASERECT_HEIGHT, false, 0xFFFFFF);
var rect:Rectangle = new Rectangle;
var matrix:Matrix = new Matrix;
var colTrans:ColorTransform = new ColorTransform;
var deg1:Number;
var deg2:Number;
var deg3:Number;
var deg4:Number;
var vdeg1:Number;
var vdeg2:Number;
var vdeg3:Number;
var vdeg4:Number;
function initialize():void {
main.addChild(new Bitmap(buffer));
deg1 = deg2 = deg3 = deg4 = 0.0;
mouseEvent(null);
}
function mouseEvent(e:Event):void {
vdeg1 = (Math.random() - 0.5) / 8.0;
vdeg2 = (Math.random() - 0.5) / 8.0;
vdeg3 = (Math.random() - 0.5) / 8.0;
vdeg4 = (Math.random() - 0.5) / 32.0;
}
function update(e:Event):void {
deg1 += vdeg1;
deg2 += vdeg2;
deg3 += vdeg3;
deg4 += vdeg4;
buffer.lock();
buffer.fillRect(buffer.rect, 0);
for (var x:int = -LEVEL; x <= LEVEL; x++) {
var yr:int = LEVEL - Math.abs(x);
for (var y:int = -yr; y <= yr; y++) {
var zr:int = yr - Math.abs(y);
for (var z:int = -zr; z <= zr; z++) {
calcMatrix(x, y, z);
calcColTrans(x, y, z);
buffer.draw(baseRect, matrix, colTrans, BlendMode.ADD);
}
}
}
buffer.unlock();
}
function calcMatrix(x:int, y:int, z:int):void {
var dx:Number = x / LEVEL;
var dy:Number = y / LEVEL;
var dz:Number = z / LEVEL;
matrix.identity();
matrix.translate(-baseRect.width / 2, -baseRect.height / 2);
matrix.translate(dx * MAX_RADIUS * Math.cos(deg4), dy * MAX_RADIUS * Math.cos(deg4));
matrix.rotate(deg1);
matrix.scale(1.0, Math.cos(deg3));
matrix.translate(0, dz * MAX_RADIUS * Math.sin(deg3) * Math.cos(deg4));
matrix.rotate(deg2);
matrix.translate(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2);
}
function calcColTrans(x:int, y:int, z:int):void {
var cr:int = (1.0 + x / LEVEL) * 16;
var cg:int = (1.0 + y / LEVEL) * 16;
var cb:int = (1.0 + z / LEVEL) * 16;
colTrans.color = 0x10000 * cr + 0x100 * cg + cb;
}