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

whatever 3

bend a finite element chain with perlin noise
this is stupid though
Get Adobe Flash player
by wh0 30 Apr 2011
/**
 * Copyright wh0 ( http://wonderfl.net/user/wh0 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/cgCs
 */

package {
    import flash.geom.ColorTransform;
    import flash.display.*;
    import flash.events.*;
    public class FlashTest extends Sprite {
        
        private static const SEGMENTS:int = 64;
        private static const PERIOD:int = 60;
        private static const EPSILON:Number = 3;
        private static const CURVATURE:Number = Math.PI / 4 / 256;
        private static const FADE:ColorTransform = new ColorTransform(1, 1, 1, 1, -4, -8, -2, 0);
        
        private var sheet:BitmapData;
        private var time:int = 0;
        private var inst:Shape;
        private var canvas:BitmapData;
        private var tx:Number = NaN;
        private var ty:Number = NaN;
        
        public function FlashTest() {
            loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, function (e:UncaughtErrorEvent):void { Wonderfl.log(e.error); });
            sheet = new BitmapData(PERIOD * 10, SEGMENTS, false, 0x000000);
            sheet.perlinNoise(PERIOD, SEGMENTS, 2, new Date().getTime(), true, true, BitmapDataChannel.BLUE);
            inst = new Shape();
            canvas = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0x000000);
            addChild(new Bitmap(canvas));
            addEventListener(Event.ENTER_FRAME, frame);
        }
        
        private function frame(e:Event):void {
            var x:Number = 232.5;
            var y:Number = 232.5;
            var u:Number = Math.PI * 2 * time / sheet.width;
            inst.graphics.clear();
            inst.graphics.moveTo(x, y);
            for (var i:int = 0; i < SEGMENTS; i++) {
                var c:uint = sheet.getPixel(time, i);
                u += CURVATURE * ((c & 0xff) - 128);
                x += EPSILON * Math.cos(u);
                y += EPSILON * Math.sin(u);
                inst.graphics.lineStyle(2, 0xc080e0, Number(i) / SEGMENTS);
                inst.graphics.lineTo(x, y);
            }
            if (!isNaN(tx)) {
                inst.graphics.lineStyle(4, 0xffffff);
                inst.graphics.moveTo(tx, ty);
                inst.graphics.lineTo(x, y);
            }
            tx = x; ty = y;
            canvas.colorTransform(canvas.rect, FADE);
            canvas.draw(inst, null, null, BlendMode.ADD);
            time = (time + 1) % sheet.width;
        }
        
    }
}