flash on 2009-11-19
どっかに普通にあると思うけど一応おいとく
/**
* Copyright nutsu ( http://wonderfl.net/user/nutsu )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/oLfj
*/
package {
//どっかに普通にあると思うけど一応おいとく
import frocessing.display.F5MovieClip2D;
[SWF(width=465,height=465,frameRate=60,backgroundColor=0)]
public class FlashTest extends F5MovieClip2D {
private var x0:Number;
private var y0:Number;
private var x1:Number;
private var y1:Number;
private var x2:Number;
private var y2:Number;
private var cx:Number;
private var cy:Number;
private var r:Number;
public function FlashTest() {
init();
}
public function draw():void{
noFill();
stroke(255);
triangle( x0, y0, x1, y1, x2, y2 );
stroke(127);
circle( cx, cy, r );
if( inOuterCircle( mouseX, mouseY ) ){
fill( 255 );
}else{
fill(0);
}
circle( mouseX, mouseY, 5 );
}
public function mousePressed():void{
init();
}
private function init():void{
x0 = random(100,350);
y0 = random(100,350);
x1 = random(100,350);
y1 = random(100,350);
x2 = random(100,350);
y2 = random(100,350);
//外円:外積0のときの例外処理入れてない
cx = ((y1-y2)*(x0*x0+y0*y0) + (y2-y0)*(x1*x1+y1*y1) + (y0-y1)*(x2*x2+y2*y2))/((x1-x0)*(y2-y0)-(y1-y0)*(x2-x0))/2;
cy = ((x2-x1)*(x0*x0+y0*y0) + (x0-x2)*(x1*x1+y1*y1) + (x1-x0)*(x2*x2+y2*y2))/((x1-x0)*(y2-y0)-(y1-y0)*(x2-x0))/2;
r = Math.sqrt((x0 - cx) * (x0 - cx) + (y0 - cy) * (y0 - cy));
}
private function inOuterCircle( x:Number, y:Number ):Boolean{
var d:Number = (x0*x0 + y0*y0 - x*x - y*y)*((x1-x)*(y2-y)-(x2-x)*(y1-y)) +
(x1*x1 + y1*y1 - x*x - y*y)*((x2-x)*(y0-y)-(y2-y)*(x0-x)) +
(x2*x2 + y2*y2 - x*x - y*y)*((x0-x)*(y1-y)-(y0-y)*(x1-x));
return ( (x1-x0)*(y2-y0)-(y1-y0)*(x2-x0)>0 ) ? d>0 : d<=0;
}
}
}