flash on 2010-4-15
/**
* Copyright kihon ( http://wonderfl.net/user/kihon )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/v1Ee
*/
package
{
import com.bit101.components.PushButton;
import flash.display.Sprite;
import flash.events.Event;
import frocessing.math.Random;
import jp.progression.commands.Func;
import jp.progression.commands.lists.SerialList;
import jp.progression.commands.Prop;
import jp.progression.commands.Wait;
public class Main extends Sprite
{
private var data:Array;
private var SIZE:int = 5;
private var num:int = 80;
private var list:SerialList = new SerialList();
public function Main()
{
graphics.beginFill(0xF0F0F0);
graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
graphics.endFill();
data = new Array(num);
for (var i:int = 0; i < data.length; i++)
{
var rect:Rect = new Rect(SIZE);
rect.x = i * SIZE;
rect.y = i * SIZE;
addChild(rect);
data[i] = rect;
}
init();
new PushButton(this, 185, 400, "execute", execute);
}
private function execute(event:Event):void
{
if (list.state == 2) return;
list = new SerialList();
init();
sort();
list.execute();
}
private function init():void
{
var random:Array = Random.shakedIntegers(num);
for (var i:int = 0; i < data.length; i++)
{
data[i].x = random[i] * SIZE;
}
}
private function sort():void
{
var copy:Array = new Array(num);
for (var i:int = 0; i < data.length; i++)
{
copy[i] = data[i].x;
}
for (i = data.length - 1; i > 0; i--)
{
for (var j:int = 0; j < i; j++)
{
if (copy[j] > copy[j + 1])
{
list.addCommand(new Func(function(x1:int, x2:int, j:int):void { data[j].x = x2; data[j + 1].x = x1;}, [copy[j], copy[j + 1], j]));
list.addCommand(new Wait(10 / 1000.0));
var temp:int = copy[j];
copy[j] = copy[j + 1];
copy[j + 1] = temp;
}
}
}
}
}
}
import flash.display.Sprite;
import flash.filters.DropShadowFilter;
class Rect extends Sprite
{
public function Rect(size:int)
{
graphics.beginFill(0x0);
graphics.drawRect(0, 0, size, size);
graphics.endFill();
this.filters = [new DropShadowFilter(2)];
}
}