forked from: 四畳半神話大系的な何か
/**
* Copyright gupon ( http://wonderfl.net/user/gupon )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/34RA
*/
// forked from Nyarineko's 四畳半神話大系的な何か
package
{
import flash.display.*;
import flash.events.*;
import org.libspark.betweenas3.BetweenAS3;
import org.libspark.betweenas3.easing.*;
import org.libspark.betweenas3.tweens.ITween;
import org.libspark.betweenas3.events.TweenEvent;
[SWF(width = "465", height = "465", backgroundColor = "0x697771")]
public class Main extends Sprite
{
private var EZ:Number = .6; //速度が変わるよ!
private var _tw:ITween;
private var _container:Sprite = new Sprite();
private var MAX:int = 20;
private var _cnt:int = 0;
private var _topBox:Box;
private var _lastBox:Box;
public function Main():void
{
var w:Number = Math.random()*200 + 50;
var h:Number = Math.random()*200 + 50;
var box:Box = new Box(w,h);
_topBox = box;
_lastBox = box;
_container.rotationZ = Math.random() * 180 - 90;
_container.x = 165;
_container.y = 165;
//_boxs = box;
addChild(_container);
_container.addChild(box);
_tw = BetweenAS3.parallel(
BetweenAS3.tween(box,{width:box.width},{width:0},EZ,Quint.easeInOut),
BetweenAS3.tween(box,{height:box.height},{height:0},EZ,Quint.easeInOut));
_tw.addEventListener(TweenEvent.COMPLETE,compTween);
_tw.play();
}
private function compTween(e:TweenEvent):void
{
_tw.removeEventListener(TweenEvent.COMPLETE,compTween);
_cnt++;
EZ = Math.random() * .3 + .4;
var twArray:Array = [];
var w:Number = Math.random()*200 + 50;
var h:Number = Math.random()*200 + 50;
var box:Box = _topBox;
//途中の部屋
while(box.linkBox){
if(_lastBox.width>_lastBox.height){
twArray.push(BetweenAS3.parallel(
BetweenAS3.tween(box,{x:box.x - _lastBox.width/2},null,EZ,Quint.easeInOut),
BetweenAS3.tween(box,{y:box.y - _lastBox.height+2},null,EZ,Quint.easeInOut)
));
}else{
twArray.push(BetweenAS3.parallel(
BetweenAS3.tween(box,{x:box.x - _lastBox.width+2},null,EZ,Quint.easeInOut),
BetweenAS3.tween(box,{y:box.y - _lastBox.height/2},null,EZ,Quint.easeInOut)
));
}
box = box.linkBox;
}
//最後の部屋と新しい部屋
var box_new:Box = new Box(w,h);
_container.addChild(box_new);
if(box.width>box.height){
twArray.push(BetweenAS3.parallel(
BetweenAS3.tween(box,{x:box.x - box.width/2},null,EZ,Quint.easeInOut),
BetweenAS3.tween(box,{y:box.y - box.height+2},null,EZ,Quint.easeInOut),
BetweenAS3.tween(box_new,{x:0},{x:box.width/2},EZ,Quint.easeInOut),
BetweenAS3.tween(box_new,{y:0},{y:box.height},EZ,Quint.easeInOut)
));
}else{
twArray.push(BetweenAS3.parallel(
BetweenAS3.tween(box,{x:box.x - box.width+2},null,EZ,Quint.easeInOut),
BetweenAS3.tween(box,{y:box.y - box.height/2},null,EZ,Quint.easeInOut),
BetweenAS3.tween(box_new,{x:0},{x:box.width},EZ,Quint.easeInOut),
BetweenAS3.tween(box_new,{y:0},{y:box.height/2},EZ,Quint.easeInOut)
));
}
twArray.push(BetweenAS3.parallel(
BetweenAS3.tween(box_new,{width:w},{width:0},EZ,Quint.easeInOut),
BetweenAS3.tween(box_new,{height:h},{height:0},EZ,Quint.easeInOut)));
//新しい配列をリストに追加
box.linkBox = box_new;
_lastBox = box_new;
//10個以上になったら古いの消すよ
if(_cnt > 12){
var bufBox:Box = _topBox.linkBox;
_container.removeChild(_topBox);
_topBox = bufBox;
}
//ちょいちょい角度を変えてみる
if(_cnt % 3 == 0){
var s:Number = Math.random() * 1 + .1;
twArray.push(
BetweenAS3.tween(_container,{rotation:Math.random() * 180 - 90},null,EZ,Quint.easeInOut),
BetweenAS3.tween( _container, { scaleX:s, scaleY:s }, null, EZ, Quint.easeInOut));
}
_tw = BetweenAS3.parallelTweens( twArray );
_tw.addEventListener(TweenEvent.COMPLETE,compTween);
_tw.play();
}
}
}
import flash.display.Sprite;
class Box extends Sprite
{
public var linkBox:Box = null;
public function Box(w:Number,h:Number):void
{
var lineColor:uint = 0x333333;
var colors:Array = [0x6397AD,0xB73A37,0xF9E08F,0x513633,0x607567,0x8C915C,0x32353A,0xEFCC6A,0xBABCB3];
graphics.lineStyle( 8,lineColor,1, true, "none","none","miter");
graphics.beginFill( colors[ Math.floor( Math.random() * colors.length )]);
graphics.drawRect( 0, 0, w, h );
graphics.endFill();
}
}