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

CLICK TO RANDOMIZE
@author SPANVEGA // CHRISTIAN
Get Adobe Flash player
by 0xABCDEF 04 Oct 2011
/**
 * Copyright 0xABCDEF ( http://wonderfl.net/user/0xABCDEF )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/lUqy
 */

// forked from spanvega's TERRACES
package
{
    // CLICK TO RANDOMIZE

    import flash.events.*;
    import flash.display.*;

    import flash.geom.Point;
    import flash.geom.Matrix;
    import flash.geom.ColorTransform;

    import frocessing.color.ColorHSV;

    /**  @author SPANVEGA // CHRISTIAN  **/

    [ SWF (width = '465', height = '465', backgroundColor = '0x000000', frameRate = '25')]
    
    public class TERRACES extends Sprite
    {
        private var c_trs : ColorTransform = new ColorTransform (1, 1, 1, 0.99);

        private var color : ColorHSV = new ColorHSV (Math.random() * 360);

        private var g_val : Vector.<IGraphicsData> = new <IGraphicsData>[];
        private var g_dat : Vector.<Number> = new <Number>[];
        private var g_com : Vector.<int> = new <int>[];

        private var g_str : GraphicsStroke = new GraphicsStroke (1);
        private var g_pat : GraphicsPath;

        private var image : BitmapData, map : BitmapData;
        private var shape : Shape = new Shape ();

        private var W : Number, H : Number;
        private var trans : Number = -1;

        //

        private var pn_of : Point = new Point (2, 2);
        private var pn_v1 : Point = new Point ();
        private var pn_v2 : Point = new Point ();
        private var pn_bx : Number;
        private var pn_by : Number;
        private var pn_sd : int;


        public function TERRACES ()
        {
            Wonderfl.disable_capture ();

            stage ? init () : addEventListener (Event.ADDED_TO_STAGE, init);
        }

        private function init (e : Event = null) : void
        {
            if (hasEventListener (Event.ADDED_TO_STAGE))
            {
                removeEventListener (Event.ADDED_TO_STAGE, init);
            }

            stage.scaleMode = 'noScale';
            stage.align = 'TL';

            H = stage.stageHeight;
            W = stage.stageWidth;

            graphics.beginFill (0, 1);
            graphics.drawRect  (0, 0, W, H);

            //

            addChild (new Bitmap (image = new BitmapData (W, H)));

            map = new BitmapData (W, 1);

            setGraphicsCommands ();

            setRandom ();

            //

            stage.addEventListener (Event.ENTER_FRAME, setRender);
            stage.addEventListener (MouseEvent.CLICK, setRandom);
        }

        private function setRender (e : Event) : void
        {
            setUpdateMap ();

            //

            shape.graphics.clear ();

            g_str.fill = new GraphicsSolidFill (color.value, 1);

            for (var i : int = 0; i < map.width; i ++)
            {
                g_dat.push
                (
                    i, (H / 1.75 - 0xE8) + ((map.getPixel (i, 0) & 0xE8) * 2)
                )
            }
            g_dat.push( W, H );
            g_dat.push( 0, H );

            g_pat = new GraphicsPath (g_com, g_dat);
            
            g_val.push( g_str.fill );
            g_val.push (g_str, g_pat);

            shape.graphics.drawGraphicsData (g_val);

            g_dat.length = g_val.length = 0;

            //

            image.colorTransform (image.rect, c_trs);
            image.scroll (0, trans);
            image.draw (shape);

            color.h += 0.5;
        }

        private function setRandom (e : MouseEvent = null) : void
        {
            pn_sd = Math.random () * 0xFFFFFF;
            pn_bx = W * 0.4 + (Math.random () * W * 0.6);
            pn_by = H * 0.4 + (Math.random () * H * 0.6);

            image.fillRect (image.rect, 0);
        }

        private function setGraphicsCommands () : void
        {
            g_com = new <int> [1];
 
            for (var c : int = 1; c < map.width+2; c++)
            {
                g_com.push (2);
            }
        }

        private function setUpdateMap () : void
        {
            pn_v1.x =- (pn_v2.x += pn_of.x);
            pn_v1.y =- (pn_v2.y += pn_of.y);

            map.perlinNoise
            (
                pn_bx, pn_by, 2, pn_sd, false,
                true, 1, true, [pn_v1, pn_v2]
            );
        }
    }
}