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: perlinNoise遊び ぐねぐね動かしてみた

オフセットいじってぐねぐね
Get Adobe Flash player
by postnum 07 Jun 2011
/**
 * Copyright postnum ( http://wonderfl.net/user/postnum )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/w5Dh
 */

// forked from cpu_t's perlinNoise遊び
// クリックでリセット。
// 
// rが明るさ
// gがx方向の移動距離
// bがy方向の移動距離
// 
package {
	import flash.display.Bitmap;
	import flash.display.BitmapData;
    import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	[SWF(width = '465', height = '465', backgroundColor = '#000000', frameRate = '60')]
    
	public class FlashTest extends Sprite
	{
		private var vectormap:BitmapData;
		private var bmpdata:BitmapData;
		private var seed:uint = Math.random() * 0xFFFFFFFF;
		private var offset:Array = [];

        public function FlashTest()
		{
            vectormap = new BitmapData(465 * .2, 465 * .2);
			
			bmpdata = new BitmapData(465, 465, false, 0);
			addChild(new Bitmap(bmpdata));
			
			for (var i:int = 0; i < 3; i++) 
			{
				offset[i] = new Point(0, 0);
			}

			addEventListener(Event.ENTER_FRAME, onEF);
        }
		
		private function onEF(event:Event):void 
		{
			offset[0].x += 1;
			offset[0].y += 1;
			//offset[1].x += 1;
			//offset[1].y += 1;
			//offset[2].x += 1;
			//offset[2].y += 1;
			
			//vectormap.perlinNoise(465 * .2, 465 * .2, 3, seed, false, true, 7, false, offset);
			vectormap.perlinNoise(465 * .1, 465 * .1, 3, seed, false, true, 7, false, offset);
			
			// bmpdataをクリア
			bmpdata.fillRect(bmpdata.rect, 0);
			
			// vectormapの全ピクセルに対してループ
			for (var y:int = 0; y < vectormap.height; y++)
			{
				for (var x:int = 0; x < vectormap.width; x++)
				{
					// rgb要素を取得
					var px:uint = vectormap.getPixel(x, y);
					var r:int = px >> 16 & 0xFF;
					var g:int = px >> 8 & 0xFF;
					var b:int = px & 0xFF;
					
					// x,yにg,bを足す
					var tx:int = (x / .2) + (g / 0xFF - .5) * 465;
					var ty:int = (y / .2) + (b / 0xFF - .5) * 465;
					
					// bmpdataの範囲外になってしまったらcontinue
					if (ty<0 || ty>=bmpdata.height ||
						tx<0 || tx>=bmpdata.width) continue;
					var col:uint = bmpdata.getPixel(tx, ty);
					col += 0x010101 * (int)(r * .4);
					if (col > 0xFFFFFF) col = 0xFFFFFF;
					bmpdata.setPixel(tx, ty, col);
				}
			}
		}
    }
}