flash on 2012-3-8
/**
* Copyright bradsedito ( http://wonderfl.net/user/bradsedito )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/ekio
*/
package
{
import flash.display.*;
import flash.events.*;
public class LocatePoint extends Sprite
{
public function LocatePoint()
{
function pointInPolygon(x:Number, y:Number, polyX:Array, polyY:Array):Boolean
{
var j:int = polyX.length - 1;
var oddNodes:Boolean = false;
for (var i:int=0; i <polyX.length; i++) {
if (polyY[i] <y && polyY[j]>= y || polyY[j] <y && polyY[i]>= y) {
if (polyX[i] + (y - polyY[i]) / (polyY[j] - polyY[i]) * (polyX[j] - polyX[i]) <x) {
oddNodes = !oddNodes;
}
}
j = i;
}
return oddNodes;
}
// draw an overly complex poly and store all x y coords
var pX:Array= new Array();
var pY:Array = new Array();
graphics.beginFill(0xCC0000);
for (var i:int = 0; i<60; i++){
pX[i] = Math.random()*stage.stageWidth;
pY[i] =Math.random()*stage.stageHeight;
if (i == 0){
graphics.moveTo(pX[i], pY[i]);
}else{
graphics.lineTo(pX[i], pY[i]);
}
}
addEventListener(Event.ENTER_FRAME, onLoop);
function onLoop(evt:Event):void {
alpha = 1;
if (pointInPolygon(mouseX, mouseY, pX, pY)){
alpha = .5;
}
}
}
}
}