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

Perlin Noise Generator

Space - random
Z - show / hide text
Enter - Play / Pause update
Left mouse - change baseX & baseY
( button ) - fullscreen
Right Mouse - switch background ( B/W/All )
Toogle RGBA channels - 1,2,3,4
Switch Octaves - O
Randomize seed - S
Switch Bitmap scale - B
Toogle Stitch - T
Toogle Grayscale - G
Toogle Fractal Noise - F
Randomize Velocities - V

Press 5,6,7,8 to randomize single octave velocity.

Each time a variables is changed, the new results are copied to clipboard.
Get Adobe Flash player
by WLAD 08 Jan 2016
    Embed
/**
 * Copyright WLAD ( http://wonderfl.net/user/WLAD )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/eRv8
 */

package  
{
	import com.bit101.components.PushButton;
	import net.hires.debug.Stats;
	import flash.display.Sprite;
	import flash.filters.DropShadowFilter;
	import flash.geom.Point;
	import flash.system.System;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.ui.Keyboard;
	[SWF(width = "465", height = "465" )]
	public class PerlinGenerator extends Sprite 
	{
		static private var W:int = 465;
		static private var H:int = 465;
		
		public function PerlinGenerator() 
		{
			stage.quality = 'low'; stage.frameRate = 20;
			stage.align = 'tl';	stage.scaleMode = 'noScale';
			changeBackground();
			
			var stats:Stats = Stats(addChild( new Stats() ));

			var debug:String = "";
			
			var btn:PushButton = new PushButton(this, 0, 0, "Fullscreen", function(e:*= null):void {
				pScale = 6;
				perlin.octaves = 2;
				stage.displayState = 'fullScreen';
				outData();
			});
			
			var pScale:int = 2;
			var state:Boolean = true;	
			var perlin:BitmapPerlin = new BitmapPerlin(100,100,this);
			var resize:Function = function( scale:Number = 2 ):void
			{
				perlin.resize( W / scale, H / scale );
				perlin.display.scaleX = perlin.display.scaleY = scale;
				btn.x = W * .5 - btn.width * .5;
				btn.y = H - btn.height;
				stats.x = W - stats.width;
			};
			
			resize( pScale );
			
			perlin.baseX = perlin.baseY = 100;
			perlin.octaves = 3;
			perlin.setChannel( false, false, false, true );
			perlin.setVelocities( 2, 1.5, -3, 4, 0, 2 );
			
			var outData:Function = function():void {
				text.text = "[Space] Randomize" +
					"\n[ENTER] Play / Pause" + 
					"\nBase[X]:\t" + perlin.baseX.toFixed(1) + 
					"\nBase[Y]:\t" + perlin.baseY.toFixed(1) + 
					"\n[O]ctaves:\t" + String( perlin.octaves ) + 
					"\n[S]eed:\t" + String( perlin.seed ) + 
					"\nchR[1]:\t" + String( chR ) + 
					"\nchG[2]:\t" + String( chG ) + 
					"\nchB[3]:\t" + String( chB ) + 
					"\nchA[4]:\t" + String( chA ) +
					"\nchannel =\t" + String( perlin.channel ) +
					"\n[B]itmap Sacle:\t" + String( pScale ) +
					"\ns[T]itch:\t" + String( perlin.stitch ) +
					"\n[G]rayScale:\t" + String( perlin.grayScale ) +
					"\nfractalNoise[F]:\t" + String( perlin.fractalNoise );
				
				var S:String = "";
				for ( var V:int = 0; V < perlin.octaves; ++V )
					S += perlin.getVelocity( V ).toString() + 
					( V < perlin.octaves - 1 ? "\n \t" : "" );
				text.text += "\n[V]el:\t" + S;
				S = perlin.toString();
				System.setClipboard( S + ", sacle:\t" + pScale );
				text.text += /*"\n\nRaw =\t" + S.split(',').join(' , ') + */"\nCopied to clipboard";
				text.htmlText = "<TEXTFORMAT TABSTOPS='[" + String( int(W/2) ) + "]'>" + text.text + "</TEXTFORMAT>";
			};
			stage.addEventListener('resize', function(e:*):void {
				W = stage.stageWidth;
				H = stage.stageHeight;
				changeBackground( bgindex );
				resize( pScale );
				text.width = W / textS;
				text.height = H / textS;
                                
			});
			
			var rndVel:Function = function():Point { 
				return new Point( randomInt( -100, 100) / 10, randomInt( -100, 100) / 10 );
			};
			
			var chR:Boolean = false;var chG:Boolean = false;
			var chB:Boolean = false;var chA:Boolean = true;
			stage.addEventListener('keyDown', function(e:*):void {
				
				
				switch(e.keyCode)
				{
					
					case Keyboard.NUMBER_5:
						if ( perlin.octaves > 0 )
							perlin.setVelocity(0, rndVel() );
						break;
					case Keyboard.NUMBER_6:
						if ( perlin.octaves > 1 )
							perlin.setVelocity(1, rndVel() );
						break;
					case Keyboard.NUMBER_7:
						if ( perlin.octaves > 2 )
							perlin.setVelocity(2, rndVel() );
						break;
					case Keyboard.NUMBER_8:
						if ( perlin.octaves > 3 )
							perlin.setVelocity(3, rndVel() );
						break;
					
					case Keyboard.ENTER: 
						state = !state;
						break;
					case Keyboard.B:
						if ( ++pScale > 6 ) pScale = 1;
						resize( pScale );
						break;
					case Keyboard.Z:
						text.visible = !text.visible;
						return;
					case Keyboard.SPACE: 
						perlin.random(256, 1);
						chR = RBool; chG = RBool; chB = RBool;	chA = RBool;
						perlin.setChannel( chR, chG, chB, chA );
						while ( perlin.channel == 0 )  { 
							chR = RBool; chG = RBool; chB = RBool;	chA = RBool;
							perlin.setChannel( chR, chG, chB, chA );
						}
						changeBackground(chA?1:0);
					case Keyboard.O:
						if ( perlin.octaves == 4 ) perlin.octaves = 1;
						else perlin.octaves ++;
					case Keyboard.V:
						for ( var i:int = 0; i < perlin.octaves; i++ )
						perlin.setVelocity( i, rndVel() );
						break;
						
						
					case Keyboard.T:
						perlin.stitch = !perlin.stitch;
						break;
					case Keyboard.G:
						perlin.grayScale = !perlin.grayScale;
						break;
					case Keyboard.S:
						perlin.seed = randomInt(100, 100000);
						break;
					case Keyboard.F:
						perlin.fractalNoise = !perlin.fractalNoise;
						break;
					case Keyboard.NUMBER_1: 
						chR = !chR; break;
					case Keyboard.NUMBER_2: 
						chG = !chG; break;
					case Keyboard.NUMBER_3: 
						chB = !chB; break;
					case Keyboard.NUMBER_4: 
						chA = !chA; break;
				}
				if ( e.keyCode > 48 && e.keyCode < 53 ) 
					perlin.setChannel( chR, chG, chB, chA );
				
				outData();
				if( !state ) perlin.update();
			});
			
			stage.addEventListener('rightMouseDown', function(e:*):void{
				
				changeBackground();
				
			});
			stage.addEventListener('enterFrame', function(e:*):void 
			{
				if( state ) perlin.update();
				stats.visible = text.visible;
			});
			stage.addEventListener('mouseDown', function(e:*):void {
				
				var border:int = 30;
				var mx:Number = ( stage.mouseX - border ) / ( W - border * 2 );
				var my:Number = ( stage.mouseY - border ) / ( H - border * 2 );
				mx = mx < 0 ? 0 : ( mx > 1 ? 1 : mx );
				my = my < 0 ? 0 : ( my > 1 ? 1 : my );
				
				perlin.baseX = mx * 256 + 16;
				perlin.baseY = my * 256 + 16;
				
				outData();
			});
			
			var text:TextField = new TextField();
			addChild( text );
			text.defaultTextFormat = new TextFormat('_sans');
			text.textColor = 0xFFFFFF;
			text.mouseEnabled = false;
			text.filters = [ new DropShadowFilter(0, 0, 0, 1, 5, 5, 3) ];
			var textS:Number = 1;
			text.width = W / textS;
			text.height = H / textS;
			text.wordWrap = true;
			text.multiline = true;
			text.scaleX = text.scaleY = textS;
			text.x = text.y = 7;  
			text.text = "Controls: leftMouse,rightMouse,1,2,3,4,F,T,V,G,O,S\nPress [Z] To hide show the text\nPress [Space] To randomize most of the values";
                        
                        stage.addChild( text );
                        stage.addChild( stats );
                        
		}
		
		private var bgindex:int = 0;
		private function changeBackground( newVal:int  = -1 ):void {
			if ( newVal != -1 ) bgindex = newVal -1;
			if ( ++bgindex > 2 ) bgindex = 0;
			if ( bgindex < 2 )
			{
				graphics.clear(); graphics.beginFill( bgindex*0xFFFFFF );
				graphics.drawRect(0, 0, W, H); graphics.endFill();
				return;
			}
			
			graphics.clear(); 
			graphics.beginFill(0xFFFFFF);
			graphics.drawRect(0, 0, W*.5, H*.5);
			graphics.beginFill(0);
			graphics.drawRect(W*.5, 0, W*.5, H*.5);
			graphics.beginFill(0xFF0000);
			graphics.drawRect(0, H*.5, W*.333, H*.5);
			graphics.beginFill(0x00FF00);
			graphics.drawRect(W*.333, H*.5, W*.333, H*.5);
			graphics.beginFill(0x0000FF);
			graphics.drawRect(W*.666, H*.5, W*.333, H*.5);
			
			graphics.endFill();
		}
		
	}

}

import flash.display.BitmapData; import flash.display.Bitmap; import flash.display.DisplayObject; import flash.display.DisplayObjectContainer; import flash.geom.Point; class BitmapPerlin { static public var PIXEL_SNAPPING:String = "auto"; static public var SMOOTHING:Boolean = false; public var baseX:Number = 0; public var baseY:Number = 0; public var seed:uint = 0; public var channel:uint = 7; public var stitch:Boolean = true; public var fractalNoise:Boolean = false; public var grayScale:Boolean = false; private var listOffset:Array; private var listVelocity:Vector.<Point>; private var targetContainer:DisplayObjectContainer; private var targetBitmap:Bitmap; private var targetBitmapData:BitmapData; public function BitmapPerlin(W:uint, H:uint, parent:DisplayObjectContainer = null) { grayScale = false; fractalNoise = false; stitch = true; channel = 7; targetContainer = parent; resize(W, H); random(); } public function get display():DisplayObject { return targetBitmap; } public function resize(W:uint, H:uint):void { disposeBitmap(); targetBitmapData = new BitmapData(W, H, true); targetBitmap = new Bitmap(targetBitmapData, PIXEL_SNAPPING, SMOOTHING); if (targetContainer) targetContainer.addChild(targetBitmap); } public function setChannel(RED:Boolean = true, GREEN:Boolean = true, BLUE:Boolean = true, ALPHA:Boolean = false):void { channel = (RED?1 : 0) | (GREEN?2 : 0) | (BLUE?4 : 0) | (ALPHA?8 : 0); } public function random(maxBase:int = 256, maxOctave:int = 3, maxSeed:int = 100000):void { baseX = randomNum(32, maxBase); baseY = randomNum(32, maxBase); octaves = randomInt(1, maxOctave); seed = randomInt(1, maxSeed); channel = randomInt(9, 15); } public function setVelocities(...arguments):void { for (var i:int = 0; i < arguments.length; i += 2) setVelocity(int(i / 2), new Point(Number(arguments[i]), Number(arguments[i + 1]))); } public function getVelocity(OctaveNumber:uint):Point { if (OctaveNumber < 0 || OctaveNumber > octaves - 1) return null; return listVelocity[OctaveNumber]; } public function setVelocity(OctaveNumber:uint, Velocity:Point):void { if (OctaveNumber < 0 || OctaveNumber > octaves - 1) return; listVelocity[OctaveNumber] = Velocity.clone(); } public function toString():String { var S:String = ""; for (var V:int = 0; V < listVelocity.length;++V) S += listVelocity[V].x.toFixed(1) + "," + listVelocity[V].y.toFixed(1) + (V < listVelocity.length - 1?",":""); return"{x:" + baseX.toFixed(1) + ",y:" + baseY.toFixed(1) + ",sd:" + seed + ",c:" + channel + ",f:" + int(fractalNoise) + ",g:" + int(grayScale) + ",st:" + int(stitch) + ",o:" + octaves + ",v:[" + S + "]}"; } public function update(TimeScale:Number = 1):void { for (var i:int = 0; i < octaves;++i) { listOffset[i].x += listVelocity[i].x * TimeScale; listOffset[i].y += listVelocity[i].y * TimeScale; } targetBitmapData.perlinNoise(baseX, baseY, octaves, seed, stitch, fractalNoise, channel, grayScale, listOffset); } public function get octaves():int { return listOffset?listOffset.length : 0; } public function set octaves(v:int):void { if (listOffset == null) listOffset = new Array(); while (listOffset.length > v) listOffset.pop(); while (listOffset.length < v) listOffset.push(new Point()); if (listVelocity == null) listVelocity = new Vector.<Point>(); while (listVelocity.length > v) listVelocity.pop(); while (listVelocity.length < v) listVelocity.push(new Point()); } public function dispose():void { disposeBitmap(); octaves = 0; targetContainer = null; } private function disposeBitmap():void { if (targetBitmapData) { targetBitmapData.dispose(); targetBitmapData = null; } if (targetBitmap) { targetBitmap.parent?targetBitmap.parent. removeChild(targetBitmap):null; targetBitmap = null; }}} function randomNum( min:Number, max:Number = 0 ):Number { if ( max == 0 ) return Math.random() * min; return Math.random() * ( max - min ) + min; } function randomInt( min:int, max:int ):int { return min + int( Math.random() * ( ( max - min) + 1) ) } function get RBool():Boolean { return randomInt(0, 1) == 0; }