forked from: 湯けむりひよこ
...
@author Hiiragi
// forked from Hiiragi's 湯けむりひよこ
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BitmapDataChannel;
import flash.display.GradientType;
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.net.URLRequest;
import flash.system.LoaderContext;
import flash.system.Security;
/**
* ...
* @author Hiiragi
*/
[SWF(width="465", height="465", frameRate="30", backgroundColor="0x99BBFF")]
public class Main extends Sprite
{
public static const CROSSDOMAIN:String = "http://melancholy.raindrop.jp/flash/crossdomain.xml";
private var _canvas:BitmapData;
private var _perlinNoiseBmpd:BitmapData;
private var _gradientSprite:Sprite;
private var _gradientBmpd:BitmapData;
private var _offsetArray:Array;
private var _offsetLength:int;
private var _diffSpeed:Number;
private var _bgLoader:Loader;
private var _hiyoko:Hiyoko;
private var _towel:Towel;
public function Main()
{
Security.loadPolicyFile(CROSSDOMAIN);
if (stage) init();
else this.addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
_diffSpeed = 4;
_canvas = new BitmapData(this.stage.stageWidth, this.stage.stageHeight, true, 0x0);
this.addChild(new Bitmap(_canvas));
_perlinNoiseBmpd = new BitmapData(this.stage.stageWidth, this.stage.stageHeight, true, 0x0);
_gradientSprite = new Sprite();
var mtx:Matrix = new Matrix();
mtx.createGradientBox(465, 465, Math.PI / 2);
_gradientSprite.graphics.beginGradientFill(GradientType.LINEAR, [0xFFFFFF, 0xFFFFFF, 0xFFFFFF], [0, 0.9, 1], [0, 100, 255], mtx);
_gradientSprite.graphics.drawRect(0, 0, this.stage.stageWidth, this.stage.stageHeight);
_gradientSprite.graphics.endFill();
_gradientBmpd = new BitmapData(this.stage.stageWidth, this.stage.stageHeight, true, 0x0);
_gradientBmpd.draw(_gradientSprite);
_offsetLength = 5;
_offsetArray = [];
for (var i:int = 0; i < _offsetLength; i++)
{
_offsetArray.push(new Point());
}
//background
_bgLoader = new Loader();
_bgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, bgLoadComplete);
_bgLoader.load(new URLRequest("http://melancholy.raindrop.jp/flash/wonderfl_5/bg.jpg"));
_towel = new Towel();
_towel.x = this.stage.stageWidth / 2;
_towel.y = 240;
}
private function bgLoadComplete(e:Event):void
{
_hiyoko = new Hiyoko(0, 100);
_hiyoko.addEventListener(Event.COMPLETE, hiyokoLoadCompleteHandler);
}
private function hiyokoLoadCompleteHandler(e:Event):void
{
_hiyoko.scaleX = _hiyoko.scaleY = 2;
_hiyoko.x = this.stage.stageWidth / 2;
_hiyoko.y = 350;
initComplete();
}
private function initComplete(e:Event = null):void
{
this.addChildAt(_bgLoader, 0);
this.addChildAt(_hiyoko, 1);
this.addChildAt(_towel, 2);
this.addEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
}
private function onEnterFrameHandler(e:Event):void
{
//this.removeEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
_perlinNoiseBmpd.lock();
_canvas.lock();
_perlinNoiseBmpd.perlinNoise(_perlinNoiseBmpd.width, _perlinNoiseBmpd.height, _offsetLength, 100, true, true, 7, true, _offsetArray);
_canvas.fillRect(_canvas.rect, 0xFFFFFFFF);
_canvas.copyChannel(_perlinNoiseBmpd, _perlinNoiseBmpd.rect, new Point(), BitmapDataChannel.RED, BitmapDataChannel.ALPHA);
var len:int = _offsetArray.length;
for (var i:int = 0; i < len; i++)
{
_offsetArray[i].x += (i + 1) * _diffSpeed;
_offsetArray[i].y += (i + 1) * _diffSpeed * (i % 2 * 2 - 1);
}
_canvas.merge(_gradientBmpd, _gradientBmpd.rect, new Point, 1, 0, 0, 50);
_canvas.unlock();
_perlinNoiseBmpd.unlock();
}
}
}
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
import flash.utils.ByteArray;
class Hiyoko extends Sprite
{
private var maskX:int;
private var maskY:int;
private var _mask:Sprite;
private var _loader:Loader;
private var _contentByteArray:ByteArray;
public function Hiyoko(maskX:int, maskY:int)
{
this.maskX = maskX;
this.maskY = maskY;
_loader = new Loader();
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
this.addChild(_loader);
_loader.load(new URLRequest("http://www.project-nya.jp/images/flash/chick.swf"));
}
private function onLoadComplete(e:Event):void
{
_mask = new Sprite();
_mask.graphics.beginFill(0);
_mask.graphics.drawRect(-_loader.width / 2, -_loader.height - 15, _loader.width, _loader.height);
_mask.graphics.endFill();
this.addChild(_mask);
_loader.mask = _mask;
this.dispatchEvent(new Event(Event.COMPLETE));
}
}
import flash.display.Sprite;
import flash.display.Shape;
import flash.filters.DropShadowFilter;
class Towel extends Sprite
{
private var _width:uint = 90;
private var _height:uint = 30;
public function Towel()
{
draw();
filters = [new DropShadowFilter(1, 90, 0x000000, 0.3, 4, 4, 2, 3, false, false, false)];
}
private function draw():void
{
graphics.beginFill(0xFFFFFF);
graphics.drawRect(-_width/2, -_height/2, _width, _height);
graphics.endFill();
for (var r:uint = 0; r < 4; r++) {
for (var c:uint = 0; c < 10; c++) {
var dot:Shape = new Shape();
dot.graphics.beginFill(0x004B99);
dot.graphics.drawEllipse(-3, -2, 6, 4);
dot.graphics.endFill();
addChild(dot);
dot.x = -35 + 12*c + 6*(r%2);
dot.y = -12 + 6*r;
}
}
var overlay:Shape = new Shape();
overlay.graphics.beginFill(0x000000);
overlay.graphics.moveTo(-32, -10);
overlay.graphics.curveTo(-40, 0, -38, 10);
overlay.graphics.curveTo(0, 0, 38, 10);
overlay.graphics.curveTo(40, 0, 32, -10);
overlay.graphics.curveTo(0, -16, -32, -10);
overlay.graphics.endFill();
addChild(overlay);
mask = overlay;
}
}