PerlinNoise Maker
Thanks to http://www.houseofthead.com/blog/flash-as3-perlin-noise-explained-and-demonstrated-part-1/#more-165
Click -> Randomize
♥2 |
Line 91 |
Modified 2014-06-16 11:55:46 |
MIT License
archived:2017-03-20 00:58:38
ActionScript3 source code
/**
* Copyright greentec ( http://wonderfl.net/user/greentec )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/kAW1
*/
package {
import com.bit101.components.Label;
import com.bit101.components.TextArea;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Point;
import com.bit101.components.Style;
public class FlashTest extends Sprite {
public var tileSprite:Sprite;
public var tileBitmapData:BitmapData;
public var tileBitmap:Bitmap;
public var randomSeed:int = Math.random() * int.MAX_VALUE;
public var offsets:Array = [];
public var speeds:Array = [];
public var numOctaves:int = 6;
public var numOctavesMax:int = 6;
public var channelOptions:int = Math.random() * 15 + 1;
public var stitch:Boolean = true;
public var fractalNoise:Boolean = false;
public var helpLabel:Label;
public var codeTextArea:TextArea;
public var codeString:String;
public function FlashTest() {
// write as3 code here..
var i:int;
for (i = 0; i < numOctaves; i += 1)
{
offsets[i] = new Point(0, 0);
speeds.push(new Point(Math.random()*8-4, Math.random()*8-4))
}
tileSprite = new Sprite();
addChild(tileSprite);
tileBitmapData = new BitmapData(400, 300, true);
tileBitmap = new Bitmap(tileBitmapData);
tileSprite.addChild(tileBitmap);
helpLabel = new Label(this, 10, 310, "numOctaves : " + String(numOctaves) + "\nrandomSeed : " + String(randomSeed) + "\nstitch : " + String(stitch) + "\nfractalNoise : " + String(fractalNoise) + "\nchannelOptions : " + String(channelOptions));
codeString = "perlinNoise(100, 100, " + String(numOctaves) + ", " + String(randomSeed) + " ," + String(stitch) + " ," + String(fractalNoise) + " ," + String(channelOptions) + " ,false ,[";
for (i = 0; i < numOctaves; i += 1)
{
codeString += "new Point(" + String(int(speeds[i].x*1000)/1000) + " ," + String(int(speeds[i].y*1000)/1000) + ")";
if (i != numOctaves - 1)
{
codeString += ", ";
}
}
codeString += "]);";
codeTextArea = new TextArea(this, 10, 380, codeString);
codeTextArea.width = 400;
codeTextArea.height = 50;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
stage.addEventListener(MouseEvent.CLICK, onMouseClick);
}
private function onMouseClick(e:MouseEvent):void
{
randomSeed = Math.random() * int.MAX_VALUE;
channelOptions = Math.random() * 15 + 1;
stitch = Math.random() < 0.5 ? true : false;
fractalNoise = Math.random() < 0.5 ? true : false;
numOctaves = Math.random() * 5 + 2;
var i:int;
for (i = 0; i < numOctavesMax; i += 1)
{
speeds[i] = new Point(Math.random() * 8 - 4, Math.random() * 8 - 4);
}
helpLabel.text = "numOctaves : " + String(numOctaves) + "\nrandomSeed : " + String(randomSeed) + "\nstitch : " + String(stitch) + "\nfractalNoise : " + String(fractalNoise) + "\nchannelOptions : " + String(channelOptions);
codeString = "perlinNoise(100, 100, " + String(numOctaves) + ", " + String(randomSeed) + " ," + String(stitch) + " ," + String(fractalNoise) + " ," + String(channelOptions) + " ,false ,[";
for (i = 0; i < numOctaves; i += 1)
{
codeString += "new Point(" + String(int(speeds[i].x*1000)/1000) + " ," + String(int(speeds[i].y*1000)/1000) + ")";
if (i != numOctaves - 1)
{
codeString += ", ";
}
}
codeString += "]);";
codeTextArea.text = codeString;
}
private function onEnterFrame(e:Event):void
{
var i:int;
for (i = 0; i < numOctaves; i += 1)
{
offsets[i].x += speeds[i].x;
offsets[i].y += speeds[i].y;
}
tileBitmapData.perlinNoise(100, 100, numOctaves, randomSeed, stitch, fractalNoise, channelOptions, false, offsets);
}
}
}