ドロンとひよこ (1)
////////////////////////////////////////////////////////////////////////////////
// ドロンとひよこ (1)
//
// abakane's Smoke 煙の表現
// [http://wonderfl.net/c/zuO7]
////////////////////////////////////////////////////////////////////////////////
/**
* Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/nWws
*/
////////////////////////////////////////////////////////////////////////////////
// ドロンとひよこ (1)
//
// abakane's Smoke 煙の表現
// [http://wonderfl.net/c/zuO7]
////////////////////////////////////////////////////////////////////////////////
package {
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.display.Loader;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.system.Security;
import flash.system.LoaderContext;
import flash.display.Shape;
import flash.geom.Matrix;
import flash.display.GradientType;
import flash.utils.Timer;
import flash.events.TimerEvent;
[SWF(backgroundColor="#FFFFFF", width="465", height="465", frameRate="30")]
public class Main extends Sprite {
private static var basePath:String = "http://assets.wonderfl.net/images/related_images/";
private static var sunshinePath:String = "9/9b/9bbe/9bbec77d53bddc5e7a5f2c00abbade6bd641c549";
private var loader:Loader;
private static var piyoPath:String = "http://www.project-nya.jp/images/flash/piyo2d.swf";
private var Piyo:Class;
private var piyo:MovieClip;
public function Main() {
//Wonderfl.capture_delay(4);
init();
}
private function init():void {
draw();
Security.allowDomain("www.project-nya.jp");
Security.loadPolicyFile("http://www.project-nya.jp/crossdomain.xml");
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, initialize, false, 0, true);
loader.load(new URLRequest(piyoPath), new LoaderContext(true));
}
private function initialize(evt:Event):void {
loader.removeEventListener(Event.COMPLETE, initialize);
var content:MovieClip = MovieClip(evt.target.content);
//Piyoクラス
Piyo = MovieClip(content.piyo).constructor;
setup();
loader = null;
}
private function setup():void {
//Piyoインスタンス
piyo = new Piyo();
addChild(piyo);
piyo.x = 232;
piyo.y = 380;
piyo.scale = 4;
piyo.visible = false;
var timer:Timer = new Timer(2500, 1);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, start, false, 0, true);
timer.start();
}
private function start(evt:TimerEvent):void {
evt.target.removeEventListener(TimerEvent.TIMER_COMPLETE, start);
var timer:Timer = new Timer(20, 20);
timer.addEventListener(TimerEvent.TIMER, update, false, 0, true);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, complete, false, 0, true);
timer.start();
}
private function update(evt:TimerEvent):void {
for (var n:uint = 0; n < 5; n++) {
var fog:Fog = new Fog();
addChild(fog);
fog.px = 152 + Math.random()*160;
fog.py = 322 + Math.random()*100;
fog.vx = 0;
fog.vy = -10;
fog.start();
}
}
private function complete(evt:TimerEvent):void {
evt.target.removeEventListener(TimerEvent.TIMER, update);
evt.target.removeEventListener(TimerEvent.TIMER_COMPLETE, complete);
piyo.visible = true;
}
/////////////////////////////////////////////
//背景
/////////////////////////////////////////////
private function draw():void {
drawSky();
drawGround();
drawSun();
}
private function drawSky():void {
var matrix:Matrix = new Matrix();
matrix.createGradientBox(465, 350, 0.5*Math.PI, 0, 0);
graphics.beginGradientFill(GradientType.LINEAR, [0x3F68AB, 0x77B2EE], [1, 1], [0, 255], matrix);
graphics.drawRect(0, 0, 465, 350);
graphics.endFill();
}
private function drawGround():void {
var matrix:Matrix = new Matrix();
matrix.createGradientBox(465, 115, 0.5*Math.PI, 0, 350);
graphics.beginGradientFill(GradientType.LINEAR, [0x99CC33, 0x7EB133], [1, 1], [0, 255], matrix);
graphics.drawRect(0, 350, 465, 115);
graphics.endFill();
}
private function drawSun():void {
var matrix:Matrix = new Matrix();
matrix.createGradientBox(200, 200, 0, -90, -90);
graphics.beginGradientFill(GradientType.RADIAL, [0xFFFFFF, 0xFFFFFF, 0xFFFFFF], [1, 0.3, 0], [25, 102, 231], matrix);
graphics.drawCircle(10, 10, 100);
graphics.endFill();
var shine:Loader = new Loader();
addChild(shine);
shine.alpha = 0.5;
shine.load(new URLRequest(basePath + sunshinePath), new LoaderContext(true));
}
}
}
//////////////////////////////////////////////////
// Fogクラス
//////////////////////////////////////////////////
import flash.display.Sprite;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Matrix;
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.display.GradientType;
import flash.display.SpreadMethod;
import flash.display.InterpolationMethod;
import flash.display.BlendMode;
import org.libspark.betweenas3.BetweenAS3;
import org.libspark.betweenas3.tweens.ITween;
import org.libspark.betweenas3.events.TweenEvent;
import org.libspark.betweenas3.easing.*;
class Fog extends Sprite {
private static var radius:uint = 30;
private var bitmapData:BitmapData;
private var bitmap:Bitmap;
private var itween:ITween;
public var px:Number = 0;
public var py:Number = 0;
public var vx:Number = 0;
public var vy:Number = 0;
public function Fog() {
draw();
//blendMode = BlendMode.SCREEN;
}
private function draw():void {
bitmapData = new BitmapData(radius, radius, true, 0x00FFFFFF);
var noise:BitmapData = bitmapData.clone();
noise.perlinNoise(radius*0.5, radius*0.5, 1, Math.random()*100 | 0, false, true, 0x00FFFFFF, true, null);
//
var circle:Sprite = new Sprite();
var matrix:Matrix = new Matrix();
matrix.createGradientBox(radius, radius, 0, -radius*0.5, -radius*0.5);
var colors:Array = [0xFFFFFF, 0xFFFFFF, 0xFFFFFF];
var alphas:Array = [1, 0.7, 0];
var ratios:Array = [0, 161, 255];
circle.graphics.beginGradientFill(GradientType.RADIAL, colors, alphas, ratios, matrix, SpreadMethod.PAD, InterpolationMethod.RGB, 0);
circle.graphics.drawCircle(0, 0, radius*0.5);
circle.graphics.endFill();
var base:BitmapData = bitmapData.clone();
matrix = new Matrix();
matrix.translate(radius*0.5, radius*0.5);
base.draw(circle, matrix);
//
var rect:Rectangle = new Rectangle(0, 0, radius, radius);
var point:Point = new Point();
bitmapData.copyPixels(noise, rect, point, base, point, true);
noise.dispose();
base.dispose();
circle = null;
bitmap = new Bitmap(bitmapData);
bitmap.scaleX = bitmap.scaleY = 2;
bitmap.x = bitmap.y = - radius;
addChild(bitmap);
}
public function start():void {
var r:Number = Math.atan2( vy, vx);
r += 20*(0.5 - Math.random())*Math.PI/180;
var tx:Number = Math.cos(r)*(Math.random() + 0.5)*100;
var ty:Number = Math.sin(r)*(Math.random() + 0.5)*160;
var nx:Number = tx*0.3*Math.random();
var ny:Number = ty*0.3*Math.random();
itween = BetweenAS3.tween(this,
{x: px + tx, y: py + ty, scaleX: 2.5, scaleY: 2.5, alpha: 0, _blurFilter: {blurX: 16, blurY: 16}},
{x: px + nx, y: py + ny, scaleX: 0.8, scaleY: 0.8, alpha: 0.8, _blurFilter: {blurX: 4, blurY: 4, quality: 1}},
1, Cubic.easeOut
);
itween.addEventListener(TweenEvent.COMPLETE, complete, false, 0, true);
itween.play();
}
private function complete(evt:TweenEvent):void {
itween.removeEventListener(TweenEvent.COMPLETE, complete);
//
parent.removeChild(this);
bitmap = null;
bitmapData.dispose();
}
}