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

線からボール

イメージしてたものと違うものができてしまった
Get Adobe Flash player
by shuff 06 Aug 2011
/**
 * Copyright shuff ( http://wonderfl.net/user/shuff )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/hRrw
 */

package
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    
    import frocessing.color.ColorHSV;
    
    [SWF(backgroundColor=0x0,width=465,height=465)]
    public class SplashBall extends Sprite
    {
        private var startX:Array = [];
        private var startY:Array = [];
        private var endX:Array = [];
        private var endY:Array = [];
        private var c:Array = [];
        private var thick:Array= [];
        private var arr:Array = [];

        
        public function SplashBall()
        {
            
            stage.addEventListener(MouseEvent.MOUSE_DOWN,mousedown);
            stage.addEventListener(MouseEvent.MOUSE_UP, mouseup);
        }
        
        private function mousedown(e:MouseEvent):void{
            startX.push(mouseX);
            startY.push(mouseY);
            thick.push(0);
            c.push(0);
            
            addEventListener(Event.ENTER_FRAME,thickUP);
            stage.addEventListener(MouseEvent.MOUSE_MOVE, mousemove);
            removeEventListener(Event.ENTER_FRAME,enterframe);
        }
        private function thickUP(e:Event):void{
            for(var i:int=0 ; i<thick.length ; i++){
            thick[i]+=3;
            if(thick[i] > 60)thick[i]=60;
            
            graphics.clear();
            var color:ColorHSV = new ColorHSV(c[i]+=10,0.7);
            graphics.lineStyle(thick[i],color.value);
            graphics.moveTo(startX[i],startY[i]);
            graphics.lineTo(mouseX,mouseY);
            }
        }
        private function mousemove(e:MouseEvent):void{
            graphics.clear();
            
            for(var i:int=0 ; i<thick.length ; i++){
            var color:ColorHSV = new ColorHSV(c[i]+=2,0.7);
            graphics.lineStyle(thick[i],color.value);
            graphics.moveTo(startX[i],startY[i]);
            graphics.lineTo(mouseX,mouseY);
            }
        }
        private function mouseup(e:MouseEvent):void{
            endX.push(mouseX);
            endY.push(mouseY);

            addEventListener(Event.ENTER_FRAME, enterframe);
            stage.removeEventListener(MouseEvent.MOUSE_MOVE,mousemove);
            removeEventListener(Event.ENTER_FRAME,thickUP);
        }
        

        private function enterframe(e:Event):void{
            
            
            for(var i:int=0 ; i<thick.length ; i++){
            startX[i] += (endX[i] - startX[i])/10;
            startY[i] += (endY[i] - startY[i])/10;
            
            graphics.clear();
            var color:ColorHSV = new ColorHSV(c[i]+=10,0.7);
            if(Math.pow(startX[i]*startX[i]+startY[i]*startY[i], 0.5) > 5){
                var dir:Number = (Math.random() - 0.5) * Math.PI*2;
                var s:Ball = new Ball(color.value,thick[i]/2,startX[i],startY[i],Math.cos(dir)*10,Math.sin(dir)*10);
                arr.push(s);
                addChild(s);
            }    
            
            graphics.lineStyle(thick[i] -= thick[i]/10,color.value);
            if(thick[i] < 1){
                c.splice(i,1);
                startX.splice(i,1);
                startY.splice(i,1);
                endX.splice(i,1);
                endY.splice(i,1);
                thick.splice(i,1);
                i--;
            }
            
            
            graphics.moveTo(startX[i],startY[i]);
            graphics.lineTo(endX[i],endY[i]);
            }
            
            
            addEventListener(Event.ENTER_FRAME,removeball);
        }
        
        private function removeball(e:Event):void{                
            for(var i:int =0 ; i<arr.length ; i++){
            if (arr[i].x < 0 || arr[i].x > stage.stageWidth) {
                removeChild(arr[i]);
                arr.splice(i--,1);
            }
            else if(arr[i].y<0 || arr[i].y >stage.stageHeight){
                removeChild(arr[i]);
                arr.splice(i--,1);
            }
            else{
            
                arr[i].x += arr[i].vx;
                arr[i].y += arr[i].vy;
            }
            }
            
        }
    }
}

import flash.display.Sprite;
import frocessing.color.ColorHSV;

class Ball extends Sprite{
    public var vx:Number;
    public var vy:Number;
    
    public function Ball(color:Number, thick:Number, startX:Number, startY:Number,vxx:Number,vyy:Number){

        graphics.beginFill(color);
        graphics.drawCircle(0,0,thick);
        graphics.endFill();
        x = startX;
        y = startY;
        
        this.vx = vxx;
        this.vy = vyy;
    }
}