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

Rubber 3D gasket

drag
Get Adobe Flash player
by Susisu 10 Apr 2011
// forked from Susisu's 3D gasket
package {
    import flash.events.MouseEvent;
    import flash.events.Event;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import frocessing.color.ColorHSV;
    import net.hires.debug.Stats;
    [SWF(width="512",height="512",backgroundColor="0x000000",frameRate="30")]
    public class FlashTest extends Sprite {
        private var bmd:BitmapData;
        private var bmp:Bitmap;
        private var points:Vector.<Vector.<Number>>;
        private var t:Number;
        private var now:Vector.<Number>;
        private var color:ColorHSV;
        private const VS:Number=512;
        private const SQRT32768:Number=128*Math.SQRT2;
        private var click:Vector.<Boolean>
        public function FlashTest() {
            bmd=new BitmapData(512,512,false,0);
            bmp=new Bitmap(bmd);
            addChild(bmp);
            points=new Vector.<Vector.<Number>>(4,true);
            points[0]=new Vector.<Number>(3,true);
            points[0][0]=0;
            points[0][1]=0;
            points[0][2]=0;
            var n:int=1;
            for(var i:Number=0;i<2*Math.PI;i+=2*Math.PI/3){
                points[n]=new Vector.<Number>(3,true);
                points[n][0]=Math.cos(i)*128;
                points[n][1]=SQRT32768;
                points[n][2]=Math.sin(i)*128;
                n++;
            }
            now=new Vector.<Number>(3,true);
            now[0]=Math.random()*512;
            now[1]=Math.random()*512;
            now[2]=Math.random()*512;
            t=0;
            color=new ColorHSV(0,0.75);
            addChild(new Stats());
            addEventListener(Event.ENTER_FRAME,enterFrame);
            click=new Vector.<Boolean>(4,true);
            stage.addEventListener(MouseEvent.MOUSE_DOWN,mouseDown);
            stage.addEventListener(MouseEvent.MOUSE_UP,mouseUp);
        }
        private function enterFrame(e:Event):void{
            bmd.fillRect(bmd.rect,0);
            for(var i:int=0;i<20000;i++){
                var r:int=Math.random()*4>>0;
                now[0]=(now[0]+points[r][0])/2;
                now[1]=(now[1]+points[r][1])/2;
                now[2]=(now[2]+points[r][2])/2;
                var c:Number=VS/(VS+now[2]);
                var x:Number=256+(now[0]*c)>>0;
                var y:Number=(SQRT32768+(now[1]*c))>>0;
                color.h=now[2]*1.2+120;
                bmd.setPixel(x,y,color.value);
            }
            if(click[0]){
                points[0][0]+=(mouseX-256-points[0][0])/2;
                points[0][1]+=(mouseY-SQRT32768-points[0][1])/2;
            }
            else{
                points[0][0]-=points[0][0]*1.6;
                points[0][1]-=points[0][1]*1.6;
            }
            var n:int=1;
            for(var j:Number=0;j<2*Math.PI;j+=2*Math.PI/3){
                if(click[n]){
                    points[n][0]+=(mouseX-256-points[n][0])/2;
                    points[n][1]+=(mouseY-SQRT32768-points[n][1])/2;
                    //points[n][2]+=0-points[n][2]/2;
                }
                else{
                    points[n][0]-=(points[n][0]-Math.cos(j+t)*128)*1.6;
                    points[n][1]-=(points[n][1]-SQRT32768)*1.6;
                    points[n][2]-=(points[n][2]-Math.sin(j+t)*128)*1.6;
                }
                n++;
            }
            t+=Math.PI/60;
            if(t>2*Math.PI)t-=2*Math.PI;
        }
        public function mouseDown(e:MouseEvent):void{
            var n:int=0;
            var maxd:Number=65536;
            for(var i:int=0;i<4;i++){
                var dx:Number=mouseX-256-points[i][0];
                var dy:Number=mouseY-SQRT32768-points[i][1];
                var d:Number=dx*dx+dy*dy;
                if(d<maxd){
                    maxd=d;
                    n=i;
                }
            }
            click[n]=true;
        }
        public function mouseUp(e:MouseEvent):void{
            for(var i:int=0;i<4;i++){
                click[i]=false;
            }
        }

    }
}