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

Ray Casting

Get Adobe Flash player
by Jacky.Riawan 04 Oct 2010
/**
 * Copyright Jacky.Riawan ( http://wonderfl.net/user/Jacky.Riawan )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/upYN
 */

package {
    import flash.geom.Point;
    import flash.display.Sprite;
    import flash.events.Event
    public class FlashTest extends Sprite {
        private var pointA:Point=new Point(20,20)
        private var pointB:Point=new Point(300,300)
        private var pointC:Point=new Point(200,0)
        private var pointD:Point=new Point(0,300)
        private var speed:Number=2
        public function FlashTest() {
            // write as3 code here..
            
            
            addEventListener(Event.ENTER_FRAME,render)
        }
        private function render(e:Event):void{
            //move points
            pointA.x=mouseX
            pointA.y=mouseY
            pointC.x+=speed
            if(pointC.x>350||pointC.x<0){
                speed*=-1
            }
            //do calc stuffs
            var checkY:Number=pointA.y-pointB.y
            var checkX:Number=pointA.x-pointB.x
            var checkXY:Number=pointA.x*pointB.y-pointA.y*pointB.x
            var checkY2:Number=pointC.y-pointD.y
            var checkX2:Number=pointC.x-pointD.x
            var checkXY2:Number=pointC.x*pointD.y-pointC.y*pointD.x
            var denom:Number=checkY*checkX2-checkY2*checkX
            var intersect:Point=new Point((checkX*checkXY2-checkX2*checkXY)/denom,(checkY*checkXY2-checkY2*checkXY)/denom)
            //draw
            graphics.clear()
            graphics.lineStyle(1)
            graphics.moveTo(pointA.x,pointA.y)
            graphics.lineTo(pointB.x,pointB.y)
            graphics.moveTo(pointC.x,pointC.y)
            graphics.lineTo(pointD.x,pointD.y)
            graphics.drawCircle(intersect.x,intersect.y,10)
        }

    }
}