flash on 2010-12-16
@author jc at bk-zen
♥0 |
Line 59 |
Modified 2010-12-16 19:37:46 |
MIT License
archived:2017-03-30 04:34:40
ActionScript3 source code
/**
* Copyright bkzen ( http://wonderfl.net/user/bkzen )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/myOb
*/
package
{
import flash.display.Graphics;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.utils.getTimer;
import frocessing.color.ColorHSV;
/**
* @author jc at bk-zen
*/
[SWF (backgroundColor = "0xFFFFFF", frameRate = "30", width = "465", height = "465")]
public class Test3 extends Sprite
{
private var disps: Array;
private var sp: Sprite;
private var txt:TextField;
public function Test3()
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e: Event = null): void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
//
disps = [];
addChild(sp = new Sprite());
addChild(txt = new TextField());
txt.width = stage.stageWidth, txt.height = stage.stageHeight;
var arr: Array = [], i: int, n: int = 300, j: int;
for (i = 0; i < n; i ++) { arr[i] = i; }
while (n) i = Math.random() * n | 0, j = arr[--n], arr[n] = arr[i], arr[i] = j;
n = arr.length;
var sh: Shape, g: Graphics, col: ColorHSV = new ColorHSV(), s: int;
for (i = 0; i < n; i ++)
{
sp.addChild(disps[i] = sh = new Shape());
j = arr[i];
col.h = j / n * 360;
g = sh.graphics;
g.beginFill(col.value);
s = 10 + j / n * 400;
sh.x = sh.y = 465 - s >> 1;
g.drawRect(0, 0, s, s);
}
stage.addEventListener(MouseEvent.CLICK, sort);
}
private function sort(e:MouseEvent):void
{
var t: int, i: int, n: int = disps.length;
t = getTimer();
disps.sortOn("width", Array.NUMERIC | Array.DESCENDING);
for (i = 0; i < n; i ++)
{
sp.addChild(disps[i]);
}
txt.text = (getTimer() - t) + "ms";
}
}
}