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

3DTagCloud

3DTagCloudの練習
* タグクラウドとしての機能はもちろんありませんけどー!(泣)
* 
* 計算がごちゃごちゃしているので、
* 後でmatrix3Dを使って修正予定です。
*
Get Adobe Flash player
by code 05 May 2010
    Embed
/**
 * Copyright code ( http://wonderfl.net/user/code )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/dvN1
 */

/*
 * 3DTagCloudの練習
 * タグクラウドとしての機能はもちろんありませんけどー!(泣)
 * 
 * 計算がごちゃごちゃしているので、
 * 後でmatrix3Dを使って修正予定です。
 * 
 */

package 
{
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
	
	[SWF(width="500",height="500",framerate="30",backgroundColor="0x000000")]
	public class main extends Sprite 
	{
		//プロパティ
		private var base:Sprite;
		private var words:Vector.<Shape>;
		private var isMouseOut:Boolean = true;
		private var degree:Number;
		private var axisDegree:Number;
		private var itemNum:uint=20;
		private var radius:Number;
		
		public function main()
		{
			init();
		}
		
		private function init():void
		{
			base = new Sprite();
			base.x = stage.stageWidth / 2;
			base.y = stage.stageHeight / 2;
			addChild(base);
			var g:Graphics = base.graphics;
			g.beginFill(0x000000, 0);
			g.drawRect( -stage.stageWidth / 2, -stage.stageHeight / 2, stage.stageWidth, stage.stageHeight);
			g.endFill();

			
			var projection:PerspectiveProjection = this.transform.perspectiveProjection;
			projection.projectionCenter = new Point(stage.stageWidth / 2, stage.stageHeight / 2);
			projection.fieldOfView = 60;
			
			degree = Math.PI/50;
			axisDegree = Math.PI * Math.random();
			
			setWord();
			
			addEventListener(Event.ENTER_FRAME, loopHandler);
			stage.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
			stage.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
			
		}
		
		private function setWord():void
		{
			words= new Vector.<Shape>(itemNum);
			
			var wordStings:Vector.<String> = new Vector.<String>(itemNum);
			wordStings[0] = "Flash"
			wordStings[1] = "AS3.0"
			wordStings[2] = "Sprite"
			wordStings[3] = "Shape"
			wordStings[4] = "Bitmap"
			wordStings[5] = "Object"
			wordStings[6] = "Vector"
			wordStings[7] = "Array"
			wordStings[8] = "TextField"
			wordStings[9] = "String"
			wordStings[10] = "Number"
			wordStings[11] = "Uint"
			wordStings[12] = "Matrix3D"
			wordStings[13] = "Vector3D"
			wordStings[14] = "addChild"
			wordStings[15] = "removeChild"
			wordStings[16] = "ENTER_FRAME"
			wordStings[17] = "CLICK"
			wordStings[18] = "Rotation"
			wordStings[19] = "江頭2:50"
			
			var dotTextContainer:dotText;
			for (var i:uint = 0; i < itemNum; i++)
			{
				dotTextContainer = new dotText(wordStings[i]);
				words[i] = dotTextContainer.shapeText;
				base.addChild(words[i]);
			}
			
			setPosition();
			
		}
		
		private function setPosition():void
		{
			var angleAlpha:Number;
			var angleBeta:Number;
			radius = 180;
			for (var i:uint = 0; i < itemNum; i++)
			{
				angleAlpha = Math.acos((2 * (i + 1) - 1) / itemNum - 1);
				angleBeta = Math.sqrt(itemNum * Math.PI) * angleAlpha;
				words[i].x = radius * Math.cos(angleBeta) * Math.sin(angleAlpha);
				words[i].y = radius * Math.cos(angleAlpha);
				words[i].z = radius * Math.sin(angleBeta) * Math.sin(angleAlpha);
			}
			
		}
		
		private function loopHandler(e:Event):void 
		{
		
			if (isMouseOut) {
				degree *= 0.97;
			}else {
				degree=-Math.max(Math.abs(mouseY - stage.stageHeight / 2), Math.abs(mouseX - stage.stageWidth / 2)) / 4000;
			}
			
			axisDegree = Math.PI/2 + Math.atan2((mouseY - stage.stageHeight / 2), (mouseX - stage.stageWidth / 2));
			
			var vx:Number = Math.cos(axisDegree);
			var vy:Number = Math.sin(axisDegree);
			var myCos:Number = Math.cos(degree);
			var mySin:Number = Math.sin(degree);
			
			var posX:Number;
			var posY:Number;
			var posZ:Number;
			for (var i:uint = 0; i < itemNum; i++)
			{
				posX= words[i].x*((1 - myCos) *Math.pow(vx,2) + myCos) + words[i].y*(vx * vy*(1 - myCos)) - words[i].z*vy * mySin;
				posY= words[i].x*(vx * vy*(1 - myCos)) +words[i].y*((1 - myCos) * Math.pow(vy,2) + myCos) +words[i].z*vx* mySin;
				posZ= words[i].x*vy * mySin - words[i].y*vx * mySin +words[i].z*myCos;

				words[i].x = posX;
				words[i].y = posY;
				words[i].z = posZ;
				
			}
			
		}
		
		private function mouseOutHandler(e:MouseEvent):void 
		{
			isMouseOut = true;
		}
		
		private function mouseOverHandler(e:MouseEvent):void 
		{
			isMouseOut = false;
		}
		
		
	}
	
}

import flash.display.*;
import flash.geom.*;
import flash.text.*;

class dotText extends Shape
{
	public var shapeText:Shape;
	
	public function dotText(word:String)
	{
		//テキストフィールド作成
		var myText:TextField = new TextField();
		var myTextFormat:TextFormat = new TextFormat();
		myTextFormat.size = 30;
		myText.defaultTextFormat = myTextFormat;
		myText.autoSize = "left";
		myText.textColor = 0xffffff;
		myText.text = word;
		
		var textWidth:Number = myText.width;
		var textHeight:Number = myText.height;
		
		var bmd:BitmapData = new BitmapData(textWidth, textHeight, true, 0xffffff);
		bmd.draw(myText);
		
		var step:uint = 2;
		var cnt:uint = 0;
		var pos:Vector.<Point> = new Vector.<Point>();
		for (var i:Number = 0; i < textWidth; i += step)
		{
			for (var j:Number = 0; j < textHeight; j += step)
			{
				var chechColor:uint = bmd.getPixel(i, j);
				if (chechColor == 0xffffff)
				{
					pos[cnt] = new Point(i, j);
					cnt++;
				}
			}
		}

		bmd.lock();
		for (i = 0; i < cnt; i++)
		{
			var mypos:Point = pos[i];
			bmd.setPixel(mypos.x, mypos.y, 0x000000);
		}
		bmd.unlock();
	
		shapeText = new Shape();
		var mtrx:Matrix = new Matrix();
		mtrx.translate( -textWidth / 2, -textHeight / 2);
		var g:Graphics = shapeText.graphics;
		g.beginBitmapFill(bmd,mtrx);
		g.drawRect(-textWidth/2, -textHeight/2, textWidth, textHeight);
		g.endFill();
		
	}
	
}