# Wormhole

Actionscript:
1. var matrix:Matrix3D = new Matrix3D();
2. var verts:Vector.<Number> = new Vector.<Number>();
3. var pVerts:Vector.<Number> = new Vector.<Number>();
4. var uvts:Vector.<Number> = new Vector.<Number>();
5. for (var i:Number = -10; i<10; i+=.04) {
6.     for (var j:Number = -5; j<8; j+=.04) {
7.         for (var k:Number = -10; k<10; k+=.04) {
8.             var s:Number =  i * i * j + j * k * k;
9.             if (s <10 && s> 9.95) {
10.                 verts.push(i * 20);
11.                 verts.push(j * 20);
12.                 verts.push(k * 20);
13.                 pVerts.push(0),pVerts.push(0);
14.                 uvts.push(0),uvts.push(0),uvts.push(0);
15.             }
16.         }
17.     }
18. }
19. var brush:BitmapData=new BitmapData(3,2,true,0x41FFFFFF);
20. var canvas:BitmapData=new BitmapData(400,400,false,0x000000);
22. var dx:Number=0;
23. var dy:Number=0;
25. function onLoop(evt:Event):void {
26.     dx += (mouseX - dx)/4;
27.     dy += (mouseY - dy)/4;
28.     matrix.identity();
29.     matrix.appendRotation(dy,Vector3D.X_AXIS);
30.     matrix.appendRotation(dx,Vector3D.Y_AXIS);
31.     matrix.appendTranslation(200, 200, 0);
32.     Utils3D.projectVectors(matrix, verts, pVerts, uvts);
33.     canvas.lock();
34.     canvas.fillRect(canvas.rect, 0x000000);
35.     var p = new Point();
36.     for (var i:int = 0; i<pVerts.length; i+=2) {
37.         p.x = pVerts[i];
38.         p.y = pVerts[i+1];
39.         canvas.copyPixels(brush, brush.rect, p, null, null, true);
40.     }
41.     canvas.unlock();
42. }

Yet another variation on the post from the last two days. This one plots something resembling a wormhole - I was randomly tweaking the equation for a sphere and stumbled upon this...

This entry was posted in 3D, BitmapData, Math, Vector, graphics algorithms, pixel manipulation and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

• ActionSnippet is on Twitter