Actionscript:
-
var matrix:Matrix3D = new Matrix3D();
-
var verts:Vector.<Number> = new Vector.<Number>();
-
var pVerts:Vector.<Number> = new Vector.<Number>();
-
var uvts:Vector.<Number> = new Vector.<Number>();
-
const TWO_PI:Number=Math.PI * 2;
-
var step:Number=.05;
-
-
var brush:BitmapData = new BitmapData(3, 2, true, 0x41FFFFFF);
-
var n:Number=8;
-
var xp:Number=0,yp:Number=0,a:Number=12,t:Number=0;
-
for (var i:Number = 0; i<TWO_PI; i+=step) {
-
for (var j:Number = 0; j<TWO_PI; j+=step) {
-
// unoptimized for readability
-
var cosi:Number = a/n * ((n - 1) * Math.cos(i) + Math.cos(Math.abs((n - 1) * i)));
-
var sini:Number = a/n * ((n - 1) * Math.sin(i) - Math.sin(Math.abs((n - 1) * i)));
-
var cosj:Number = a/n * ((n - 1) * Math.cos(j) + Math.cos(Math.abs((n - 1) * j)));
-
var sinj:Number = a/n * ((n - 1) * Math.sin(j) - Math.sin(Math.abs((n - 1) * j)));
-
verts.push(cosi * cosj);
-
verts.push(sini * cosj);
-
verts.push(a * sinj);
-
pVerts.push(0),pVerts.push(0);
-
uvts.push(0),uvts.push(0),uvts.push(0);
-
}
-
}
-
var canvas:BitmapData=new BitmapData(400,400,false,0x000000);
-
addChild(new Bitmap(canvas));
-
var dx:Number=0;
-
var dy:Number=0;
-
addEventListener(Event.ENTER_FRAME, onLoop);
-
function onLoop(evt:Event):void {
-
dx += (mouseX - dx)/4;
-
dy += (mouseY - dy)/4;
-
matrix.identity();
-
matrix.appendRotation(dy,Vector3D.X_AXIS);
-
matrix.appendRotation(dx,Vector3D.Y_AXIS);
-
matrix.appendTranslation(200, 200, 0);
-
Utils3D.projectVectors(matrix, verts, pVerts, uvts);
-
canvas.lock();
-
canvas.fillRect(canvas.rect, 0x000000);
-
var p = new Point();
-
for (var i:int = 0; i<pVerts.length; i+=2) {
-
p.x = pVerts[i];
-
p.y = pVerts[i + 1];
-
canvas.copyPixels(brush, brush.rect, p, null, null, true);
-
}
-
canvas.unlock();
-
}
Taking the Hypocycloid stuff from yesterday into 3D...
5 Comments
Hi Zevon,
I get 3 errors when checking this one out?
I’m on a different computer using CS3. I’ll check it out on my computer tomorrow in CS4 to see if it works then.
Best
Gayle
A lot of really nice snippets, very good inspiration!
One little thing though, could you perhaps use a syntax-highlighter without the linenumbers?
Its quite cumbersome to paste a script and then have to remove all the numbers - at least thats what happens for me on XP when pasting to Flash IDE.
Cheers
Mads
@gayle - it will only work in CS4… since it used Vector and flash 10 3D stuff.
@Mads - just click on the “Plain Text” button above the code and you’ll be able to copy and paste without line nums… I will however be switching to a new code highlighter that will not require the “Plain Text” button … sometime in the next few days…
Thanks Zevon!
I am eating my words! I figured, regarding the the 3D stuff.
Really is a beautiful piece. Love these Action Snippets. It’s a goodie a day!
Gayle
Ah okay, hadn’t even noticed that that was a clickable button, just looked like a header - thanks
One Trackback
[...] kan dreje sig om alt fra 3D eksperimenter til hvordan man tegner bestemt tandhjul eller hvordan man kan finde kvadratroden, hvis man nu bare [...]