implementation of javascript ray trace