forked from: 雲海
夜空っぽくなったかな?
色の問題だけのような気もします
// forked from civet's 雲海
// 夜空っぽくなったかな?
// 色の問題だけのような気もします
package {
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BitmapDataChannel;
import flash.display.GradientType;
import flash.display.SpreadMethod;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.filters.DropShadowFilter;
import flash.geom.ColorTransform;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.utils.Timer;
[SWF(frameRate='24', backgroundColor='0x000000')]
public class Sora extends Sprite {
private var source:BitmapData;
private var sky:BitmapData;
private var stars:Number = 40;
private var rect:Rectangle;
private var seed:int;
private var offset:Point;
private var trans:ColorTransform;
public function Sora() {
createSky(stage.stageWidth, stage.stageHeight);
createCloud(stage.stageWidth, stage.stageHeight);
}
private function createSky(w:uint, h:uint):void {
var bg:Sprite = new Sprite();
var colors:Array = [0x141c25, 0x1f2a36];
var alphas:Array = [1, 1];
var ratios:Array = [0x00, 0xFF];
var mat:Matrix = new Matrix();
mat.createGradientBox(w, h, Math.PI/2, 0, 0);
bg.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, mat, SpreadMethod.PAD);
bg.graphics.drawRect(0, 0, w, h);
bg.graphics.endFill();
sky = new BitmapData(w, h, true);
sky.draw(bg);
// 星たち
for(var i:Number = 0; i < stars; i++) {
sky.setPixel(Math.random() * w, Math.random() * h, 0x475769);
}
var bmp:Bitmap = new Bitmap(sky);
addChild(bmp);
}
private function createCloud(w:uint, h:uint):void {
source = new BitmapData(w, h, true, 0);
var bmp:Bitmap = new Bitmap(source);
addChild(bmp);
//bmp.filters = [new DropShadowFilter(4, 45, 0xb3b3b3)];
rect = new Rectangle(0, 0, source.width, source.height);
seed = Math.random()*100;
offset = new Point();
trans = new ColorTransform(1,1,1,2, 45,60,80, -200);
render();
var t:Timer = new Timer(500);
t.addEventListener(TimerEvent.TIMER, render);
t.start();
}
private function render(e:Event=null):void {
offset.x += 8;
source.perlinNoise(256, 100, 4, seed, false, true, BitmapDataChannel.ALPHA, false, [offset]);
source.colorTransform(rect, trans);
}
}
}