MilkyWay (perlinNoise)
/**
* Copyright yd_niku ( http://wonderfl.net/user/yd_niku )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/gVN8
*/
package {
import flash.events.*;
import flash.geom.*;
import flash.display.*;
import flash.filters.*;
[SWF(backgroundColor=0x000000)]
public class FlashTest extends Sprite {
private var _seed:Number;
private var _twinkles:BitmapData;
private var _noise:BitmapData;
private var _milkyway:BitmapData;
private var _canvas:BitmapData;
private var _blur :BlurFilter
public function FlashTest() {
// write as3 code here..
_milkyway = new BitmapData(465,465,true,0x00);
_canvas = _milkyway.clone();
addChild( new Bitmap(_canvas) );
_noise = _canvas.clone();
_noise.noise(Math.random(),0,255,1,true);
_twinkles = new BitmapData(465>>1,465>>1,false,0x00);
var tw:Bitmap = new Bitmap(_twinkles);
tw.smoothing = true;
tw.scaleX = tw.scaleY= 2;
addChildAt(tw,0 );
_offset = new Point();
_seed = Math.random();
_blur = new BlurFilter(8,8,3);
addEventListener(Event.ENTER_FRAME,update);
}
private var _orgPoint:Point = new Point();
private var _offset:Point;
private var _ctf:ColorTransform = new ColorTransform(0.95,0.95,0.98,0.97);
private function update(e:Event):void{
_offset.x += -(mouseX/465-0.5)*5;
_offset.y += -(mouseY/465-0.5)*5;
//_canvas.fillRect(_canvas.rect,0x00);
_milkyway.perlinNoise(128,256,2,_seed,true,true,1, true, [ _offset ]);
_milkyway.draw(_noise,null,null,BlendMode.OVERLAY);
_milkyway.threshold(_milkyway,_milkyway.rect,_orgPoint,"<",0xFFE50000,0x00000000,0xFFFFFFFF,false);
_canvas.applyFilter(_canvas,_canvas.rect,_orgPoint,_blur );
_canvas.draw(_milkyway);
_canvas.colorTransform(_canvas.rect,_ctf);
//_twinkles.fillRect(_twinkles.rect,0x00);
//_twinkles.draw(_milkyway, new Matrix(0.5,0,0,0.5));
}
}
}