In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

暗いタイルでは文字を白く(HLS版+重み付け)

Get Adobe Flash player
by Nicolas 09 May 2009
// forked from Nicolas's forked from: forked from: flash on 2009-5-8  暗いタイルでは文字を白く(HLS版)
// forked from nicolas's forked from: flash on 2009-5-8  暗いタイルでは文字を白く
// forked from hacker_tanaka's flash on 2009-5-8

package {
    import flash.display.*;  
    import flash.text.TextField;
    import flash.text.TextFormat;
    import flash.events.MouseEvent;

    public class gameTile extends Sprite {
		private static const linenum:Number = 4;
		private static const spr_size:int = 50;
		
		
        public function gameTile () {
            
			for(var i:int = 0;i < linenum*linenum;i++){
				var spr:Sprite = new Sprite();
                //色
                var color:uint = Math.random()*0xFFFFFF;
                var red:uint = (color & 0xFF0000) >>16;
                var green:uint = (color & 0x00FF00) >>8;
                var blue:uint = color & 0xFF;
                //輝度(RGB重み付け平均)
                var luminance:Number = red*0.29891 + green*0.58661 + blue*0.11448;
				spr.graphics.beginFill(color);
				spr.graphics.drawRect(0,0,spr_size,spr_size);
				spr.graphics.endFill();
				spr.x = spr_size*(i%linenum);
				spr.y = spr_size*(Math.floor(i/linenum));
				addChild(spr);
				
				var arr:Array = new Array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
				var arrLength:int = arr.length;
                                
                //閾値
                const threshold:uint = 0x66;
                                
                for (var arr_i:int=0; arr_i<arrLength; arr_i++){
                    var rnd:int = Math.random() * arr.length;
				    var sprText:TextField = new TextField();

                    var format:TextFormat = new TextFormat();
                    format.size = 20;
                    sprText.defaultTextFormat = format;
				    sprText.text = arr[rnd];
                    //輝度<閾値なら文字色を白に
                    if(luminance < threshold) {
						sprText.textColor = 0xFFFFFF;	
                        }
                    arr.splice(rnd,1);
                    
				}
			
				spr.addChild(sprText);

			}

        }
    }
}