Actionscript:
-
[SWF(width = 600, height = 600, backgroundColor=0x000000)]
-
var squareNum:int = 1000;
-
var hw:Number = stage.stageWidth / 2;
-
var hh:Number = stage.stageHeight / 2;
-
// verts defines a single square
-
var verts:Vector.<Number> = Vector.<Number>([-20, 0, 0, 20, 0, 0, 20, 0, 40, -20, 0, 40, -20, 0, 0]);
-
var cmds:Vector.<int> = Vector.<int>([1,2,2,2,2]);
-
var tempVerts:Vector.<Number> = new Vector.<Number>();
-
var newVerts:Vector.<Number> = new Vector.<Number>();
-
var pVerts:Vector.<Number> = new Vector.<Number>(10 * squareNum);
-
var uv:Vector.<Number> = new Vector.<Number>(15 * squareNum);
-
var vectors:Shape = new Shape();
-
var canvas:BitmapData = new BitmapData(stage.stageWidth,stage.stageHeight,false, 0x000000);
-
addChild(new Bitmap(canvas));
-
var blurred:BitmapData = new BitmapData(stage.stageWidth,stage.stageHeight,false, 0x000000);
-
var blur:BlurFilter = new BlurFilter(20,20,1);
-
-
var m:Matrix3D = new Matrix3D();
-
-
var radius:Number = 200;
-
// duplicate the verts array a bunch of times
-
// each time moving the square to a random place on the
-
// circumference of a sphere
-
for (var i:int = 0; i<squareNum; i++){
-
m.identity();
-
var s:Number = Math.random()*.5 + .5;
-
m.appendScale(s, s, s);
-
m.appendRotation(90,Vector3D.X_AXIS);
-
m.appendTranslation(0, 0, radius);
-
m.appendRotation(Math.random()*360,Vector3D.X_AXIS);
-
m.appendRotation(Math.random()*360,Vector3D.Y_AXIS);
-
m.appendRotation(Math.random()*360,Vector3D.Z_AXIS);
-
m.transformVectors(verts,tempVerts);
-
newVerts = newVerts.concat(tempVerts);
-
cmds = cmds.concat(Vector.<int>([1,2,2,2,2]));
-
}
-
newVerts.fixed = pVerts.fixed = uv.fixed = true;
-
var dx:Number = 0, dy:Number = 0;
-
var pnt:Point = new Point();
-
addEventListener(Event.ENTER_FRAME, onLoop);
-
function onLoop(evt:Event):void {
-
dx += (mouseX - dx) / 4;
-
dy += (mouseY - dy) / 4;
-
m.identity();
-
m.appendRotation(dx,Vector3D.Z_AXIS);
-
m.appendRotation(dy,Vector3D.X_AXIS);
-
m.appendTranslation(hw,hh, 0);
-
Utils3D.projectVectors(m, newVerts, pVerts, uv);
-
with(vectors.graphics){
-
clear();
-
beginFill(0xFFFFFF);
-
drawCircle(hw, hh, radius+10);
-
beginFill(0x000000);
-
drawPath(cmds, pVerts, GraphicsPathWinding.NON_ZERO);
-
}
-
canvas.fillRect(canvas.rect, 0x000000);
-
canvas.draw(vectors);
-
blurred.copyPixels(canvas, canvas.rect, pnt);
-
blurred.applyFilter(blurred,blurred.rect, pnt, blur);
-
canvas.draw(blurred, null, null, BlendMode.SCREEN);
-
}
This snippet is similar to yesterdays post but the visual result is rather different. This one does a little more Matrix3D stuff resulting in a sphere made up entirely of squares. This is obscured by the size of the squares and the fact that they overlap and cut each other up. BitmapData a BlurFilter and a BlendMode give the entire thing a slight glow...