diff options
-rw-r--r-- | raytracer.hs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/raytracer.hs b/raytracer.hs index 9d60e8c..8bc697d 100644 --- a/raytracer.hs +++ b/raytracer.hs @@ -19,10 +19,12 @@ x_of (x, _, _) = x y_of (_, y, _) = y z_of (_, _, z) = z -sphere1 = Sphere (80, 43, 5) 10 (55,255,0) -sphere2 = Sphere (30, 65, -5) 20 (255,60,0) +sphere1 = Sphere (80, 80, 5) 10 (55,255,0) +sphere2 = Sphere (80, -80, -5) 20 (255,60,0) +sphere3 = Sphere (-80, 80, -5) 20 (5,60,200) +sphere4 = Sphere (-80, -80, -5) 20 (0,255,255) -spheres = [sphere1, sphere2] +spheres = [sphere1, sphere2, sphere3, sphere4] alpha1 = 120 * degrees @@ -123,7 +125,10 @@ skycolor source (alpha, beta) = (60, data SphereIntersect = SphereIntersect Double Color deriving (Eq, Show) -- distance color instance Ord SphereIntersect where - (SphereIntersect d1 _) `compare` (SphereIntersect d2 _) = d1 `compare` d2 + (SphereIntersect d1 _) `compare` (SphereIntersect d2 _) + | d2 == 0 = LT + | d1 == 0 = GT + | otherwise = d1 `compare` d2 nearest_sphere :: Coord -> ScreenCoord -> [Sphere] -> SphereIntersect nearest_sphere source scoord spheres = @@ -193,4 +198,5 @@ allpixels = map ov_color ov_pixels image = imgheader ++ (foldr (++) "" (map pixel_to_ppm allpixels)) -main = writeFile "foo.ppm" image +main = do putStrLn "Rendering"; + writeFile "foo.ppm" image |