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: forked from: [朝ワン]何か涼しそうなやつ > 麦

自家製ベジエ曲線にしてみたけど、ブレンドの仕方間違ってるのかなあ・・
// forked from dizgid's forked from: [朝ワン]何か涼しそうなやつ > 麦
// forked from bkzen's [朝ワン]何か涼しそうなやつ
// forked from hacker_ij48yrxl's flash on 2009-5-10
package 
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Graphics;
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.filters.BlurFilter;
    import flash.geom.ColorTransform;
    import flash.geom.Point;
    import net.hires.debug.Stats;
    
    // 自家製ベジエ曲線にしてみたけど、ブレンドの仕方間違ってるのかなあ・・
    [SWF(width="465", height="465", backgroundColor="0x000000", frameRate="60")]
    public class Asawon6 extends Sprite 
    {
        
        public static const PERLIN_WIDTH:int = 40;
        public static const PERLIN_HEIGHT:int = 60;
        public static const WIDTH:int = 500;
        public static const HEIGHT:int = 400;
        public static const num:Number = 255;
        
        private var px:Number = 0;
        private var offset:Array;
         private var bmd:BitmapData;
        private var p:Point;
        private var blur:BlurFilter;
        private var colorTf:ColorTransform;
        private var bmpData:BitmapData;
        
        private var _randPos:Array;
        
        public function Asawon6():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }
        
        private function init(e:Event = null):void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            
            stage.quality = "low";
            // entry point
            //filters = [new BlurFilter(4,0)];
            offset = [new Point(px += 0.5, 0), new Point( -px / 2, 0), new Point(0, 0)];
            bmpData = new BitmapData(PERLIN_WIDTH, PERLIN_HEIGHT, false);
            
            bmd = new BitmapData(465, 465, false, 0x0);
            p = new Point();
            blur = new BlurFilter(8, 8);
            colorTf = new ColorTransform(1, 1, 1, 1, -1, -10, -20, -5);
            createRandPos();
            
            addChild(new Bitmap(bmd, "auto", true));
            addChild(new Stats());
            
            addEventListener(Event.ENTER_FRAME, loop);
        }
        private function createRandPos():void
        {
            _randPos = [];
            for(var i:int=0; i < PERLIN_WIDTH * PERLIN_HEIGHT; i++){
                _randPos.push(Math.random()*20);
            }
        }
        
        private function loop(e:Event):void {
            Point(offset[0]).x = px += 0.8;
            Point(offset[1]).x = -px / 2;
            bmpData.perlinNoise(PERLIN_WIDTH, PERLIN_HEIGHT, 3, 6456, true, true, 2 | 1, false, offset);
            
            bmd.lock();
            //bmd.fillRect(bmd.rect, 0x0);
            bmd.colorTransform(bmd.rect, colorTf);
            bmd.applyFilter(bmd, bmd.rect, p, blur);
            for (var j:int = 0; j < PERLIN_HEIGHT - 1; j++) { 
                for (var i:int = 0; i < PERLIN_WIDTH - 1; i++) {
                    
                    var value1:uint = bmpData.getPixel(i, j) >>> 16;
                    var value2:uint = bmpData.getPixel(i + 1, j) >>> 16;
                    var rp : Number = _randPos[i * (PERLIN_HEIGHT - 1) + j];
                    drawCurve(bmd,
                        i * WIDTH / (PERLIN_WIDTH - 1) + rp -30, HEIGHT / 2 + j * 5 + 20,
                        value1 + i * WIDTH / (PERLIN_WIDTH - 1) -128 + rp -30,  HEIGHT / 2 + j * 4.5 - rp,
                        value1 + i * WIDTH / (PERLIN_WIDTH - 1) -128 + rp -30,  HEIGHT / 2 + j * 4.0 - rp, 
                        0x060c0c, 0.8
                    );
                }
            }
            bmd.unlock();
        }
        
        private static function drawCurve(bmd : BitmapData, x1 : Number, y1 : Number, xc : Number, yc : Number, x2 : Number, y2 : Number, color : uint, fill : Number = 1.0) : void
        {
            var nDiv : int = (
                Math.sqrt((xc - x1) * (xc - x1) + (yc - y1) * (yc - y1)) + 
                Math.sqrt((x2 - xc) * (x2 - xc) + (y2 - yc) * (y2 - yc))
                ) * fill + 1;
            for(var i : int = 0;i < nDiv;i++){
                var t : Number = i / nDiv;
                var x1c : Number = x1 + t * (xc - x1);
                var y1c : Number = y1 + t * (yc - y1);
                var xc2 : Number = xc + t * (x2 - xc);
                var yc2 : Number = yc + t * (y2 - yc);
                var xxx : int = x1c + t * (xc2 - x1c);
                var yyy : int = y1c + t * (yc2 - y1c);
                var col : uint = bmd.getPixel32(xxx, yyy);
//                var a : uint = (col >>> 24) + (color >>> 24); if(a > 255)a = 255;
                var r : uint = (col >>> 16 & 255) + (color >>> 16 & 255); if(r > 255)r = 255;
                var g : uint = (col >>> 8 & 255) + (color >>> 8 & 255); if(g > 255)g = 255;
                var b : uint = (col & 255) + (color & 255); if(b > 255)b = 255;
                bmd.setPixel(xxx, yyy, r << 16 | g << 8 | b);
            }
            
        }
    }
    
}