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 nabe 11 Jan 2009
    Embed
// forked from nabe's PerlinNoise
// write as3 code here..
package {
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;

    [SWF(width="465", height="465", backgroundColor="0", frameRate="12")]
    public class Program_ extends Sprite {

        private var W_:uint;
        private var H_:uint;

        private var bmd:BitmapData;

        private var bubble_:Bitmap;

        private var vx_:Number = 0;
        private var vy_:Number = 0;
        private var vs_:Number = 0;

        public function Program_ () {
            addEventListener(Event.ADDED_TO_STAGE, init_);
        }

        public function init_ (event_:Event):void {
            removeEventListener(Event.ADDED_TO_STAGE, init_);

            W_ = stage.stageWidth;
            H_ = stage.stageHeight;

            bmd = new BitmapData(W_, H_, false);

            //基本の波長。
            var baseWidth_:uint = W_ >> 3;
            var baseHeight_:uint = H_ >> 3;

            //細かい変化を何段階加えるか。例)大雑把な変化に細かい変化を加えるなら2。
            var octaves_:int = 4;

            //ランダムイメージの元。同じ値を指定すれば同じ結果を返す。
            var seed_:int = Math.floor(int.MAX_VALUE * Math.random());

            //上下・左右の端の内容が不連続で良ければfalse。
            var stitch_:Boolean = true;

            //入道雲のような塊はfalse、拡散した煙のようなムラはtrue。
            var fractal_:Boolean = true;

            //RGBの内容を一致させるならtrue、個別の内容にするならfalse。
            var gray_:Boolean = false;

            bmd.perlinNoise(
                baseWidth_, baseHeight_, octaves_, seed_, stitch_, fractal_,
                BitmapDataChannel.RED|BitmapDataChannel.GREEN|BitmapDataChannel.BLUE,
                gray_
            );

            bmd.colorTransform(new Rectangle(0, 0, W_, H_), new ColorTransform(
                0.75, 0.50, 1, 1, 0x3F, 0x7F
            ));

            var alpha_:Shape = new Shape();
            var g_:Graphics;
            g_ = alpha_.graphics;
            var matrix_:Matrix = new Matrix();
            matrix_.createGradientBox(200, 200);
            g_.beginGradientFill(
                GradientType.RADIAL,
                [0, 0],
                [0, 0.4],
                [63, 255],
                matrix_,
                SpreadMethod.PAD,
                InterpolationMethod.RGB
            );
            g_.drawEllipse(0, 0, 200, 200);
            g_.endFill(); 

            var mask_:BitmapData = new BitmapData(200, 200, true, 0x00000000);
            mask_.draw(alpha_);

            var target_:BitmapData = new BitmapData(200, 200, true, 0xFF000000);
            target_.copyPixels(bmd,
                new Rectangle(0, 0, 200, 200), new Point(),
                mask_, new Point(), false);

            bubble_ = new Bitmap(target_);
            addChild(bubble_);
            bubble_.y = H_>>1;
            bubble_.x = W_>>1;

            addEventListener(Event.ENTER_FRAME, update_);
        }

        public function update_ (event_:Event):void {
            var f_:Number = 0.2;
            vx_ += -f_ * vx_ + 3 * (Math.random() - 0.5);
            vy_ += -f_ * vy_ + 1 * (Math.random() + 0.5);

            var x_:Number = bubble_.x + vx_;
            if (x_ < -200) x_ += (W_ + 200);
            if (x_ > W_) x_ -= (W_ + 200);

            var y_:int = bubble_.y + vy_;
            if (y_ > H_) y_ -= (H_ + 200);

            vs_ = vs_ * 0.8 + 0.025 * (Math.random() - 0.5);

            bubble_.x = x_;
            bubble_.y = y_;
            bubble_.scaleX = 1 + vs_;
            bubble_.scaleY = 1 - vs_;
        }
    }
}