forked from: forked from: 飛行機からみた風景っぽく [PerlinNoise]
/**
* Copyright Etienne.Verhote ( http://wonderfl.net/user/Etienne.Verhote )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/1NRp
*/
// forked from thaiha2t's forked from: 飛行機からみた風景っぽく [PerlinNoise]
// forked from mousepancyo's 飛行機からみた風景っぽく [PerlinNoise]
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, 0x99999999);
_oct = 12
_seed = Math.floor(Math.random() * 100);
_seed = 76;
_channels = BitmapDataChannel.ALPHA | 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/9, Math.random()*_h/9);
_offset[i] = new Point(1, 1);
_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, _oct, _seed, false, false, _channels, false, _offset);
_bmd.perlinNoise(_w, _h, _oct, _seed, false, false, 9, false, _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 = [0x000000, 0x000000, 0x000000]
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()
}
}