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

三角形と円

Get Adobe Flash player
by 178ep3 02 Oct 2009
/**
 * Copyright 178ep3 ( http://wonderfl.net/user/178ep3 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/vLRF
 */

package
{
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;
	
	public class InnerCenter extends Sprite
	{
		public function InnerCenter()
		{
			var y1_1:Point = new Point(0,465);
			var y1_2:Point = new Point(0,0);
			
			var y2_1:Point = new Point(0,465);
			var y2_2:Point = new Point(0,0);
			
			var line1:Shape = addChild(new Shape())as Shape;
			line1.y = 233;
			drawHLine(line1,0x00);
			
			var line2:Shape = addChild(new Shape())as Shape;
			line2.y = 150;
			drawHLine(line2,0xff0000);
			
			var pointOnLine1_1:Shape = addChild(new Shape())as Shape;
			pointOnLine1_1.x = 180;
			pointOnLine1_1.y = 233;
			drawPoint(pointOnLine1_1);
			var p1_1:Point = new Point(180,233);
			
			var pointOnLine1_2:Shape = addChild(new Shape())as Shape;
			pointOnLine1_2.x = 286;
			pointOnLine1_2.y = 233;
			drawPoint(pointOnLine1_2);
			var p1_2:Point = new Point(286,233);
			
			var pointOnLine2:Shape = addChild(new Shape())as Shape;
			pointOnLine2.y = 150;
			drawPoint(pointOnLine2);
			var p2:Point = new Point(0,150);
			
			var line1_1_2:Shape = addChild(new Shape())as Shape;
			var line1_2_2:Shape = addChild(new Shape())as Shape;
			
			var circle1:Shape = addChild(new Shape())as Shape;
			var c1p:Point = new Point(233,300);
			circle1.x = c1p.x;
			circle1.y = c1p.y;
			var pointC1:Shape = addChild(new Shape())as Shape;
			pointC1.x = c1p.x;
			pointC1.y = c1p.y;
			drawPoint(pointC1);
			
			var Dpoint:Shape = addChild(new Shape())as Shape;
			var oP1:Point = pointD(p2,p1_1,p1_2);
			Dpoint.x = oP1.x;
			Dpoint.y = oP1.y;
			drawPoint(Dpoint);
			var oc1:Shape = addChild(new Shape())as Shape;
			
			var Dpoint2:Shape = addChild(new Shape())as Shape;
			var oP2:Point = pointD(p2,p1_1,p1_2);
			Dpoint2.x = oP2.x;
			Dpoint2.y = oP2.y;
			drawPoint(Dpoint2);
			var oc2:Shape = addChild(new Shape())as Shape;
			
			var Dpoint3:Shape = addChild(new Shape())as Shape;
			var oP3:Point = pointD(p2,p1_1,p1_2);
			Dpoint3.x = oP3.x;
			Dpoint3.y = oP3.y;
			drawPoint(Dpoint3);
			var oc3:Shape = addChild(new Shape())as Shape;
			
			var sp:Number = 7;
			
			addEventListener(Event.ENTER_FRAME,loop);
			
			function loop(e:Event):void
			{
				
				sp = Math.pow(pointOnLine2.x -233,2)/10000+7;
				pointOnLine2.x += sp;
				if(pointOnLine2.x > 4233)pointOnLine2.x = -4767;
				
				p2.x = pointOnLine2.x;
				p2.y = pointOnLine2.y;
	
				y1_1.x = lineFormula(p1_1,p2,y1_1.y).x;
				y1_2.x = lineFormula(p1_1,p2,y1_2.y).x;
				drawLine(line1_1_2,y1_1,y1_2);
				
				y2_1.x = lineFormula(p1_2,p2,y2_1.y).x;
				y2_2.x = lineFormula(p1_2,p2,y2_2.y).x;
				drawLine(line1_2_2,y2_1,y2_2);
				
				c1p = innerPoint(p1_1,p1_2,p2);
				circle1.x = c1p.x;
				circle1.y = c1p.y;
				pointC1.x = c1p.x;
				pointC1.y = c1p.y;
				
				var o:Object = lineFormula(y1_1,y1_2,y1_1.y);
				drawcircle(circle1,distFormula(o,c1p));
				oP1 = innerPoint(p2,p1_1,p1_2,-1);
				Dpoint.x = oP1.x;
				Dpoint.y = oP1.y;
				
				var oo:Object = lineFormula(p1_1,p2,y1_1.y);
				drawcircle(oc1,distFormula(oo,oP1));
				oc1.x = oP1.x;
				oc1.y = oP1.y;
				oP2 = innerPoint(p2,p1_1,p1_2,1,-1);
				Dpoint2.x = oP2.x;
				Dpoint2.y = oP2.y;
				
				var oo2:Object = lineFormula(p1_2,p2,y2_1.y);
				drawcircle(oc2,distFormula(oo2,oP2));
				oc2.x = oP2.x;
				oc2.y = oP2.y;
				
				oP3 = innerPoint(p2,p1_1,p1_2,1,1,-1);
				Dpoint3.x = oP3.x;
				Dpoint3.y = oP3.y;
				var oo3:Object = lineFormula(p1_1,p2,y1_1.y);
				drawcircle(oc3,distFormula(oo3,oP3));
				oc3.x = oP3.x;
				oc3.y = oP3.y;
				
			}	
		}	
		
		private function innerPoint(p1:Point,p2:Point,p3:Point,m1:int=1,m2:int=1,m3:int=1):Point
		{
			var p:Point = new Point(0,0);
			var a:Number = Point.distance(p2,p3)*m1;
			var b:Number = Point.distance(p1,p3)*m2;
			var c:Number = Point.distance(p1,p2)*m3;
			
			p.x = (p1.x*a+p2.x*b+p3.x*c)/(a+b+c);
			p.y = (p1.y*a+p2.y*b+p3.y*c)/(a+b+c);
			return p;
		}
		
		private function lineFormula(p1:Point,p2:Point,y:Number):Object
		{
			var a:Number = (p2.y - p1.y)/(p2.x-p1.x);
			var b:Number = (p2.x*p1.y - p1.x*p2.y)/(p2.x-p1.x);
			var x:Number = (y - b)/a;
			var obj:Object = {a:a,b:b,x:x,y:y};
			return obj;
		}

		private function distFormula(o:Object,p:Point):Number
		{
			var d:Number = Math.abs(o.a*p.x - p.y + o.b) / Math.sqrt(o.a*o.a+1); 
			return d;
		}

		private function pointD(p1:Point,p2:Point,p3:Point):Point
		{
			var a:Number = Point.distance(p1,p2);
			var b:Number = Point.distance(p1,p3);
			var c:Number = Point.distance(p2,p3);
			var q:Number = a/b;
			if(p1.x>233)q = 1-(b/a);
			var p:Point = Point.interpolate(p2,p3,q);
			return p;
		}
		
		private function drawLine(target:Shape,mp:Point,lp:Point):void
		{
			with(target.graphics)
			{
				clear();
				lineStyle(1,0x00);
				moveTo(mp.x,mp.y);
				lineTo(lp.x,lp.y);
				endFill();
			}
		}
		
		private function drawHLine(target:Shape,color:uint):void
		{
			with(target.graphics)
			{
				lineStyle(1,color);
				moveTo(0,0);
				lineTo(465,0);
				endFill();
			}
		}
		
		private function drawcircle(target:Shape,r:Number):void
		{
			if(isNaN(r))r=0;
			with(target.graphics)
			{
				clear();
				beginFill(0xff,0.5);
				drawCircle(0,0,r);
				endFill();
			}
		}
		
		private function drawPoint(target:Shape):void
		{
			with(target.graphics)
			{
				clear();
				lineStyle(1,0x00);
				beginFill(0xff0000);
				drawCircle(0,0,3);
				endFill();
			}
		}
	}
}