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

flash on 2013-6-11

Get Adobe Flash player
by mutantleg 11 Jun 2013
    Embed
/**
 * Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/q2YW
 */

package {
    import flash.geom.Point;
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import flash.events.Event;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
      
      
       
        public function FlashTest() {
            
            var num:int;
            var i:int;
            
            mwidth = 8;
            mheight = 8;
            
            num = mwidth * mheight;
            
            vecGrid = new Vector.<int>(num, false);
            
            for (i = 0; i < num; i++)
            {
                vecGrid[i] = Math.random() * 6;
            }//nexti

            
            bd = new BitmapData(8,8, false, 0);
            bd.perlinNoise(8,8,2, 32, true, true,1|2|4,true,null);
            pic = new Bitmap(bd);
            pic.scaleX = 8;
            pic.scaleY = 8;
            addChild(pic);
            
            stage.addEventListener(Event.ENTER_FRAME, onEnter);
        }//ctor
        
        public var vecGrid:Vector.<int>;
        public var mwidth:int = 0;
        public var mheight:int = 0;
        public var cw:Number = 32;
        public var ch:Number = 32;
      
          public var pic:Bitmap;
          public var bd:BitmapData;
          
          public var ax:Number = 0;
      
        public function onEnter(e:Event):void
        {
            graphics.clear();
            graphics.lineStyle(2,0);
            
            ax += 0.2;
            
            bd.lock();
             bd.perlinNoise(8,8,2, 32, true, true,1|2|4,true,[new Point(ax,0),new Point(0,ax)]);
            bd.unlock();
            
            var i:int;
            var k:int;
            var yt:int;
            var t:int;
            var g:int;
            var c:uint;
            
            var rx:Number; var ry:Number; var rz:Number;
            var sx:Number; var sy:Number;
            
            var kw:Number; var kh:Number;
            
            kw = cw * 0.5;
            kh = ch * 0.5;
            
            for (i = 0; i < mheight; i++)
            {
                yt = i * mwidth;
                for (k = 0; k < mwidth; k++)
                {
                     //t = vecGrid[yt+k];   
                    
                     t = (bd.getPixel(k, i) >> 16 ) / 24;
                
                      if (t > 8) { t = 8;}
                      
                     rx = k * cw;
                     ry = i * ch;
                     
                     for (g = 0; g < t; g++)
                     {
                         //optimisation hack thing (only draw top 2 when far)
                         //its not an universal solution, only really works with this perlin thing
                         if (k != mwidth-1)  
                         if (i != mheight-1)
                         if (g < t-2)
                          { g = t-2;}
                         
                     rz = g*16; //height
                     
                    sx = rx - ry;
                    sy = (rx*0.5)+(ry*0.5) - rz;
                    
                    //correction so we are somewhat center
                    sx += 200;
                    sy += 100;
                
                   //top
                   
                   //top should be lighter the higher it is
                   c = 0x202020 +(0x202020*g);
                   if (c > 0xd0d0d0) { c = 0xd0d0d0; }
                   
              
                   
                    graphics.beginFill(c, 1);
                    graphics.moveTo(sx, sy);
                    graphics.lineTo(sx+cw,sy+kh);  
                    graphics.lineTo(sx+cw-cw,sy+kh+kh);
                    graphics.lineTo(sx-cw, sy+kh);
                    graphics.lineTo(sx,sy);
                    graphics.endFill();   
                
                   //wall
                   
                    graphics.beginFill(0x202020,1);
                    graphics.moveTo(sx+cw,sy+kh);  
                    graphics.lineTo(sx+cw,sy+kh+kh);  
                    graphics.lineTo(sx+cw-cw,sy+kh+kh+kh);
                    graphics.lineTo(sx+cw-cw,sy+kh+kh);
                    graphics.endFill();
                    
                    
                    graphics.beginFill(0x404040,1);
                    graphics.moveTo(sx-cw, sy+kh);
                    graphics.lineTo(sx-cw, sy+kh+kh);
                    graphics.lineTo(sx+cw-cw,sy+kh+kh+kh);
                    graphics.lineTo(sx+cw-cw,sy+kh+kh);
                    graphics.endFill();
                     }//nextg
                    
                
                }//nextk
            }//nexti
            
            
        }//onenter
        
        
        
    }//classend
}