In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Another Implicit 3D Blobby

interactive implicit 3D blobby plot
more info here: http://actionsnippet.com/?p=1318
Get Adobe Flash player
by zotin95 04 Mar 2010
/**
 * Copyright zotin95 ( http://wonderfl.net/user/zotin95 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/lMcd
 */

// forked from shapevent's Implicit 3D Blobby
package {

        // interactive implicit 3D blobby plot
        
        // more info here: http://actionsnippet.com/?p=1318
        
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;


	
       [SWF(backgroundColor=0x000000)]
       
       public class ImplicitBlobby extends MovieClip {
		private var matrix:Matrix3D;
		private var verts:Vector.<Number>;
		private var pVerts:Vector.<Number>;
		private var uvts:Vector.<Number>;
		private var s:Number;
		private var brush:BitmapData;
		private var canvas:BitmapData;
		private var dx:Number;
		private var dy:Number;


        public function ImplicitBlobby(){
                  // init
			matrix = new Matrix3D();
			verts = new Vector.<Number>();
			pVerts = new Vector.<Number>();
			uvts = new Vector.<Number>();
			for (var i:Number = -2; i<2; i+=.08) {
				for (var j:Number = -2; j<2; j+=.08) {
					for (var k:Number = -2; k<2; k+=.08) {
						// blobby, from here www.iiit.net/techreports/ImplicitTR.pdf
			//s=i*i+(int(j)%5)+k*k+Math.sin(4*i)-Math.cos(4*j)+Math.sin(4*k)-1;
				s = i*i + k*k + Math.sin(4*i)-Math.cos(j)+Math.sin(4*k) * j*j;
						if (s<0&&s>-.4) {
							verts.push(i * 60);
							verts.push(j * 30);
							verts.push(k * 60);
							pVerts.push(0),pVerts.push(0);
							uvts.push(0),uvts.push(0),uvts.push(0);
						}
					}
				}
			}
			brush=new BitmapData(5,6,true,0x516666FF);
			canvas=new BitmapData(400,400,false,0x000000);
			addChild(new Bitmap(canvas));
			dx=0;
			dy=0;
			addEventListener(Event.ENTER_FRAME, onLoop);
			

               }
               // private methods

		private 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:Point = 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();
		}
		

       }

}