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

WaterDropsSample

重ならないように配置
/**
 * Copyright ile ( http://wonderfl.net/user/ile )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/fHDC
 */

// forked from ile's WaterDropMaker
/* 
shape で WaterDrop を作ってみました。 
waterdrop.size=dropRadius
*/
package  {
    
import flash.display.Sprite;
import flash.events.Event;

    public class Suiteki extends Sprite {
        
        public function Suiteki() {
            var dropN:uint=50;
            var waitN:uint = 120;
            var drops:Array=new Array();
            var drop:WaterDropMaker;
            
            dropDrop();
            addEventListener(Event.ENTER_FRAME, enterFrameHandler);
            
            function enterFrameHandler():void {
                
                if (!waitN--) {
                    waitN = 120;
                    for (var i:uint = 0; i < dropN; i++) {
                        removeChild(drops[i]);
                    }
                    graphics.clear();
                    dropDrop();
                }
            }
            
            function dropDrop():void {
                //backgroundColor
                var bgColor:uint = Math.random() * 0x1000000;
                
                graphics.beginFill(bgColor);
                graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
                graphics.endFill();
                graphics.beginFill (Math.random() * 0x1000000, 1.0);
                graphics.drawCircle  ( 270, 100 , 150);
                graphics.endFill();
                
                //WaterDropsMake
                for(var i:uint=0;i<dropN;i++){
                    do{
                        drop = new WaterDropMaker(Math.random() * 40 + 2);
                        addChild(drop);
                        drops[i] = drop;
                        var reFlg:Boolean=false;
                        drops[i].x = Math.random() * stage.stageWidth;
                        drops[i].y = Math.random() * stage.stageHeight;
                        if(i){
                            for(var j:uint=0;j<i;j++) {
                                if (dropHitTest(drops[i], drops[j])) {
                                    removeChild(drops[i]);
                                    reFlg = true;
                                    break;
                                }
                            }
                        }
                    }while (reFlg);
                    drops[i].rotation = -45;
                }
            }
            //Overlap?true:false
            function dropHitTest(d1:WaterDropMaker, d2:WaterDropMaker):Boolean {
                if (d1.size + d2.size > pythagora(d1.x - d2.x,d1.y - d2.y)) {
                    return true;
                }else {
                    return false;
                }
            }
            //r^2=n^2+m^2
            function pythagora(n:int,m:int):uint{
                return Math.sqrt(m*m+n*n);
            }

            
        }
    }
}

import flash.display.Sprite;
import flash.display.Shape;
import flash.display.GradientType;
import flash.display.SpreadMethod;
import flash.display.Graphics;
import flash.geom.Matrix;
import flash.display.BlendMode;

class WaterDropMaker extends Sprite {
    private var dropSize:uint;

    public function WaterDropMaker(n:uint):void {
        dropSize = n;
        var shadowColor:uint = 0x000000;
        var lightColor:uint = 0xFFFFFF;
        
        var container:Sprite = addChild(new Sprite) as Sprite;
        //container.x = container.y = dropSize;
     
        var shape:Shape = container.addChild(new Shape) as Shape;
        var g:Graphics = shape.graphics;
        var matrix:Matrix = new Matrix;
        
        //long shadow
        shape =  container.addChild(new Shape) as Shape;
        g = shape.graphics;
        //createGradientBox(w,h,r,X,Y)
        matrix.createGradientBox(dropSize * 2, dropSize * 4, 0, -dropSize, -dropSize*2);
        g.beginGradientFill(GradientType.RADIAL, [shadowColor, shadowColor, shadowColor], [0.0,0.1,0], [0,200,255], matrix, SpreadMethod.PAD);
        g.moveTo(-dropSize, 0);
        g.curveTo ( -dropSize , dropSize * 2, 0 , dropSize * 2 );
        g.curveTo ( dropSize , dropSize*2, dropSize , 0 );
        g.curveTo ( dropSize*0.88 , dropSize*0.88, 0 , dropSize );
        g.curveTo ( -dropSize*0.88 , dropSize*0.88, -dropSize , 0 );
        g.endFill();
        
        //around OUTSIDE shadow
        shape =  container.addChild(new Shape) as Shape;
        g = shape.graphics;
        matrix.createGradientBox(dropSize * 2.6, dropSize * 2.6+dropSize/5, 0, -dropSize*1.3, -dropSize*1.3);
        g.beginGradientFill(GradientType.RADIAL, [shadowColor,shadowColor, shadowColor], [0.02,0.05,0], [0,200,255], matrix, SpreadMethod.PAD);
        g.drawCircle(0, dropSize/5, dropSize*1.5);
        g.endFill();

        //base color
        shape =  container.addChild(new Shape) as Shape;
        g = shape.graphics;
        g.beginFill (0x888888, 0.15);
        g.drawCircle  ( 0, 0 , dropSize);
        g.endFill();
        shape.blendMode = BlendMode.LIGHTEN;

        //around INSIDE shadow
        shape =  container.addChild(new Shape) as Shape;
        g = shape.graphics;
        matrix.createGradientBox(dropSize * 3.5, dropSize * 3.7, 0, -dropSize * 1.8, -dropSize * 1.0);
        g.beginGradientFill(GradientType.RADIAL, [shadowColor,shadowColor, shadowColor], [0,0.05,0.07], [0,200,255], matrix, SpreadMethod.PAD);
        g.drawCircle  ( 0, 0 , dropSize);
        g.endFill();
        
        //under shadow
        shape =  container.addChild(new Shape) as Shape;
        g = shape.graphics;
        matrix.createGradientBox(dropSize * 5, dropSize * 5, 0, -dropSize*2.5, -dropSize*3);
        g.beginGradientFill(GradientType.RADIAL, [shadowColor,shadowColor,shadowColor,shadowColor], [0,0, 0.3,1], [0,95,222,255], matrix, SpreadMethod.PAD);
        g.drawCircle(0, 0, dropSize);
        g.endFill();
        
        //base gradation
        shape =  container.addChild(new Shape) as Shape;
        g = shape.graphics;
        matrix.createGradientBox(dropSize * 3.5, dropSize * 3.7, 0, -dropSize*1.8, -dropSize*1.0);
        g.beginGradientFill(GradientType.RADIAL, [lightColor,lightColor, lightColor,lightColor,lightColor,lightColor], [0.8,0.5, 0.1,0,0,0.3], [0,70, 181,216,245,255], matrix, SpreadMethod.PAD);
        g.drawCircle(0, 0, dropSize);
        g.endFill();
        shape.blendMode = BlendMode.OVERLAY;
        
        //highlight
        shape =  container.addChild(new Shape) as Shape;
        g = shape.graphics;
        matrix.createGradientBox(dropSize/2, dropSize/2, 0, -dropSize/4, -dropSize*0.9);
        g.beginGradientFill(GradientType.RADIAL, [lightColor,lightColor,lightColor], [0.8,0.1 ,0], [0,85,255], matrix, SpreadMethod.PAD);
        g.drawCircle(0, 0, dropSize);
        g.endFill();
        
    }
    
    public function get size():int {
    return dropSize;
    }
}