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: MyTemplate

wonderfl で何か作るときの雛形
Get Adobe Flash player
by bradsedito 04 Feb 2011
/**
 * Copyright bradsedito ( http://wonderfl.net/user/bradsedito )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/cJga
 */

// forked from autumngoodluck's MyTemplate
/*
 * wonderfl で何か作るときの雛形
 */
package
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.filters.BlurFilter;
    

    [SWF(width="465", height="465", backgroundColor="0x000000", frameRate="50")]
    public class MyTemplate extends Sprite
    {
        private var _ball:MyBall;

        public function MyTemplate()
        {
            _ball   = new MyBall(30, 0x00ffffff);
            _ball.x = stage.stageWidth  / 2;
            _ball.y = stage.stageHeight / 2;
              var _blur:BlurFilter;
              _blur = new BlurFilter(10, 10, 3);
            addChild(_ball);
            addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
        }

        public function loop(event:Event):void
        {
            _ball.move();
        }
    }
}

import flash.display.GradientType;
import flash.display.Sprite;
import flash.geom.Matrix;

class MyBall extends Sprite
{

    private var _velocityX:Number;
    private var _velocityY:Number;

    public function MyBall(radius:Number, color:uint)
    {
        var gradientType:String = GradientType.RADIAL;
        var colors:Array        = [color, 0x000000];
        var alphas:Array        = [1, 1];
        var ratios:Array        = [0, 255];
        var matrix:Matrix       = new Matrix();
        
        matrix.createGradientBox(radius * 3, radius * 3, 0, -radius * 1.8, -radius * 1.8);
        graphics.beginGradientFill(gradientType, colors, alphas, ratios, matrix);
        graphics.drawCircle(0, 0, radius);
        graphics.endFill();
        
        _velocityX = 0;
        _velocityY = 0;
    }


    public function move():void
    {
  //      _velocityX = MyMotion.elastic(x, stage.mouseX, 0.15, 0.85, _velocityX);
   //     _velocityY = MyMotion.elastic(y, stage.mouseY, 0.15, 0.85, _velocityY);
        _velocityX = MyMotion.friction(x, stage.mouseX, 10);
        _velocityY = MyMotion.friction(y, stage.mouseY, 10);

        x += _velocityX;
        y += _velocityY;
    }
}


class MyMotion
{

    public static function deg2Rad(angle:Number):Number
    {
        return angle * (Math.PI / 180);
    }

    public static function elastic(start:Number, stop:Number, k:Number, damp:Number, velocity:Number):Number
    {
        velocity += -k * (start - stop);
        return velocity *= damp;
    }
    
    public static function friction(start:Number, stop:Number, k:Number = 10):Number
    {
        return (stop - start) / k;
    }
}