海 (WaveMask)
海 (WaveMask)
/**
* Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/aTaW
*/
////////////////////////////////////////////////////////////////////////////////
// 海 (WaveMask)
////////////////////////////////////////////////////////////////////////////////
package {
import flash.display.Sprite;
import flash.display.Loader;
import flash.events.Event;
import flash.net.URLRequest;
import flash.system.LoaderContext;
import flash.system.Security;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.utils.Timer;
import flash.events.TimerEvent;
[SWF(backgroundColor="#000000", width="465", height="465", frameRate="30")]
public class Main extends Sprite {
private var bitmapData:BitmapData;
private var bitmap:Bitmap;
private var bx:int;
private var by:int;
private static var basePath:String = "http://assets.wonderfl.net/images/related_images/";
private static var filePath:String = "1/19/191f/191f2bf9a8254eadaea5222f5a629ca920bb6e6b";
private var wave:WaveMask;
private var se:SoundEffect;
private var source:String = "http://www.project-nya.jp/images/flash/wave.mp3";
public function Main() {
//Wonderfl.capture_delay(1);
init();
}
private function init():void {
graphics.beginFill(0x000000);
graphics.drawRect(0, 0, 465, 465);
graphics.endFill();
//
Security.allowDomain("assets.wonderfl.net");
Security.loadPolicyFile("http://assets.wonderfl.net/crossdomain.xml");
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.INIT, initialize, false, 0, true);
loader.load(new URLRequest(basePath + filePath), new LoaderContext(true));
//
se = new SoundEffect();
se.addEventListener(Event.COMPLETE, loaded, false, 0, true);
se.load(source);
}
private function initialize(evt:Event):void {
evt.target.removeEventListener(Event.INIT, initialize);
var content:Bitmap = Bitmap(evt.target.content);
bitmapData = content.bitmapData;
bx = int((465 - content.width)/2);
by = int((465 - content.height)/2);
content =null;
bitmap = new Bitmap(bitmapData);
addChild(bitmap);
bitmap.x = bx;
bitmap.y = by;
//
var timer:Timer = new Timer(1000, 4);
timer.addEventListener(TimerEvent.TIMER , create, false, 0, true);
timer.addEventListener(TimerEvent.TIMER_COMPLETE , complete, false, 0, true);
timer.start();
}
private function create(evt:TimerEvent):void {
var wave:WaveMask = new WaveMask(bitmapData);
addChild(wave);
wave.x = 232;
wave.y = 0;
wave.setup(180);
wave.start();
}
private function complete(evt:TimerEvent):void {
evt.target.removeEventListener(TimerEvent.TIMER , create);
evt.target.removeEventListener(TimerEvent.TIMER_COMPLETE , complete);
}
private function loaded(evt:Event):void {
se.removeEventListener(Event.COMPLETE, loaded);
se.play(1, true);
}
}
}
//////////////////////////////////////////////////
// SoundEffectクラス
//////////////////////////////////////////////////
import flash.display.Sprite;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.display.Shape;
import org.libspark.betweenas3.BetweenAS3;
import org.libspark.betweenas3.tweens.ITween;
import org.libspark.betweenas3.events.TweenEvent;
import org.libspark.betweenas3.easing.Linear;
import org.libspark.betweenas3.easing.Quad;
import org.libspark.betweenas3.easing.Expo;
class WaveMask extends Sprite {
private var bitmapData:BitmapData;
private var bitmap1:Bitmap;
private var bitmap2:Bitmap;
private var overlay1:Sprite;
private var overlay2:Sprite;
private var wave1:Wave;
private var wave2:Wave;
private var targetPos:uint;
private var basePos:uint;
private var length:uint;
private var amplitude:Number = 0;
private static var deceleration:Number = 0.04;
public function WaveMask(bd:BitmapData) {
bitmapData = bd;
init();
}
private function init():void {
bitmap1 = new Bitmap(bitmapData.clone());
bitmap1.scaleX = bitmap1.scaleY = 1.02;
addChild(bitmap1);
bitmap1.x = -uint(bitmapData.width/2);
bitmap2 = new Bitmap(bitmapData.clone());
bitmap2.scaleX = bitmap2.scaleY = 1.04;
addChild(bitmap2);
bitmap2.x = -uint(bitmap2.width/2);
overlay1 = new Sprite();
addChild(overlay1);
bitmap1.mask = overlay1;
overlay2 = new Sprite();
addChild(overlay2);
bitmap2.mask = overlay2;
wave1 = new Wave(bitmapData.width, 10);
overlay1.addChild(wave1);
wave2 = new Wave(bitmapData.width, 10);
overlay2.addChild(wave2);
wave2.y = wave1.y + 10;
}
public function setup(t:uint):void {
targetPos = t;
basePos = bitmapData.height;
length = basePos - targetPos;
var rect:Shape = new Shape();
rect.graphics.beginFill(0x000000);
rect.graphics.drawRect(-bitmapData.width/2, 0, bitmapData.width, bitmapData.height - targetPos);
rect.graphics.endFill();
addChild(rect);
rect.y = targetPos;
mask = rect;
}
public function start():void {
var itween:ITween = BetweenAS3.parallel(
BetweenAS3.tween(wave1, {y: targetPos}, {y: basePos}, 4, Quad.easeOut),
BetweenAS3.tween(wave1, {scale: 1}, {scale: 2}, 4, Expo.easeOut),
BetweenAS3.delay(BetweenAS3.tween(bitmap1, {alpha: 0}, {alpha: 1}, 0.8, Linear.easeNone), 3.2),
BetweenAS3.tween(wave2, {y: targetPos}, {y: basePos}, 4, Quad.easeOut),
BetweenAS3.tween(wave2, {scale: 1}, {scale: 2}, 4, Expo.easeOut),
BetweenAS3.delay(BetweenAS3.tween(bitmap2, {alpha: 0}, {alpha: 1}, 0.8, Linear.easeNone), 3.2)
);
itween.addEventListener(TweenEvent.COMPLETE, complete, false, 0, true);
itween.play();
}
private function complete(evt:TweenEvent):void {
evt.target.removeEventListener(TweenEvent.COMPLETE, complete);
start();
}
}
//////////////////////////////////////////////////
// Waveクラス
//////////////////////////////////////////////////
import flash.display.Shape;
class Wave extends Shape {
private var _width:uint;
private var _height:uint;
private var _scale:Number = 1;
public function Wave(w:uint, h:uint) {
_width = w;
_height = h;
init();
}
private function init():void {
graphics.beginFill(0x000000);
graphics.moveTo(-_width/2, 0);
graphics.lineTo(-_width/2, _height);
graphics.curveTo(0, _height*4, _width/2, _height);
graphics.lineTo(_width/2, _height);
graphics.lineTo(_width/2, 0);
graphics.curveTo(0, _height*2, -_width/2, 0);
graphics.lineTo(-_width/2, 0);
graphics.endFill();
}
public function get scale():Number {
return _scale;
}
public function set scale(param:Number):void {
_scale = param;
scaleX = scaleY = _scale;
}
}
//////////////////////////////////////////////////
// SoundEffectクラス
//////////////////////////////////////////////////
import flash.events.EventDispatcher;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundTransform;
import flash.net.URLRequest;
class SoundEffect extends EventDispatcher {
public var id:String;
private var sound:Sound;
private var channel:SoundChannel;
private var level:Number;
private var volume:Number = 1;
private var looping:Boolean = false;
public var initialized:Boolean = false;
public var playing:Boolean = false;
public function SoundEffect() {
}
public function init(Snd:Class):void {
sound = new Snd();
}
public function load(filePath:String):void {
sound = new Sound();
sound.load(new URLRequest(filePath));
sound.addEventListener(ProgressEvent.PROGRESS, progress, false, 0, true);
sound.addEventListener(Event.COMPLETE, initialize, false, 0, true);
}
private function progress(evt:ProgressEvent):void {
dispatchEvent(evt);
}
private function initialize(evt:Event):void {
initialized = true;
channel = sound.play();
channel.stop();
dispatchEvent(evt);
}
public function play(lv:Number, loop:Boolean = false):void {
playing = true;
channel.stop();
level = lv;
looping = loop;
channel = sound.play();
var transform:SoundTransform = channel.soundTransform;
transform.volume = level*volume;
channel.soundTransform = transform;
if (looping) {
channel.addEventListener(Event.SOUND_COMPLETE, complete, false, 0, true);
}
}
public function stop():void {
playing = false;
channel.stop();
channel.removeEventListener(Event.SOUND_COMPLETE, complete);
}
public function setVolume(v:Number):void {
volume = v;
var transform:SoundTransform = channel.soundTransform;
transform.volume = level*volume;
channel.soundTransform = transform;
}
private function complete(evt:Event):void {
channel.removeEventListener(Event.SOUND_COMPLETE, complete);
if (looping) {
channel = sound.play(0);
channel.addEventListener(Event.SOUND_COMPLETE, complete, false, 0, true);
var transform:SoundTransform = channel.soundTransform;
transform.volume = level*volume;
channel.soundTransform = transform;
} else {
playing = false;
}
}
}