春の麗らの
package {
import flash.display.*;
import flash.filters.*;
import flash.geom.*;
import flash.events.*;
[SWF(width=320,height=320,backgroundColor=0x669999,frameRate=24)]
public class Take04 extends Sprite {
private const SW:Number = stage.stageWidth;
private const SH:Number = stage.stageHeight;
private var petalStage:Sprite;
private var fDisplace:DisplacementMapFilter;
private var petalBmd:BitmapData;
private var streamBmd:BitmapData;
private var streamBmdBase:BitmapData;
private var fStream:DisplacementMapFilter;
private var mapPointX:int = 0;
public function Take04():void {
// 川面の流れMapを作る
streamBmdBase = new BitmapData(SW*2,SH);
streamBmdBase.perlinNoise(20,10,1,1,true,true,1,false,[]);
var revSprite:Shape = new Shape();
revSprite.graphics.beginBitmapFill(streamBmdBase);
revSprite.graphics.drawRect(0,0,SW*2,SH);
revSprite.graphics.endFill();
revSprite.scaleX = -1;
var revStream:BitmapData = new BitmapData(SW*2,SH);
revStream.draw(revSprite);
streamBmdBase.copyChannel(revStream,revStream.rect,new Point(0,0),0xff0000,0xff0000);
streamBmd = new BitmapData(SW*2,SH);
streamBmd.copyPixels(streamBmdBase, new Rectangle(SW,0,SW*2,SH), new Point(0,0));
// うねりを描画
fStream = new DisplacementMapFilter();
fStream.mapBitmap = streamBmd;
fStream.componentX = BitmapDataChannel.RED;
fStream.componentY = BitmapDataChannel.RED;
fStream.scaleX = 8;
fStream.scaleY = 8;
fStream.mapPoint = new Point(40,40);
fStream.mode = DisplacementMapFilterMode.IGNORE;
// 描画ステージを作る
var mainStage:Sprite = new Sprite();
mainStage.graphics.drawRect(-40,-40,SW+80,SH+80);
addChild(mainStage);
// 背景用のBitmapDataを作る
var bg:Background = new Background(SW+80,SH+80);
var bgBmd:BitmapData = new BitmapData(SW+80,SH+80,true,0x000000);
bgBmd.draw(bg);
// 背景を描画
var bgShape:Shape = new Shape();
bgShape.graphics.beginBitmapFill(bgBmd);
bgShape.graphics.drawRect(0, 0, SW+80, SH+80);
bgShape.graphics.endFill();
bgShape.x = -40;
bgShape.y = -40;
mainStage.addChild(bgShape);
mainStage.filters = [fStream];
mainStage.addEventListener(Event.ENTER_FRAME, streamMove);
// 川のうねりを表現するぼかしMAPを作る
var redBmd:BitmapData = bgBmd.clone();
var ctf:ColorTransform = new ColorTransform();
ctf.redOffset = 255;
ctf.greenOffset = 255;
ctf.blueOffset = 255;
redBmd.colorTransform(redBmd.rect,ctf);
var fBlur:BlurFilter = new BlurFilter();
fBlur.blurX = 32;
fBlur.blurY = 32;
//fBlur.quality = BitmapFilterQuality.HIGH;
redBmd.applyFilter(redBmd, redBmd.rect, new Point(0,0), fBlur);
petalBmd = new BitmapData(SW+80,SH+80,false,0x000000);
petalBmd.copyPixels(redBmd,redBmd.rect,new Point(0,0));
// うねりを描画
fDisplace = new DisplacementMapFilter();
fDisplace.mapBitmap = petalBmd;
//fDisplace.componentX = BitmapDataChannel.RED;
fDisplace.componentY = BitmapDataChannel.RED;
//fDisplace.scaleX = -4;
fDisplace.scaleY = -4;
// 水面の光をBevelFilterで表現
var fBevel:BevelFilter = new BevelFilter();
fBevel.knockout = true;
fBevel.blurX = 2;
fBevel.blurY = 2;
fBevel.angle = 80;
fBevel.shadowColor = 0x0066ff;
fBevel.distance = 32;
fBevel.type = BitmapFilterType.FULL;
var faceShape:Shape = new Shape();
faceShape.graphics.beginBitmapFill(redBmd);
faceShape.graphics.drawRect(0, 0, SW+80, SH+80);
faceShape.graphics.endFill();
faceShape.filters = [fBevel];
faceShape.x = -32;
faceShape.y = -32;
mainStage.addChild(faceShape);
// 花びらを描く
var petalsSprite:Sprite = new Sprite();
for (var i:uint = 0; i < 24; i++) {
var petal:Petal = new Petal();
petal.x = Math.random()*(SW+40)-20;
petal.y = Math.random()*SH+40;
petal.rotation = Math.random()*360;
petalsSprite.addChild(petal);
}
var fDropShadow:DropShadowFilter = new DropShadowFilter();
fDropShadow.distance = 30;
fDropShadow.alpha = 0.1;
fDropShadow.angle = 80;
fDropShadow.color = 0x003366;
petalsSprite.filters = [fDisplace,fDropShadow];
addChild(petalsSprite);
petalsSprite.addEventListener(Event.ENTER_FRAME, petalStream);
}
private function petalStream(e:Event):void {
for (var i:uint=0; i < 24; i++) {
var petal:Object = e.target.getChildAt(i);
if (petal.y < -50) {
petal.y += SH+100;
} else if (petal.y > SW+50) {
petal.y -= SH+100;
}
if (petal.x > 0) {
var xOffset:Number = petalBmd.getPixel(petal.x,petal.y)-0x7f7f7f;
var yOffset:Number = petalBmd.getPixel(petal.x,petal.y)-0xbbbbbb;
xOffset = xOffset/0x7f7f7f;
yOffset = yOffset/0x7f7f7f;
petal.x -= 1.5+2*xOffset;
petal.y += 1.5*yOffset;
petal.rotation -= yOffset*5;
} else if (petal.x < -30) {
petal.x += SW+60+Math.random()*10-5;
petal.y = Math.random()*(SH+80)-40;
} else {
petal.x -=4;
}
}
}
private function streamMove(e:Event):void {
if (mapPointX >= SW) {
mapPointX = 0;
}
mapPointX += 4;
streamBmd.copyPixels(streamBmdBase, new Rectangle(mapPointX,0,SW,SH), new Point(0,0));
e.target.filters = [fStream];
}
}
}
import flash.display.*;
import flash.filters.*;
class Petal extends Shape {
public function Petal():void {
graphics.lineStyle(0,0xeeaadd);
graphics.beginFill(0xffbbee);
graphics.moveTo(8,-20);
graphics.curveTo(22,0,0,20);
graphics.curveTo(-22,0,-8,-20);
graphics.lineTo(0,-12);
graphics.endFill();
}
}
class Background extends Sprite {
public function Background(w:Number, h:Number):void {
var fDropShadow:DropShadowFilter = new DropShadowFilter();
fDropShadow.alpha = 0.25;
fDropShadow.distance = 8;
var fBevel:BevelFilter = new BevelFilter();
fBevel.shadowAlpha = 0.25;
fBevel.highlightAlpha = 0.25;
fBevel.blurX = 16;
fBevel.blurY = 16;
var vC:uint = 0;
for (var nY:uint=0; nY <= h; nY+=40) {
var xOffset:int = vC%2==0 ? -10 : 10;
for (var nX:uint=0; nX < h; nX+=40) {
var sR:Number = Math.random()*5+20;
var stone:Shape = new Shape();
stone.graphics.beginFill(getColor());
stone.graphics.drawCircle(0,0,sR);
stone.graphics.endFill();
stone.x = nX + Math.random()*20-10+xOffset;
stone.y = nY + Math.random()*30-15;
stone.filters = [fBevel,fDropShadow];
addChild(stone);
}
vC++;
}
}
private function getColor():uint {
var cR:uint = Math.floor(Math.random()*20)+117;
var cG:uint = Math.floor(Math.random()*20)+168;
var cB:uint = Math.floor(Math.random()*20)+168;
var color:uint = cR << 16 | cG << 8 | cB;
return color;
}
}