forked from: generate random maps with perlin
From http://www.emanueleferonato.com/2011/05/17/using-cellular-automata-to-generate-random-land-and-water-maps-with-flash/
copy-paste h_seldon comment
——————- import ———————-
/**
* Copyright abiyasa ( http://wonderfl.net/user/abiyasa )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/9E1S
*/
// forked from Albert's generate random maps with perlin
//From http://www.emanueleferonato.com/2011/05/17/using-cellular-automata-to-generate-random-land-and-water-maps-with-flash/
// copy-paste h_seldon comment
package {
import flash.display.AVM1Movie;
//——————- import ———————-
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.events.Event;
import flash.display.Sprite;
import flash.events.MouseEvent;
public class FlashTest extends Sprite {
//——————- vars ———————-
protected var bmTerrain:Bitmap;
protected var bmpTerrain:BitmapData;
protected var freqDivisor:Number = 0.5;
protected var octs:Number = 8;
protected var seed:Number = 12;
protected var stitch:Boolean = true;
protected var fractal:Boolean = true;
protected var channels:Number = 1;
protected var gray:Boolean = true;
protected var red:Array = new Array(256);
protected var green:Array = new Array(256);
protected var blue:Array = new Array(256);
protected var landBase:Number = 0xff808080;
protected var water:Number = 0xff8080ff;
//——————- start ———————-
public function FlashTest() {
// write as3 code here..
init();
stage.addEventListener(MouseEvent.CLICK, reset);
}
//——————- functions ———————-
public function init():void {
var i:int;
var max:int = 128;
var temp:int;
var theColor:uint;
for (i = 0; i < max; i++) {
temp = (i * 0x80) * max;
theColor = landBase + (temp << 8);
red[i] = green[i] = blue[i] = theColor;
}
for (i = 128; i < 256; i++) {
red[i]=green[i]=blue[i]=water;
}
bmpTerrain = new BitmapData(512,512);
bmpTerrain.perlinNoise(bmpTerrain.width*freqDivisor,bmpTerrain.height*freqDivisor,octs,seed,stitch,fractal,channels,gray);
bmpTerrain.paletteMap(bmpTerrain,new Rectangle(0,0,bmpTerrain.width,bmpTerrain.height),new Point(0,0),red,green,blue);
bmTerrain = new Bitmap(bmpTerrain);
addChild(bmTerrain);
}
public function destroy():void {
removeChild(bmTerrain);
bmTerrain=null;
bmpTerrain=null;
}
public function reset(e: MouseEvent=null):void {
destroy();
seed = Math.random()*2000;
init();
}
}
}