飛行機からみた風景っぽく [PerlinNoise]
/**
* Copyright mousepancyo ( http://wonderfl.net/user/mousepancyo )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/vWP1
*/
package {
import flash.events.Event;
import flash.display.Sprite;
[SWF(width="465", height="465", backgroundColor="0", frameRate="30")]
public class Main extends Sprite{
public function Main(){
var sky:Base = new Base(stage.stageWidth, stage.stageHeight)
addChild(sky)
var cloud:PerlinNoiseEx = new PerlinNoiseEx(stage.stageWidth, stage.stageHeight)
cloud.blendMode = "screen"
addChild(cloud)
addEventListener(Event.ENTER_FRAME, cloud.update)
}
}
}
//
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BitmapDataChannel
import flash.events.Event;
import flash.display.Sprite;
import flash.geom.Point
import flash.geom.ColorTransform;
import flash.geom.Rectangle;
import flash.filters.ConvolutionFilter;
import flash.geom.Matrix;
class PerlinNoiseEx extends Sprite{
private var _bmd:BitmapData
private var _oct:int
private var _seed:Number
private var _channels:uint
private var _offset:Array = new Array()
private var _speed:Array = new Array()
private var _bm:Bitmap
private var _color:ColorTransform
private var _w:int
private var _h:int
public function PerlinNoiseEx(w:int, h:int){
_w = w
_h = h
_bmd = new BitmapData(_w, _h, false, 0x000000);
_oct = 12
_seed = Math.floor(Math.random() * 100);
_channels = BitmapDataChannel.RED | BitmapDataChannel.BLUE | BitmapDataChannel.GREEN;
_bm = new Bitmap(_bmd);
_bm.blendMode = "add"
addChild(_bm);
//
for(var i:int; i<_oct; i++){
_offset[i] = new Point(Math.random()*_w, Math.random()*_h);
_speed[i] = new Point(-1, Math.random()*1-0.5);
}
}
public function update(e:Event):void{
for(var i:int; i<_oct; i++){
_offset[i].x += _speed[i].x;
_offset[i].y += _speed[i].y;
}
_bmd.perlinNoise(_w, _h/2, _oct, _seed, true, true, _channels, true, _offset);
var mat:Array = [0,1,0,
1,1,1,
0,1,0]
_bmd.applyFilter(_bmd, new Rectangle(0,0,465,465),new Point(0,0),new ConvolutionFilter(3,3,mat,3,0))
}
}
import flash.display.Sprite
class Base extends Sprite{
public function Base(w:int,h:int):void{
var colors:Array = [0xFFFFFF, 0x0063F9, 0x666600]
var alphas:Array = [1, 1, 1]
var ratios:Array = [50, 127, 245]
var mat:Matrix = new Matrix()
mat.rotate(Math.PI / 180 * 90);
graphics.beginGradientFill("linear", colors, alphas, ratios, mat)
graphics.drawRect(0,0,w,h)
graphics.endFill()
}
}