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

forked from: Stripe forked from: Draw worm by mouse gesture.

帯を引く
package {
	import caurina.transitions.Equations;
	import caurina.transitions.Tweener;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.ColorTransform;
	import flash.geom.Point;
	
	import frocessing.display.F5MovieClip2DBmp;
	import frocessing.geom.FMatrix2D;
	
	//帯を引く
	[SWF(backgroundColor=0x444444, width=465, height=465)]
	public class Matrixtest extends F5MovieClip2DBmp
	{
		private var vms:Array;
        private var MAX_NUM:int = 100; 
        private var N:Number = 80;
        private var px:Number;
        private var py:Number;
        private var col:uint = 0xFFFFFFFF;
        private var ct:ColorTransform = new ColorTransform(1,1,1,1,-4,-4,-4);
		private var movePts:Point = new Point(865,100)
		
		public function Matrixtest()
		{
			stage.frameRate = 60;
            colorMode( HSV, 1 );
            
            vms = [];
            
            addEventListener(Event.ADDED_TO_STAGE, addStageHandler);
            drawStripe();
		}
		
		private function addStageHandler(e:Event):void {
			stage.addEventListener(MouseEvent.CLICK, function():void{
					drawStripe();
				} );
		}
		private function drawStripe():void {
			movePts.x = 965; movePts.y = -20;
			Tweener.addTween(movePts,{x:0, time:1, transition:Equations.easeNone});
		}
		
		public function setup():void
        {
            background(0);
            noStroke();
            px = movePts.x;
            py = movePts.y;
            scale(0.5, 0.5);
        }
        
        
        //////////////////
        ////		 ////
        //// D R A W ////
        ////		 ////
        //////////////////
        public function draw():void
        {
        	if( isMousePressed ) {
                background(0);
                vms = [];
            }
            
            noStroke();
       	    var len:int = vms.length;
            for( var i:int=0; i<len; i++ ) {
                var o:WormObject = vms[i];
                if( o.count<N ){
                	drawWorm( o );
                    o.count++;
                }else{
                    len--;
                    vms.splice( i, 1 );
                    i--;
                }
            }
            
            check();
        }
        
        public function check():void
        {
            var x0:Number = movePts.x;
            var y0:Number = movePts.y;
            var vx:Number = x0 - px;
            var vy:Number = y0 - py;
            var len:Number = min( mag( vx, vy ), 80 );
          	
            if( len<10 ) return;
            
            var mtx:FMatrix2D = new FMatrix2D();
            mtx.rotate( atan2( vy, vx )+270*Math.PI/180 );
            //mtx.rotate( 45*Math.PI/180 );
            mtx.translate( x0, y0 );
            
            createObj( mtx, len );
            
            stroke(0xFF0000*Math.random())
            line( px, py, x0, y0 );
            px = x0;
            py = y0;
        }
        
        public function createObj( mtx:FMatrix2D, len:Number ):void
        {
            var angle:Number = random(PI/15,PI/6);
            if( Math.random()>0.5 )
                angle *= -1;
            var tmt:FMatrix2D = new FMatrix2D();
            
           // tmt.scale( 0.95, 0.95 );
           // tmt.rotate( angle );
            tmt.translate( len, len );
            var w:Number = 1;
            
            var obj:WormObject = new WormObject();
            obj.thin = 1 + 5 * Math.random();
            obj.c1x = obj.p1x = -obj.thin * mtx.c + mtx.tx;
            obj.c1y = obj.p1y = -obj.thin * mtx.d + mtx.ty;
            obj.c2x = obj.p2x =  obj.thin * mtx.c + mtx.tx;
            obj.c2y = obj.p2y =  obj.thin * mtx.d + mtx.ty;
            
           
            obj.col = color(random(0.95,1), random(0.2,1), random(0.3,1));
            if( Math.random()>0.9 ) {
            	obj.flg = true;
            	tmt.scale( 0.95, 0.95 );
            }
            
            obj.vmt = mtx;
            obj.tmt = tmt;
            obj.r   = angle;
            obj.w   = len/20;
            obj.count = 0;
                
            vms.push( obj );
            if( vms.length > MAX_NUM )
                vms.shift();
        }
        
        
        public function drawWorm( obj:WormObject ):void
        {
        	if( Math.random()>0.9 ){
                if(obj.flg) obj.tmt.rotate( -obj.r );
                obj.r *= -1;
            }
           	obj.vmt.prepend( obj.tmt );
            var cc1x:Number = -obj.w*obj.vmt.c*obj.thin + obj.vmt.tx;
            var cc1y:Number = -obj.w*obj.vmt.d*obj.thin + obj.vmt.ty;
            
            var pp1x:Number = (obj.c1x+cc1x)/2;
            var pp1y:Number = (obj.c1y+cc1y)/2;
            var cc2x:Number = obj.w*obj.vmt.c*obj.thin + obj.vmt.tx;
            var cc2y:Number = obj.w*obj.vmt.d*obj.thin + obj.vmt.ty;
            
            var pp2x:Number = (obj.c2x+cc2x)/2;
            var pp2y:Number = (obj.c2y+cc2y)/2;
            
            beginFill( obj.col );
            
            stroke( obj.col );
            moveTo( obj.p1x, obj.p1y );
            curveTo( obj.c1x, obj.c1y, pp1x, pp1y );
            lineTo( pp2x, pp2y );
            curveTo( obj.c2x, obj.c2y, obj.p2x, obj.p2y );
            closePath();
            endFill();
            
            
            obj.c1x = cc1x;
            obj.c1y = cc1y;
            obj.p1x = pp1x;
            obj.p1y = pp1y;
            obj.c2x = cc2x;
            obj.c2y = cc2y;
            obj.p2x = pp2x;
            obj.p2y = pp2y;
        }
        
	}
}

import frocessing.geom.FMatrix2D;
class WormObject{
    public var c1x:Number;
    public var c1y:Number;
    public var c2x:Number;
    public var c2y:Number;
    public var p1x:Number;
    public var p1y:Number;
    public var p2x:Number;
    public var p2y:Number;
    public var col:Number;
    public var flg:Boolean = false;
    public var thin:Number = 1;
    public var w:Number;
    public var r:Number;
    public var count:int;
    public var vmt:FMatrix2D;
    public var tmt:FMatrix2D;
    public function WormObject(){
        
    }
}