forked from: 雲海
雲海
* civet
* @dreamana.com
// forked from civet's 雲海
/**
* 雲海
* civet
* @dreamana.com
*/
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 rect:Rectangle;
private var seed:int;
private var sx:Number;
private var sy:Number;
private var vx:Number;
private var vy:Number;
private var ax:Number;
private var ay:Number;
private var offset:Point;
private var trans:ColorTransform;
public function Sora() {
createSky(stage.stageWidth, stage.stageHeight/2);
createCloud(stage.stageWidth, stage.stageHeight/2);
}
private function createSky(w:uint, h:uint):void {
var bg:Sprite = new Sprite();
var colors:Array = [0x09B6FF, 0xFFFFFF];
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();
addChild(bg);
createGround(w,h);
}
private function createGround(w:uint, h:uint):void {
var bg:Sprite = new Sprite();
var colors:Array = [0x7CFF44, 0x2F9900];
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();
bg.y = h;
addChild(bg);
}
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, 255,255,255, -200);
sx = 0;
sy = 0;
vx = Math.random()*8;
vy = Math.random()*8;
ax = Math.random()*0.02;
ay = Math.random()*0.02;
render();
//var t:Timer = new Timer(30);
//t.addEventListener(TimerEvent.TIMER, render);
//t.start();
addEventListener(Event.ENTER_FRAME, render);
}
private function render(e:Event=null):void {
for(var i:int=0;i<5;i++){
sx += vx;
sy += vy/10;
//seed += 1;
vx += ax;
vy += ay;
ax += Math.random()*0.02;
ay += Math.random()*0.02;
ax *= 0.9;
ay *= 0.9;
vx *= 0.95;
vy *= 0.95;
}
offset.x = int(sx);
offset.y = int(sy);
source.perlinNoise(250, 100, 4, seed, false, false, BitmapDataChannel.ALPHA, false, [offset]);
source.colorTransform(rect, trans);
}
}
}