パーリンノイズ勉強 曲線
パーリンノイズを作って、その色の値を使って曲線を描く。
/**
* Copyright sakef ( http://wonderfl.net/user/sakef )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/rAXz
*/
package
{
import flash.display.BitmapData;
import flash.display.BitmapDataChannel;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Point;
[SWF(width="465", height="465", backgroundColor="0x000000", frameRate="30")]
public class Main extends Sprite
{
private var bmpd:BitmapData;
private var seed:Number;
private var offset:Array;
public function Main()
{
bmpd=new BitmapData(500, 100, false, 0xFFFFFF);
seed=Math.floor(Math.random() * 10);
offset=[new Point(0, 0), new Point(0, 0)];
addEventListener(Event.ENTER_FRAME, onFrame);
}
private function onFrame(e:Event):void
{
// パーリンノイズを生成
bmpd.perlinNoise(500, 500, 2, seed, true, true, BitmapDataChannel.RED, false, offset);
offset[0].x += 10;
offset[1].y += 1;
// 曲線を描写
graphics.clear();
drawLine(graphics, 0, bmpd, 0xff0000);
drawLine(graphics, 25, bmpd, 0x00ffff);
drawLine(graphics, 50, bmpd, 0x00ff00);
drawLine(graphics, 75, bmpd, 0x0000ff);
drawLine(graphics, 99, bmpd, 0xffff00);
}
// 曲線を描く関数
private function drawLine(g:Graphics, y:Number, source:BitmapData, color:uint):void
{
g.lineStyle(1, color);
for(var i:int=0 ; i<500 ; i+=20)
{
if(i==0) g.moveTo(i, (source.getPixel(i,y)>>16)*1.5);
else g.lineTo(i,(source.getPixel(i,y)>>16)*1.5);
}
g.endFill();
}
}
}