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

四角いBitmapを極座標変換する

PhotoShopの極座標変換みたいな
* 三角でのアプローチをやめて、getBixel,setPixelで描く
* ディザを取れたら完璧なんだけど…難しそう
* DisplacementMap作成中
// forked from Kay's 四角いBitmapを三角にする
/*
 * PhotoShopの極座標変換みたいな
 * 三角でのアプローチをやめて、getBixel,setPixelで描く
 * ディザを取れたら完璧なんだけど…難しそう
 * DisplacementMap作成中
 */
package {
	import flash.display.Sprite;
	import flash.display.Shape;
	import flash.display.Loader;
	import flash.display.BitmapData;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFieldAutoSize;
	import flash.net.URLRequest; 
	import flash.system.Security;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;

	[SWF(backgroundColor=0x000000)]
	public class Take09 extends Sprite {
		private const SW:Number = stage.stageWidth;
		private const SH:Number = stage.stageHeight;
		private var loader:Loader;
		private var textfield:TextField;
		private var newBitmapData:BitmapData;
		private var newShape:Shape = new Shape();

		public function Take09():void {
			addChild(newShape);
			// infomation
			var textFormat:TextFormat = new TextFormat();
			textFormat.color = 0x00ff00;
			textfield = new TextField();
			textfield.defaultTextFormat = textFormat;
			textfield.setTextFormat(textFormat);
			textfield.autoSize = TextFieldAutoSize.LEFT;
			textfield.text = 'NowLoading...';
			addChild(textfield);
			
			// Bitmap読み込み
			var url:String = "http://www.seeda.jp/";
			Security.loadPolicyFile(url + "crossdomain.xml");
			loader = new Loader();
			loader.load(new URLRequest(url + "flash/visitor.jpg"));
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete);
		}
		
		private function drawCircle():void {
			stage.removeEventListener(MouseEvent.CLICK, sceenChange);
			loader.visible = false;
			newShape.graphics.beginBitmapFill(newBitmapData);
			newShape.graphics.drawRect(0,0,SW,SH);
			newShape.graphics.endFill();
		}
		
		private function sceenChange(e:MouseEvent):void {
			textfield.text = "Complete";
			drawCircle();
		}

		private function onComplete(e:Event):void {
			var bitmapData:BitmapData = new BitmapData(loader.content.width, loader.content.height,true);
			bitmapData.draw(loader);
			
			// ステージサイズ一杯に描く
			var radius:Number = Math.sqrt(Math.pow(SW/2,2)+Math.pow(SH/2,2));
			var bitmapCenter:Point = new Point(bitmapData.width/2, bitmapData.height/2);
			var stageCenter :Point = new Point(SW/2, SH/2);
			
			newBitmapData = new BitmapData(SW,SH);
			for (var h:uint = 0; h < SW; h++) {
				for (var v:uint = 0; v < SH; v++) {
					// ステージセンターからの距離と角度を求める
					var p:Point = new Point(h,v);
					var distance:Number = Point.distance(stageCenter,p);
					var radian:Number = Math.atan2(p.y-stageCenter.y, p.x-stageCenter.x)+Math.PI;
					var target:Point = new Point();
					target.x = radian / (Math.PI*2) * bitmapData.width-1;
					target.y = distance / radius * bitmapData.height;
					var color:uint = bitmapData.getPixel(target.x,target.y);
					newBitmapData.setPixel(h, v, color);
				}
			}
			// 読み込んだ画像を表示してマウスクリックを待つ
			addChild(loader);
			loader.x = (SW-loader.width)/2;
			loader.y = (SH-loader.height)/2;
			stage.addEventListener(MouseEvent.CLICK, sceenChange);
			textfield.text = "Click Screen";
		}
	}
}