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

forked from: 文字列を文字に切り離しての円運動

文字列を文字に切り離しての円運動
* use papervision3d
// forked from katan_t's 文字列を文字に切り離しての円運動
/*
* 文字列を文字に切り離しての円運動
* use papervision3d
*/

package  {
	//必要なクラスのimport
	import flash.display.Sprite;
	import org.papervision3d.view.Viewport3D;
	import org.papervision3d.scenes.Scene3D;
	import org.papervision3d.cameras.Camera3D;
	import org.papervision3d.render.BasicRenderEngine;
	
	import org.papervision3d.materials.special.Letter3DMaterial;
	import org.papervision3d.typography.Text3D;
	import org.papervision3d.typography.fonts.HelveticaBold;

	import flash.events.Event;

	public class Sample10 extends Sprite { //Spriteクラス継承
		public var viewport:Viewport3D;
		public var scene:Scene3D;
		public var camera:Camera3D;
		public var renderer:BasicRenderEngine;

		private var degrees_arr:Array = new Array();//角度格納用配列
		private var text_arr:Array = new Array();//文字格納配列
		private var text_str:String = "TTTTTTTTTTTTTTTTTTTTTTTTT";//表示文字列
		

		private var letterformat:Letter3DMaterial;
		private var basicx_int:int = 0;//基準x座標
		private var basicz_int:int = 0;//基準z座標
		private var diameter_int:int = 485;//半径
		private var speed_int:int = 1;//毎回の移動角度

		//コンストラクタ
		public function Sample10() {
			init();//初期化関数開始
		}

		//初期化関数
		public function init():void{
			viewport = new Viewport3D(stage.stageWidth , stage.stageHeight);
			addChild(viewport);//viewportを表示ツリーに追加

			renderer = new BasicRenderEngine();
			scene = new Scene3D();
			camera = new Camera3D();

			//文字の設定 引数は色コード・透過度
			letterformat = new Letter3DMaterial(0x0000ff , 0.8);
			
			//文字の分解とText3Dインスタンス生成
			for(var i:int = 0 ; i < text_str.length ; i++){
				text_arr.push(new Text3D(text_str.charAt(text_str.length - i -1) , new HelveticaBold() , letterformat));
				degrees_arr.push(i * 360 / text_str.length);//角度を均等に分割
				scene.addChild(text_arr[i]);
			}

			addEventListener(Event.ENTER_FRAME , onEnterFrame);//ENTER_FRAMEイベント定義
		}

		//ENTER_FRAME時関数
		public function onEnterFrame(event:Event):void {

			//各文字の座標及び角度計算と角度の増加
			for(var i:int = 0 ; i < text_str.length ; i++){
				
				text_arr[i].x = Math.sin(degrees_arr[i] * Math.PI/180) * diameter_int + basicx_int;
				text_arr[i].z = Math.cos(degrees_arr[i] * Math.PI/180) * diameter_int + basicz_int;
				
				//rotationYにおいての文字の反転が行えなかったため、scaleXを位置によって変更することで反転表示に対応
				if(degrees_arr[i] > 90 && degrees_arr[i] < 270){
					text_arr[i].rotationY = degrees_arr[i] + 180;
					text_arr[i].scaleX = 1;
				}
				else{
					text_arr[i].rotationY = degrees_arr[i];
					text_arr[i].scaleX = -1;
				}
				
				degrees_arr[i] += speed_int;
				degrees_arr[i] %= 360;
			}

			renderer.renderScene(scene, camera, viewport);//描画
		}
	}
}