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

文字集合

MainStage
Get Adobe Flash player
by hashito 24 Mar 2010
    Embed
/**
 * Copyright hashito ( http://wonderfl.net/user/hashito )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/n0HX
 */

// MainStage
package {
	import flash.display.Sprite;
	[SWF(frameRate=60,width=456,height=456)]
	public class MainStage extends Sprite {
		public function MainStage(){
			addChild(new Main());
		}
	}
}

import flash.display.*;
import flash.filters.BlurFilter;
import flash.geom.Point;
import flash.geom.ColorTransform;
import flash.events.*;
import flash.text.TextField;
import flash.text.TextFormat;
import net.hires.debug.Stats;

//class debug{public static var out:TextField=new TextField();}
//
/*
	t.hashito
	日本語未対応
*/
class MF{
	public static function AFFORD (x:Number,aim:Number,a:Number):Boolean{return (x<=(a+aim))&&(x>=(a-aim));}
	public static function RAN (n:Number=1):Number{return (Math.random()*n);}
	public static function ISPM (n:Number):Number{if(n<0){return -1;}else if(n>0){return 1;}return 0;}
}


class Main extends Sprite{
	public const H:Number = 456;
	public const W:Number = 456;
	private var t:Tx=new Tx(W,H);
	//Constructor
	public function Main() {addEventListener(Event.ADDED_TO_STAGE, init);}
	//init
	public function init(e:*):void{
		addChild(t);
		
		// debug
		///debug.out.autoSize=flash.text.TextFieldAutoSize.LEFT;
		///addChild(debug.out);
		///debug.out.text="0";
		stage.addEventListener(flash.events.KeyboardEvent.KEY_DOWN  ,keydown);
		addEventListener(Event.ENTER_FRAME ,update);
		stage.addEventListener(MouseEvent.MOUSE_DOWN ,reset);
	}
	public function update(e:Event=null):void{
		t.update();
		//debug.out.text="x="+t.bits[0].x+" y="+t.bits[0].y+" vx="+t.bits[0].vx+" vy="+t.bits[0].vy+" ax="+t.bits[0].ax+" ay="+t.bits[0].ay;
	}
	public function reset(e:MouseEvent=null):void{
		t.setChar("A",MF.RAN(W),MF.RAN(H))
	}
	public function keydown(e:KeyboardEvent=null):void{
		//if(e.keyCode>=0x22 && e.keyCode<=0x7e )
			t.setChar( String.fromCharCode(e.keyCode),MF.RAN(W),MF.RAN(H))
		//debug.out.text=""+e.keyCode;
	}
}

class Tx extends Sprite{
	public var W:int,H:int;
	public const K:int=2;
	public function Tx(W:int,H:int){
		this.W=W;this.H=H;
		bits_init();
		t_init();
	}
	
	public var bits:Vector.<Bit> =new Vector.<Bit>(500,true);
	public var bitsT:Vector.<Vector.<Bit>> =new Vector.<Vector.<Bit>>();
	private function bits_init():void{
		for(var i:int=0 ; bits.length>i ; i++){
			bits[i] = new Bit(K,MF.RAN(W),MF.RAN(H),MF.RAN(0xffffff));
			addChild(bits[i]);
		}
	}
	
	private var b:BitmapData =new BitmapData(B_X,B_Y,true,T_BC);
	private const B_X:int=40 , B_Y:int=20;
	
	private var t:TextField=new TextField();
	private const T_FC:uint=0xffffff,T_BC:uint=0;
	
	private function t_init():void{
		var tf:TextFormat=new TextFormat();
		t.autoSize   = flash.text.TextFieldAutoSize.LEFT;
		t.background = true;
		t.backgroundColor = T_BC;
		t.textColor=T_FC;
		tf.size  = B_Y-1;
		tf.letterSpacing  = 1;
		t.setTextFormat(tf);
	}
	public function setChar(c:String,x:int,y:int):void{
		var v:Vector.<Bit> = new Vector.<Bit>();
		var bit:Bit;
		t.text = c.charAt(0);
		b.fillRect(b.rect,T_BC);
		b.draw(t);
		var w:int=b.width , h:int=b.height;
		for(var ix:int=0;ix<w;ix++){
			for(var iy:int=0;iy<h;iy++){
				if(b.getPixel(ix,iy)==T_FC){
					bit=getBit();
					bit.setAim(x+ix*K,y+iy*K);
					v.push(bit);
				}
			}
		}
		bitsT.push(v);
	}
	private var bitcount:int;
	public function getBit():Bit{
		var ret:Bit=bits[bitcount];
		if(++bitcount >= bits.length)bitcount=0;
		return ret;
	}
	public function update(t:Number=1):void{
		var i:int,l:int,ret:Boolean=false;
		var v:Vector.<Bit>;
		for(i=0 ; bits.length>i ; i++){
			bits[i].update(t);
		}
		//チームの処理
		for(i=0 ; bitsT.length>i ; i++){
			v=bitsT[i];
			ret=true;
			for(l = 0 ; v.length>l ; l++){
				if(!v[l].isAim()){
					ret=false;
					break;
				}
			}
			if(ret){
				while(v.length>0){
					v[0].endAim();
					v.splice(0,1);
				}
				bitsT.splice(bitsT.indexOf(v),1);
			}
		}
	}
}
class Bit extends Shape{
	public var ix:int,iy:int,k:int,color:uint;
	public var aimx:int,aimy:int;
	public var ax:Number=0,ay:Number=0,vx:Number=0,vy:Number=0;
	
	public function Bit(k:int,x:int,y:int,color:uint){
		this.x = aimx = ix = (x);
		this.y = aimy = iy = (y);
		this.k=k;this.color=color
		this.graphics.beginFill(color);
		this.graphics.drawCircle(0,0,k)
	}
	public function setAim(x:int,y:int):void{
		aimx=x;aimy=y;
		this.graphics.beginFill(0x0);
		this.graphics.drawCircle(0,0,k);
		aim=false;
	}
	public function endAim():void{
		aimx=ix;aimy=iy;
		this.graphics.beginFill(color);
		this.graphics.drawCircle(0,0,k)
	}
	public function isAim():Boolean{
		return aim;
	}
	private var aim:Boolean=true;
	public function update(t:Number=1):void{
		if((x==aimx) && (y==aimy)){
			aim=true;
		}else{
			x+=MF.ISPM(aimx - x);
			y+=MF.ISPM(aimy - y);
			
			//x  += (vx*t);vx += (ax*t);
			//y  += (vy*t);vy += (ay*t);
			//vx *= 0.90; ax *= 0.95;
			//vy *= 0.90; ay *= 0.95;
			//if((ax+ay) < 0.0005){
			//	ax = (aimx - x)*0.0003+ MF.ISPM(aimx - x)*0.0003;
			//	ay = (aimy - y)*0.0003+ MF.ISPM(aimy - y)*0.0003;
			//}
		}
	}
	
}