forked from: flash on 2009-12-2
高速化
/**
* Copyright bkzen ( http://wonderfl.net/user/bkzen )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/9P05
*/
// 高速化
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.utils.getTimer;
import flash.display.BitmapData;
public class Test extends Sprite {
private var _tf : TextField;
public function Test() {
_tf = new TextField();
_tf.width = 465;
_tf.height = 465;
addChild(_tf);
var bmd : BitmapData = new BitmapData(465, 465, false, 0x000000);
bmd.noise(getTimer());
var s : int = getTimer();
var max : int = 0;
var maxk : uint = 0;
var counter : Object = {};
for(var y : int = 0;y < 465;y++){
for(var x : int = 0;x < 465;x++){
var key : uint = bmd.getPixel(x, y);
if (counter[key])
{
if (++counter[key] > max)
{
max ++;
maxk = key;
}
}
else counter[key] = 1;
}
}
/*
for(var k : String in counter){
if(max < counter[k]){
max = counter[k];
maxk = uint(k);
}
}
*/
var g : int = getTimer();
tr("maxk : #" + maxk.toString(16));
tr("maxcount : " + max);
tr((g - s) + " ms");
}
private function tr(...o : Array) : void
{
_tf.appendText(o + "\n");
}
}
}