public void RenderBasicScene()
        {
            Plane floor = new Plane();

            floor.Material                   = new Material();
            floor.Material.Reflective        = 0.75;
            floor.Material.Pattern           = new Checkers(new Color(0.85, 0, 0), new Color(0.85, 0.85, 0.85));
            floor.Material.Pattern.Transform = Transformation.Translation(0, 0.01, 0);

            Sphere left = new Sphere();

            left.Transform                  = Transformation.Translation(-1.40, 0.33, -0.50) * Transformation.Scaling(0.33, 0.33, 0.33);
            left.Material                   = new Material();
            left.Material.Pattern           = new Gradient(new Color(0.85, 0, 0), new Color(0.85, 0.85, 0.85));
            left.Material.Pattern.Transform = Transformation.Scaling(2, 1, 1) * Transformation.Translation(-0.5, 0.0, 0.0);

            Sphere mid = new Sphere();

            mid.Transform                  = Transformation.Translation(-1, 1, 0.75);
            mid.Material                   = new Material();
            mid.Material.Pattern           = new Gradient(new Color(0.85, 0, 0), new Color(0.85, 0.85, 0.85));
            mid.Material.Pattern.Transform = Transformation.Scaling(2, 1, 1) * Transformation.Translation(-0.5, 0.0, 0.0);

            Sphere right = new Sphere();

            right.Transform                  = Transformation.Translation(-0.25, 0.5, -0.5) * Transformation.Scaling(0.5, 0.5, 0.5);
            right.Material                   = new Material();
            right.Material.Pattern           = new Gradient(new Color(0.85, 0, 0), new Color(0.85, 0.85, 0.85));
            right.Material.Pattern.Transform = Transformation.Scaling(2, 1, 1) * Transformation.Translation(-0.5, 0.0, 0.0);

            World world = new World();

            world.Shapes = new List <Shape> {
                floor, left, mid, right
            };
            world.Lights = new List <ILight> {
                new PointLight(new Point(-10, 10, -10), new Color(1, 1, 1))
            };

            Camera camera = new Camera(200, 120, Math.PI / 3);

            camera.Transform = Transformation.ViewTransform(new Point(0, 1.5, -5),
                                                            new Point(0, 1, 0),
                                                            new Vector(0, 1, 0));

            Canvas canvas = camera.Render(world);


            string filename = imagePath.ToString() + "BasicReflection.ppm";

            if (File.Exists(filename))
            {
                File.Delete(filename);
            }
            FileStream   stream = File.OpenWrite(filename);
            StreamWriter writer = new StreamWriter(stream);

            PpmWriter.WriteCanvasToPpm(writer, canvas);
            writer.Close();
        }
Exemple #2
0
        public void PpmFileWithLongLines_ShouldSplitLinesAt70CharsMax()
        {
            var writer   = new StringWriter();
            var myCanvas = new Canvas(10, 2);
            var myColor  = new Color(1, 0.8, 0.6);

            for (int w = 0; w < 10; w++)
            {
                for (int h = 0; h < 2; h++)
                {
                    myCanvas.SetPixel(w, h, myColor);
                }
            }
            PpmWriter.WriteCanvasToPpm(writer, myCanvas);
            writer.Close();
            Assert.Equal(
                @"P3
10 2
255
255 204 153 255 204 153 255 204 153 255 204 153 255 204 153 255 204 
153 255 204 153 255 204 153 255 204 153 255 204 153 
255 204 153 255 204 153 255 204 153 255 204 153 255 204 153 255 204 
153 255 204 153 255 204 153 255 204 153 255 204 153 
", writer.ToString());
        }
Exemple #3
0
        private static void SaveFrame(Frame frame)
        {
            var ppmWriter = new PpmWriter(OutputFolder);
            var filePath  = ppmWriter.Write(frame, FileName);

            Console.WriteLine($"Successfully written to {filePath} !");
        }
        public void RenderBasicScene()
        {
            var cube = new Cube(new Point(-1, -1, -1), new Point(1, 1, 1))
            {
                Transform = Transformation.Translation(0, 0, 0),
                Material  = new Material()
                {
                    Color           = new Color(1, 0, 0),
                    Ambient         = 0.2,
                    Diffuse         = 0.1,
                    Specular        = 0.9,
                    Shininess       = 50,
                    Transparency    = 0.9,
                    Reflective      = 0.2,
                    RefractiveIndex = 1.0,
                },
            };

            World world = new World();

            world.Shapes = new List <Shape> {
                hexagon(), cube
            };

            // ======================================================
            // light sources
            // ======================================================

            world.Lights = new List <ILight> {
                new PointLight(new Point(0, 6.9, -5), new Color(1, 1, 0.9))
            };

            // ======================================================
            // the camera
            // ======================================================

            Camera camera = new Camera(640, 480, 0.785);

            camera.Transform = Transformation.ViewTransform(
                new Point(4, 3, 0),                // view from
                new Point(0, 0, 0),                // view to
                new Vector(0, 1, 0));              // vector up

            Canvas canvas = camera.Render(world);


            string filename = imagePath.ToString() + "Group.ppm";

            if (File.Exists(filename))
            {
                File.Delete(filename);
            }
            FileStream   stream = File.OpenWrite(filename);
            StreamWriter writer = new StreamWriter(stream);

            PpmWriter.WriteCanvasToPpm(writer, canvas);
            writer.Close();
        }
Exemple #5
0
        public void PpmFiles_ShoudBeTerminatedWithNewLine()
        {
            var writer   = new StringWriter();
            var myCanvas = new Canvas(5, 3);

            PpmWriter.WriteCanvasToPpm(writer, myCanvas);
            writer.Close();
            Assert.Equal("\n", writer.ToString().Substring(writer.ToString().Length - 1));
        }
        public void RenderBasicScene()
        {
            var          objFile  = modelPath.ToString() + "utah_teapot_hires.obj";
            FileStream   instream = File.OpenRead(objFile);
            StreamReader reader   = new StreamReader(instream);
            var          objData  = reader.ReadToEnd();

            var parser = new ObjParser(objData);

            parser.Parse();
            var teapot = new Group();

            teapot.AddShapes(parser.Groups);
            teapot.Divide(200);

            World world = new World();

            world.Shapes = new List <Shape> {
                teapot
            };

            // ======================================================
            // light sources
            // ======================================================

            world.Lights = new List <ILight> {
                new PointLight(new Point(-10, 10, -10), new Color(1, 1, 1))
            };

            // ======================================================
            // the camera
            // ======================================================

            Camera camera = new Camera(400, 300, Math.PI / 2);

            camera.Transform = Transformation.ViewTransform(
                new Point(-1.5, 1.5, 0),             // view from
                new Point(0, 0.5, 0),                // view to
                new Vector(0, 1, 0));                // vector up

            Canvas canvas = camera.Render(world);


            string filename = imagePath.ToString() + "SmoothTeapot.ppm";

            if (File.Exists(filename))
            {
                File.Delete(filename);
            }
            FileStream   stream = File.OpenWrite(filename);
            StreamWriter writer = new StreamWriter(stream);

            PpmWriter.WriteCanvasToPpm(writer, canvas);
            writer.Close();
        }
Exemple #7
0
        private static void SaveCanvas(Canvas canvas, string filename)
        {
            if (File.Exists(filename))
            {
                File.Delete(filename);
            }
            FileStream   stream = File.OpenWrite(filename);
            StreamWriter writer = new StreamWriter(stream);

            PpmWriter.WriteCanvasToPpm(writer, canvas);
            writer.Close();
        }
        public void ren(ProgramScene scene, string outputPath)
        {
            List <ILightSource> lightList        = new List <ILightSource>();
            PointLight          pointLightSource = new PointLight {
                Intencity = 0.5f, Position = new Vector3(0, 0, -1)
            };
            AmbientLight ambientLightSource = new AmbientLight {
                Intencity = 0.1f
            };
            DirectionalLight directonalLightSource = new DirectionalLight {
                Intencity = 0.4f, Direction = new Vector3(1, 0.7f, 3)
            };

            lightList.Add(pointLightSource);
            lightList.Add(ambientLightSource);
            lightList.Add(directonalLightSource);

            var    cameraPos = scene.mainCamera.GetCameraPosition();
            Screen screen    = new Screen(_viewportHeight, _viewportWidth, focalLength, cameraPos);
            var    rays      = _raysProvider.GetRays(_width, _height, cameraPos, screen);

            byte[] rgb = new byte[_width * _height * 3];

            List <SphereObject> spheresLst  = new List <SphereObject>();
            List <MeshObject>   meshObjects = new List <MeshObject>();

            foreach (var obj in scene.objects)
            {
                if (obj is SphereObject)
                {
                    spheresLst.Add((SphereObject)obj);
                }
                if (obj is MeshObject)
                {
                    meshObjects.Add((MeshObject)obj);
                }
            }

            if (spheresLst.Count > 0)
            {
                renderSpheres(spheresLst, rays, ref rgb, lightList);
            }
            if (meshObjects.Count > 0)
            {
                renderMeshs(meshObjects, rays, ref rgb, lightList);
            }
            Image     image  = new Image(_width, _height, rgb);
            PpmWriter writer = new PpmWriter();

            writer.Write(outputPath, image);
        }
Exemple #9
0
        public void SaveBlankCanvas_ShouldWriteCanvasToStream()
        {
            var writer   = new StringWriter();
            var myCanvas = new Canvas(5, 3);

            PpmWriter.WriteCanvasToPpm(writer, myCanvas);
            writer.Close();
            Assert.Equal(
                @"P3
5 3
255
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
", writer.ToString());
        }
Exemple #10
0
        public void ProjectSphereAgainstWall()
        {
            Point  ray_origin    = new Point(0, 0, -5);
            int    canvas_pixels = 100;
            double wall_z        = 10.0;
            double wall_size     = 7.0;

            World  world  = new World();
            Canvas canvas = new Canvas(canvas_pixels, canvas_pixels);
            Color  color  = new Color(1, 0, 0);
            Sphere shape  = new Sphere();

            double pixel_size = wall_size / canvas_pixels;
            double half       = wall_size / 2;

            for (int y = 0; y < canvas.Height; y++)
            {
                // compute the world y coordinate (top = +half, bottom = -half)
                double world_y = half - pixel_size * y;
                for (int x = 0; x < canvas.Width; x++)
                {
                    double world_x         = -half + pixel_size * x;
                    Point  position        = new Point(world_x, world_y, wall_z);
                    Ray    r               = new Ray(ray_origin, (position - ray_origin).Normalize());
                    List <Intersection> xs = shape.Intersect(r);
                    if (r.Hit(xs) != null)
                    {
                        canvas.SetPixel(x, canvas.Height - y, color);
                    }
                }
            }


            string filename = imagePath.ToString() + "BasicSphere.ppm";

            if (File.Exists(filename))
            {
                File.Delete(filename);
            }
            FileStream   stream = File.OpenWrite(filename);
            StreamWriter writer = new StreamWriter(stream);

            PpmWriter.WriteCanvasToPpm(writer, canvas);
            writer.Close();
        }
        public static void Main()
        {
            var image = new RayTracer.Image(1800,1800);

            var ppmWriter = new PpmWriter();

            var random = new Random();
            for(int i=0; i < image.Width; i++)
            {
                for (int j = 0; j < image.Height; j++)
                {
                    image.SetPixel(new Point(i,j), Color.FromArgb(random.Next(0,255), random.Next(0, 255), random.Next(0, 255)));
                }
            }

            ppmWriter.Write("foo.ppm", image);

            // won't be using openTK
            //using (var game = new GameWindow())
            //{
            //    game.Load += (sender, e) =>
            //    {
            //    };

            //    game.Resize += (sender, e) =>
            //    {
            //    };

            //    game.UpdateFrame += (sender, e) =>
            //    {
            //    };

            //    game.RenderFrame += (sender, e) =>
            //    {
            //    };

            //    game.Run(60.0);
            //}
        }
Exemple #12
0
        public void SaveColoredCanvas_ShouldWriteCanvasToStream()
        {
            var writer   = new StringWriter();
            var myCanvas = new Canvas(5, 3);
            var red      = new Color(1.5, 0, 0);
            var blueish  = new Color(0, 0.5, 0);
            var green    = new Color(-0.5, 0, 1);

            myCanvas.SetPixel(0, 0, red);
            myCanvas.SetPixel(2, 1, blueish);
            myCanvas.SetPixel(4, 2, green);
            PpmWriter.WriteCanvasToPpm(writer, myCanvas);
            writer.Close();
            Assert.Equal(
                @"P3
5 3
255
255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 128 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 255 
", writer.ToString());
        }
Exemple #13
0
        /*public void Render(string sourcePath, string outputPath)
         * {
         *
         *  PointLight lightSource = new PointLight { Intencity = 0.7f, Position = new Vector3(5, 2, -2) };
         *  var obj = _objLoader.LoadObj(sourcePath);
         *  var cameraPos = _camera.GetCameraPosition();
         *  Screen screen = new Screen(_viewportHeight, _viewportWidth, focalLength, cameraPos);
         *  var rays = _raysProvider.GetRays(_width, _height, cameraPos, screen);
         *  var triangles = getTrianglesList(obj);
         *  var tree = new Octree(triangles);
         *  byte[] rgb = new byte[_width * _height * 3];
         *
         *  for (int i = 0; i < rays.Count; i++)
         *  {
         *      var ray = rays[i];
         *      Vector3 pixelColor = new Vector3(1, 1, 1);
         *      if (tree.CheckChildNodes(ray))
         *      {
         *          pixelColor = RayColor(ray, lightSource);
         *      }
         *      //Vector3 pixelColor = RayColor(rays[i], triangles, lightSource);
         *      WriteColor(ref rgb, pixelColor, i);
         *  }
         *
         *  Image image = new Image(_width, _height, rgb);
         *  PpmWriter writer = new PpmWriter();
         *  writer.Write(outputPath, image);
         *
         * }*/


        public void Render(string sourcePath, string outputPath)
        {
            PointLight lightSource = new PointLight {
                Intencity = 0.7f, Position = new Vector3(0, 0, -1f)
            };
            var    cameraPos = _camera.GetCameraPosition();
            Screen screen    = new Screen(_viewportHeight, _viewportWidth, focalLength, cameraPos);
            var    rays      = _raysProvider.GetRays(_width, _height, cameraPos, screen);
            var    obj       = _objLoader.LoadObj(sourcePath);
            var    triangles = getTrianglesList(obj);

            byte[] rgb = new byte[_width * _height * 3];

            for (int i = 0; i < rays.Count; i++)
            {
                Draw(rays[i], triangles, i, lightSource, ref rgb);
            }

            Image     image  = new Image(_width, _height, rgb);
            PpmWriter writer = new PpmWriter();

            writer.Write(outputPath, image);
        }
        public void OutputBasicProjectileToImageFile()
        {
            var cannonBall = new Projectile {
                Position = new Point(0, 1, 0),
                Velocity = new Vector(1, 1.8, 0).Normalize() * 11.25
            };
            var earth = new Environment {
                Gravity = new Vector(0, -0.1, 0),
                Wind    = new Vector(-0.01, 0, 0)
            };
            var canvas = new Canvas(900, 550);


            string filename = imagePath.ToString() + "Projectile.ppm";

            if (File.Exists(filename))
            {
                File.Delete(filename);
            }
            FileStream   stream = File.OpenWrite(filename);
            StreamWriter writer = new StreamWriter(stream);


            while (cannonBall.Position.y > 0)
            {
                canvas.SetPixel((int)Math.Round(cannonBall.Position.x),
                                canvas.Height - (int)Math.Round(cannonBall.Position.y),
                                new Color(1, 0, 0));
                cannonBall = Tick(cannonBall, earth);
            }

            Console.WriteLine($"CannonBall traveled to position {cannonBall.Position.x}");

            PpmWriter.WriteCanvasToPpm(writer, canvas);
            writer.Close();
        }
        public void RenderBasicScene()
        {
            Plane floor = new Plane();

            floor.Transform         = Transformation.Scaling(10, 0.01, 10);
            floor.Material          = new Material();
            floor.Material.Color    = new Color(1, 0.9, 0.9);
            floor.Material.Specular = 0;

            Sphere middle = new Sphere();

            middle.Transform         = Transformation.Translation(-0.5, 1, 0.5);
            middle.Material          = new Material();
            middle.Material.Color    = new Color(0.1, 1, 0.5);
            middle.Material.Diffuse  = 0.7;
            middle.Material.Specular = 0.3;

            Sphere right = new Sphere();

            right.Transform         = Transformation.Translation(1.5, 0.5, -0.5) * Transformation.Scaling(0.5, 0.5, 0.5);
            right.Material          = new Material();
            right.Material.Color    = new Color(0.5, 1, 0.1);
            right.Material.Diffuse  = 0.7;
            right.Material.Specular = 0.3;

            Sphere left = new Sphere();

            left.Transform         = Transformation.Translation(-1.5, 0.33, -0.75) * Transformation.Scaling(0.33, 0.33, 0.33);
            left.Material          = new Material();
            left.Material.Color    = new Color(1, 0.8, 0.1);
            left.Material.Diffuse  = 0.7;
            left.Material.Specular = 0.3;

            World world = new World();

            world.Shapes = new List <Shape> {
                left, right, middle, floor
            };
            world.Lights = new List <ILight> {
                new PointLight(new Point(-10, 10, -10), new Color(1, 1, 1))
            };

            Camera camera = new Camera(200, 120, Math.PI / 3);

            camera.Transform = Transformation.ViewTransform(new Point(0, 1.5, -5),
                                                            new Point(0, 1, 0),
                                                            new Vector(0, 1, 0));

            Canvas canvas = camera.Render(world);


            string filename = imagePath.ToString() + "BasicSceneWithPlanes.ppm";

            if (File.Exists(filename))
            {
                File.Delete(filename);
            }
            FileStream   stream = File.OpenWrite(filename);
            StreamWriter writer = new StreamWriter(stream);

            PpmWriter.WriteCanvasToPpm(writer, canvas);
            writer.Close();
        }
        public void RenderBasicScene()
        {
            var floor = new Plane();

            floor.Transform          = Transformation.Translation(0, -10, 0);
            floor.Material           = new Material();
            floor.Material.Pattern   = new Checkers(new Color(0, 0, 0), new Color(1, 1, 1));
            floor.Material.Ambient   = 0.1;
            floor.Material.Diffuse   = 0.9;
            floor.Material.Specular  = 0.9;
            floor.Material.Shininess = 200;

            var innerSphere = new Sphere();

            innerSphere.HitBy                    = RayType.Primary | RayType.Reflection | RayType.Refraction;
            innerSphere.Transform                = Transformation.Scaling(0.5, 0.5, 0.5);
            innerSphere.Material                 = new Material();
            innerSphere.Material.Ambient         = 0;
            innerSphere.Material.Diffuse         = 0.1;
            innerSphere.Material.Specular        = 0.9;
            innerSphere.Material.Shininess       = 300;
            innerSphere.Material.Reflective      = 1;
            innerSphere.Material.Transparency    = 1;
            innerSphere.Material.RefractiveIndex = 1.00029;

            var outerSphere = new Sphere();

            innerSphere.HitBy                    = RayType.Primary | RayType.Reflection | RayType.Refraction;
            outerSphere.Material                 = new Material();
            outerSphere.Material.Ambient         = 0;
            outerSphere.Material.Diffuse         = 0.1;
            outerSphere.Material.Specular        = 0.9;
            outerSphere.Material.Shininess       = 300;
            outerSphere.Material.Reflective      = 1;
            outerSphere.Material.Transparency    = 1;
            outerSphere.Material.RefractiveIndex = 1.52;

            World world = new World();

            world.Shapes = new List <Shape> {
                floor, innerSphere, outerSphere
            };
            world.Lights = new List <ILight> {
                new PointLight(new Point(20, 10, 0), new Color(0.7, 0.7, 0.7))
            };

            Camera camera = new Camera(300, 300, Math.PI / 3);

            camera.Transform = Transformation.ViewTransform(new Point(0, 2.5, 0),
                                                            new Point(0, 0, 0),
                                                            new Vector(-1, 0, 0));

            Canvas canvas = camera.Render(world);


            string filename = imagePath.ToString() + "SphereInSphere.ppm";

            if (File.Exists(filename))
            {
                File.Delete(filename);
            }
            FileStream   stream = File.OpenWrite(filename);
            StreamWriter writer = new StreamWriter(stream);

            PpmWriter.WriteCanvasToPpm(writer, canvas);
            writer.Close();
        }
        public void RenderBasicScene()
        {
            // ======================================================
            // describe the elements of the scene
            // ======================================================

            // floor/ceiling
            var floorCeiling = new Cube();

            floorCeiling.Transform                  = Transformation.Scaling(20, 7, 20) * Transformation.Translation(0, 1, 0);
            floorCeiling.Material                   = new Material();
            floorCeiling.Material.Pattern           = new Checkers(new Color(0, 0, 0), new Color(0.25, 0.25, 0.25));
            floorCeiling.Material.Pattern.Transform = Transformation.Scaling(0.07, 0.07, 0.07);
            floorCeiling.Material.Ambient           = 0.25;
            floorCeiling.Material.Diffuse           = 0.7;
            floorCeiling.Material.Specular          = 0.9;
            floorCeiling.Material.Shininess         = 300;
            floorCeiling.Material.Reflective        = 0.1;

            // walls
            var walls = new Cube();

            walls.Transform                  = Transformation.Scaling(10, 10, 10);
            walls.Material                   = new Material();
            walls.Material.Pattern           = new Checkers(new Color(0.4863, 0.3765, 0.2941), new Color(0.3725, 0.2902, 0.2275));
            walls.Material.Pattern.Transform = Transformation.Scaling(0.05, 20, 0.05);
            walls.Material.Ambient           = 0.1;
            walls.Material.Diffuse           = 0.7;
            walls.Material.Specular          = 0.9;
            walls.Material.Shininess         = 300;
            walls.Material.Reflective        = 0.1;

            // table top
            var tableTop = new Cube();

            tableTop.Transform                  = Transformation.Translation(0, 3.1, 0) * Transformation.Scaling(3, 0.1, 2);
            tableTop.Material                   = new Material();
            tableTop.Material.Pattern           = new Stripe(new Color(0.5529, 0.4235, 0.3255), new Color(0.6588, 0.5098, 0.4000));
            tableTop.Material.Pattern.Transform = Transformation.Scaling(0.05, 0.05, 0.05) * Transformation.Rotation_y(0.1);
            tableTop.Material.Ambient           = 0.1;
            tableTop.Material.Diffuse           = 0.7;
            tableTop.Material.Specular          = 0.9;
            tableTop.Material.Shininess         = 300;
            tableTop.Material.Reflective        = 0.2;

            // leg #1
            var leg1 = new Cube();

            leg1.Transform        = Transformation.Translation(2.7, 1.5, -1.7) * Transformation.Scaling(0.1, 1.5, 0.1);
            leg1.Material         = new Material();
            leg1.Material.Color   = new Color(0.5529, 0.4235, 0.3255);
            leg1.Material.Ambient = 0.2;
            leg1.Material.Diffuse = 0.7;

            // leg #2
            var leg2 = new Cube();

            leg2.Transform        = Transformation.Translation(2.7, 1.5, 1.7) * Transformation.Scaling(0.1, 1.5, 0.1);
            leg2.Material         = new Material();
            leg2.Material.Color   = new Color(0.5529, 0.4235, 0.3255);
            leg2.Material.Ambient = 0.2;
            leg2.Material.Diffuse = 0.7;

            // leg #3
            var leg3 = new Cube();

            leg3.Transform        = Transformation.Translation(-2.7, 1.5, -1.7) * Transformation.Scaling(0.1, 1.5, 0.1);
            leg3.Material         = new Material();
            leg3.Material.Color   = new Color(0.5529, 0.4235, 0.3255);
            leg3.Material.Ambient = 0.2;
            leg3.Material.Diffuse = 0.7;

            // leg #4
            var leg4 = new Cube();

            leg4.Transform        = Transformation.Translation(-2.7, 1.5, 1.7) * Transformation.Scaling(0.1, 1.5, 0.1);
            leg4.Material         = new Material();
            leg4.Material.Color   = new Color(0.5529, 0.4235, 0.3255);
            leg4.Material.Ambient = 0.2;
            leg4.Material.Diffuse = 0.7;

            // glass cube
            var glassCube = new Cube();

            glassCube.Transform                = Transformation.Translation(0, 3.45001, 0) * Transformation.Rotation_y(0.2) * Transformation.Scaling(0.25, 0.25, 0.25);
            glassCube.HitBy                    = RayType.Primary | RayType.Reflection | RayType.Refraction;
            glassCube.Material                 = new Material();
            glassCube.Material.Color           = new Color(1, 1, 0.8);
            glassCube.Material.Ambient         = 0;
            glassCube.Material.Diffuse         = 0.3;
            glassCube.Material.Specular        = 0.9;
            glassCube.Material.Shininess       = 300;
            glassCube.Material.Reflective      = 0.7;
            glassCube.Material.Transparency    = 0.7;
            glassCube.Material.RefractiveIndex = 1.5;

            // little cube #1
            var littleCube1 = new Cube();

            littleCube1.Transform           = Transformation.Translation(1, 3.35, -0.9) * Transformation.Rotation_y(-0.4) * Transformation.Scaling(0.15, 0.15, 0.15);
            littleCube1.Material            = new Material();
            littleCube1.Material.Color      = new Color(1, 0.5, 0.5);
            littleCube1.Material.Reflective = 0.6;
            littleCube1.Material.Diffuse    = 0.4;

            // little cube #2
            var littleCube2 = new Cube();

            littleCube2.Transform      = Transformation.Translation(-1.5, 3.27, 0.3) * Transformation.Rotation_y(0.4) * Transformation.Scaling(0.15, 0.07, 0.15);
            littleCube2.Material       = new Material();
            littleCube2.Material.Color = new Color(1, 1, 0.5);

            // little cube #3
            var littleCube3 = new Cube();

            littleCube3.Transform      = Transformation.Translation(0, 3.25, 1) * Transformation.Rotation_y(0.4) * Transformation.Scaling(0.2, 0.05, 0.05);
            littleCube3.Material       = new Material();
            littleCube3.Material.Color = new Color(0.5, 1, 0.5);

            // little cube #4
            var littleCube4 = new Cube();

            littleCube4.Transform      = Transformation.Translation(-0.6, 3.4, -1) * Transformation.Rotation_y(0.8) * Transformation.Scaling(0.05, 0.2, 0.05);
            littleCube4.Material       = new Material();
            littleCube4.Material.Color = new Color(0.5, 0.5, 1);

            // little cube #5
            var littleCube5 = new Cube();

            littleCube5.Transform      = Transformation.Translation(2, 3.4, 1) * Transformation.Rotation_y(0.8) * Transformation.Scaling(0.05, 0.2, 0.05);
            littleCube5.Material       = new Material();
            littleCube5.Material.Color = new Color(0.5, 1, 1);

            // mirror
            var mirror = new Cube();

            mirror.Transform           = Transformation.Translation(-2, 3.5, 9.95) * Transformation.Scaling(4.8, 1.4, 0.06);
            mirror.Material            = new Material();
            mirror.Material.Color      = new Color(0, 0, 0);
            mirror.Material.Diffuse    = 0;
            mirror.Material.Ambient    = 0;
            mirror.Material.Specular   = 1;
            mirror.Material.Shininess  = 300;
            mirror.Material.Reflective = 1;

            // frame #1
            var frame1 = new Cube();

            frame1.Transform        = Transformation.Translation(-10, 4, 1) * Transformation.Scaling(0.05, 1, 1);
            frame1.Material         = new Material();
            frame1.Material.Color   = new Color(0.7098, 0.2471, 0.2196);
            frame1.Material.Diffuse = 0.6;

            // frame #2
            var frame2 = new Cube();

            frame2.Transform        = Transformation.Translation(-10, 3.4, 2.7) * Transformation.Scaling(0.05, 0.4, 0.4);
            frame2.Material         = new Material();
            frame2.Material.Color   = new Color(0.2667, 0.2706, 0.6902);
            frame2.Material.Diffuse = 0.6;

            // frame #3
            var frame3 = new Cube();

            frame3.Transform        = Transformation.Translation(-10, 4.6, 2.7) * Transformation.Scaling(0.05, 0.4, 0.4);
            frame3.Material         = new Material();
            frame3.Material.Color   = new Color(0.3098, 0.5961, 0.3098);
            frame3.Material.Diffuse = 0.6;

            // frame #4
            var frame4 = new Cube();

            frame4.Transform        = Transformation.Translation(-2, 3.5, 9.95) * Transformation.Scaling(5, 1.5, 0.05);
            frame4.Material         = new Material();
            frame4.Material.Color   = new Color(0.3882, 0.2627, 0.1882);
            frame4.Material.Diffuse = 0.7;

            World world = new World();

            world.Shapes = new List <Shape> {
                walls, floorCeiling, tableTop, leg1, leg2, leg3, leg4, glassCube, mirror, frame1, frame2, frame3, frame4, littleCube1, littleCube2, littleCube3, littleCube4, littleCube5
            };

            // ======================================================
            // light sources
            // ======================================================

            world.Lights = new List <ILight> {
                new PointLight(new Point(0, 6.9, -5), new Color(1, 1, 0.9))
            };

            // ======================================================
            // the camera
            // ======================================================

            Camera camera = new Camera(600, 300, 0.785);

            camera.Transform = Transformation.ViewTransform(
                new Point(5, 6, -8),               // view from
                new Point(0, 3, 0),                // view to
                new Vector(0, 1, 0));              // vector up

            Canvas canvas = camera.Render(world);


            string filename = imagePath.ToString() + "Cubes.ppm";

            if (File.Exists(filename))
            {
                File.Delete(filename);
            }
            FileStream   stream = File.OpenWrite(filename);
            StreamWriter writer = new StreamWriter(stream);

            PpmWriter.WriteCanvasToPpm(writer, canvas);
            writer.Close();
        }
        public void RenderBasicScene()
        {
            var floor = new Plane();

            floor.Material                   = new Material();
            floor.Material.Pattern           = new Checkers(new Color(0.5, 0.5, 0.5), new Color(0.75, 0.75, 0.75));
            floor.Material.Pattern.Transform = Transformation.Rotation_y(0.3) * Transformation.Scaling(0.25, 0.25, 0.25);
            floor.Material.Ambient           = 0.2;
            floor.Material.Diffuse           = 0.9;
            floor.Material.Specular          = 0;

            var cyl = new Cylinder();

            cyl.Minimum             = 0;
            cyl.Maximum             = 0.75;
            cyl.IsClosed            = true;
            cyl.Transform           = Transformation.Translation(-1, 0, 1) * Transformation.Scaling(0.5, 1, 0.5);
            cyl.Material            = new Material();
            cyl.Material.Color      = new Color(0, 0, 0.6);
            cyl.Material.Diffuse    = 0.1;
            cyl.Material.Specular   = 0.9;
            cyl.Material.Shininess  = 300;
            cyl.Material.Reflective = 0.9;

            var decCyl1 = new Cylinder();

            decCyl1.Minimum            = 0;
            decCyl1.Maximum            = 0.3;
            decCyl1.IsClosed           = true;
            decCyl1.Transform          = Transformation.Translation(0, 0, -0.75) * Transformation.Scaling(0.05, 1, 0.05);
            decCyl1.Material           = new Material();
            decCyl1.Material.Color     = new Color(1, 0, 0);
            decCyl1.Material.Ambient   = 0.1;
            decCyl1.Material.Diffuse   = 0.9;
            decCyl1.Material.Specular  = 0.9;
            decCyl1.Material.Shininess = 300;

            var decCyl2 = new Cylinder();

            decCyl2.Minimum            = 0;
            decCyl2.Maximum            = 0.3;
            decCyl2.IsClosed           = true;
            decCyl2.Transform          = Transformation.Translation(0, 0, -2.25) * Transformation.Rotation_y(-0.15) * Transformation.Translation(0, 0, 1.5) * Transformation.Scaling(0.05, 1, 0.05);
            decCyl2.Material           = new Material();
            decCyl2.Material.Color     = new Color(1, 1, 0);
            decCyl2.Material.Ambient   = 0.1;
            decCyl2.Material.Diffuse   = 0.9;
            decCyl2.Material.Specular  = 0.9;
            decCyl2.Material.Shininess = 300;

            var decCyl3 = new Cylinder();

            decCyl3.Minimum            = 0;
            decCyl3.Maximum            = 0.3;
            decCyl3.IsClosed           = true;
            decCyl3.Transform          = Transformation.Translation(0, 0, -2.25) * Transformation.Rotation_y(-0.3) * Transformation.Translation(0, 0, 1.5) * Transformation.Scaling(0.05, 1, 0.05);
            decCyl3.Material           = new Material();
            decCyl3.Material.Color     = new Color(0, 1, 0);
            decCyl3.Material.Ambient   = 0.1;
            decCyl3.Material.Diffuse   = 0.9;
            decCyl3.Material.Specular  = 0.9;
            decCyl3.Material.Shininess = 300;

            var decCyl4 = new Cylinder();

            decCyl4.Minimum            = 0;
            decCyl4.Maximum            = 0.3;
            decCyl4.IsClosed           = true;
            decCyl4.Transform          = Transformation.Translation(0, 0, -2.25) * Transformation.Rotation_y(-0.45) * Transformation.Translation(0, 0, 1.5) * Transformation.Scaling(0.05, 1, 0.05);
            decCyl4.Material           = new Material();
            decCyl4.Material.Color     = new Color(0, 1, 1);
            decCyl4.Material.Ambient   = 0.1;
            decCyl4.Material.Diffuse   = 0.9;
            decCyl4.Material.Specular  = 0.9;
            decCyl4.Material.Shininess = 300;

            var glassCyl = new Cylinder();

            glassCyl.Minimum                  = 0.0001;
            glassCyl.Maximum                  = 0.5;
            glassCyl.IsClosed                 = true;
            glassCyl.Transform                = Transformation.Translation(0, 0, -1.5) * Transformation.Scaling(0.33, 1, 0.33);
            glassCyl.Material                 = new Material();
            glassCyl.Material.Color           = new Color(0.25, 0, 0);
            glassCyl.Material.Diffuse         = 0.1;
            glassCyl.Material.Specular        = 0.9;
            glassCyl.Material.Shininess       = 300;
            glassCyl.Material.Reflective      = 0.9;
            glassCyl.Material.Transparency    = 0.9;
            glassCyl.Material.RefractiveIndex = 1.5;

            var conCentCyl1 = new Cylinder();

            conCentCyl1.Minimum            = 0;
            conCentCyl1.Maximum            = 0.2;
            conCentCyl1.IsClosed           = false;
            conCentCyl1.Transform          = Transformation.Translation(1, 0, 0) * Transformation.Scaling(0.8, 1, 0.8);
            conCentCyl1.Material           = new Material();
            conCentCyl1.Material.Color     = new Color(1, 1, 0.3);
            conCentCyl1.Material.Ambient   = 0.1;
            conCentCyl1.Material.Diffuse   = 0.8;
            conCentCyl1.Material.Specular  = 0.9;
            conCentCyl1.Material.Shininess = 300;

            var conCentCyl2 = new Cylinder();

            conCentCyl2.Minimum            = 0;
            conCentCyl2.Maximum            = 0.3;
            conCentCyl2.IsClosed           = false;
            conCentCyl2.Transform          = Transformation.Translation(1, 0, 0) * Transformation.Scaling(0.6, 1, 0.6);
            conCentCyl2.Material           = new Material();
            conCentCyl2.Material.Color     = new Color(1, 0.9, 0.4);
            conCentCyl2.Material.Ambient   = 0.1;
            conCentCyl2.Material.Diffuse   = 0.8;
            conCentCyl2.Material.Specular  = 0.9;
            conCentCyl2.Material.Shininess = 300;

            var conCentCyl3 = new Cylinder();

            conCentCyl3.Minimum            = 0;
            conCentCyl3.Maximum            = 0.4;
            conCentCyl3.IsClosed           = false;
            conCentCyl3.Transform          = Transformation.Translation(1, 0, 0) * Transformation.Scaling(0.4, 1, 0.4);
            conCentCyl3.Material           = new Material();
            conCentCyl3.Material.Color     = new Color(1, 0.8, 0.5);
            conCentCyl3.Material.Ambient   = 0.1;
            conCentCyl3.Material.Diffuse   = 0.8;
            conCentCyl3.Material.Specular  = 0.9;
            conCentCyl3.Material.Shininess = 300;

            var conCentCyl4 = new Cylinder();

            conCentCyl4.Minimum            = 0;
            conCentCyl4.Maximum            = 0.5;
            conCentCyl4.IsClosed           = true;
            conCentCyl4.Transform          = Transformation.Translation(1, 0, 0) * Transformation.Scaling(0.2, 1, 0.2);
            conCentCyl4.Material           = new Material();
            conCentCyl4.Material.Color     = new Color(1, 0.7, 0.6);
            conCentCyl4.Material.Ambient   = 0.1;
            conCentCyl4.Material.Diffuse   = 0.8;
            conCentCyl4.Material.Specular  = 0.9;
            conCentCyl4.Material.Shininess = 300;

            World world = new World();

            world.Shapes = new List <Shape> {
                floor, cyl, decCyl1, decCyl2, decCyl3, decCyl4, glassCyl, conCentCyl1, conCentCyl2, conCentCyl3, conCentCyl4
            };

            // ======================================================
            // light sources
            // ======================================================

            world.Lights = new List <ILight> {
                new PointLight(new Point(1, 6.9, -4.9), new Color(1, 1, 1))
            };

            // ======================================================
            // the camera
            // ======================================================

            Camera camera = new Camera(400, 200, 0.314);

            camera.Transform = Transformation.ViewTransform(
                new Point(8, 3.5, -9),               // view from
                new Point(0, 0.3, 0),                // view to
                new Vector(0, 1, 0));                // vector up

            Canvas canvas = camera.Render(world);


            string filename = imagePath.ToString() + "Cylinders.ppm";

            if (File.Exists(filename))
            {
                File.Delete(filename);
            }
            FileStream   stream = File.OpenWrite(filename);
            StreamWriter writer = new StreamWriter(stream);

            PpmWriter.WriteCanvasToPpm(writer, canvas);
            writer.Close();
        }
Exemple #19
0
        public void ProjectSphereWithMaterialAgainstWall()
        {
            Point  ray_origin    = new Point(0, 0, -5);
            int    canvas_pixels = 100;
            double wall_z        = 10.0;
            double wall_size     = 7.0;

            World  world  = new World();
            Canvas canvas = new Canvas(canvas_pixels, canvas_pixels);
            Sphere shape  = new Sphere();

            shape.Material.Color = new Color(1, 0.2, 1);
            //shape.Material.Specular = 0.1;
            //shape.Material.Diffuse = 0.1;
            //shape.Material.Ambient = 0.5;

            var light_position = new Point(-10, -10, -10);
            var light_color    = new Color(1, 1, 1);
            var light          = new PointLight(light_position, light_color);

            //shape.Transform = Transformation.Scaling(1, 0.5, 1);
            //shape.Transform = Transformation.Scaling(0.5, 1, 1);
            //shape.Transform = Transformation.Rotation_z(Math.PI / 4) * Transformation.Scaling(0.5, 1, 1);
            //shape.Transform = Transformation.Shearing(1, 0, 0, 0, 0, 0) * Transformation.Scaling(0.5, 1, 1);

            double pixel_size = wall_size / canvas_pixels;
            double half       = wall_size / 2;

            for (int y = 0; y < canvas.Height; y++)
            {
                // compute the world y coordinate (top = +half, bottom = -half)
                double world_y = half - pixel_size * y;
                for (int x = 0; x < canvas.Width; x++)
                {
                    double world_x         = -half + pixel_size * x;
                    Point  position        = new Point(world_x, world_y, wall_z);
                    Ray    r               = new Ray(ray_origin, (position - ray_origin).Normalize());
                    List <Intersection> xs = shape.Intersect(r);
                    var hit_intersect      = r.Hit(xs);
                    if (hit_intersect != null)
                    {
                        var hit_point = r.Position(hit_intersect.Time);
                        var normal    = shape.NormalAt(hit_point);
                        var eye       = -r.Direction;
                        var hit_color = shape.Material.Lighting(shape, light, hit_point, eye, normal);
                        canvas.SetPixel(x, canvas.Height - y, hit_color);
                    }
                }
            }


            string filename = imagePath.ToString() + "SphereWithMaterial.ppm";

            if (File.Exists(filename))
            {
                File.Delete(filename);
            }
            FileStream   stream = File.OpenWrite(filename);
            StreamWriter writer = new StreamWriter(stream);

            PpmWriter.WriteCanvasToPpm(writer, canvas);
            writer.Close();
        }
Exemple #20
0
        public void RenderBasicScene()
        {
            // ======================================================
            // define constants to avoid duplication
            // ======================================================

            var wallMaterial = new Material();

            wallMaterial.Pattern           = new Stripe(new Color(0.45, 0.45, 0.45), new Color(0.55, 0.55, 0.55));
            wallMaterial.Pattern.Transform = Transformation.Scaling(0.25, 0.25, 0.25);
            wallMaterial.Ambient           = 0;
            wallMaterial.Diffuse           = 0.4;
            wallMaterial.Specular          = 0;
            wallMaterial.Reflective        = 0.3;

            // ======================================================
            // describe the elements of the scene
            // ======================================================

            // the checkered floor
            var floor = new Plane()
            {
                Transform = Transformation.Rotation_y(0.31415),

                Material = new Material()
                {
                    Pattern = new Checkers(new Color(0.35, 0.35, 0.35), new Color(0.65, 0.65, 0.65))
                    {
                        Transform = Transformation.Translation(0, 0.01, 0)
                    },
                    Specular   = 0,
                    Reflective = 0.4,
                }
            };

            // the ceiling
            var ceiling = new Plane()
            {
                Transform = Transformation.Translation(0, 5, 0),
                Material  = new Material()
                {
                    Color    = new Color(0.8, 0.8, 0.8),
                    Ambient  = 0.3,
                    Specular = 0
                }
            };

            // west wall
            var westWall = new Plane();

            westWall.Transform = Transformation.Translation(-5, 0, 0) * Transformation.Rotation_z(1.5708) * Transformation.Rotation_y(1.5708);
            westWall.Material  = wallMaterial;

            // east wall
            var eastWall = new Plane();

            eastWall.Transform = Transformation.Translation(5, 0, 0) * Transformation.Rotation_z(1.5708) * Transformation.Rotation_y(1.5708);
            eastWall.Material  = wallMaterial;

            // north wall
            var northWall = new Plane();

            northWall.Transform = Transformation.Translation(0, 0, 5) * Transformation.Rotation_x(1.5708);
            northWall.Material  = wallMaterial;

            // south wall
            var southWall = new Plane();

            southWall.Transform = Transformation.Translation(0, 0, -5) * Transformation.Rotation_x(1.5708);
            southWall.Material  = wallMaterial;

            // ----------------------
            // background balls
            // ----------------------

            var bgGroup1 = new Group();
            var bg1      = new Sphere();

            bg1.Transform          = Transformation.Translation(4.6, 0.4, 1) * Transformation.Scaling(0.4, 0.4, 0.4);
            bg1.Material           = new Material();
            bg1.Material.Color     = new Color(0.8, 0.5, 0.3);
            bg1.Material.Shininess = 50;
            bgGroup1.AddShape(bg1);

            var bg2 = new Sphere();

            bg2.Transform          = Transformation.Translation(4.7, 0.3, 0.4) * Transformation.Scaling(0.3, 0.3, 0.3);
            bg2.Material           = new Material();
            bg2.Material.Color     = new Color(0.9, 0.4, 0.5);
            bg2.Material.Shininess = 50;
            bgGroup1.AddShape(bg2);

            var bgGroup2 = new Group();
            var bg3      = new Sphere();

            bg3.Transform          = Transformation.Translation(-1, 0.5, 4.5) * Transformation.Scaling(0.5, 0.5, 0.5);
            bg3.Material           = new Material();
            bg3.Material.Color     = new Color(0.4, 0.9, 0.6);
            bg3.Material.Shininess = 50;
            bgGroup2.AddShape(bg3);

            var bg4 = new Sphere();

            bg4.Transform          = Transformation.Translation(-1.7, 0.3, 4.7) * Transformation.Scaling(0.3, 0.3, 0.3);
            bg4.Material           = new Material();
            bg4.Material.Color     = new Color(0.4, 0.6, 0.9);
            bg4.Material.Shininess = 50;
            bgGroup2.AddShape(bg4);

            // ----------------------
            // foreground balls
            // ----------------------

            var fgGroup = new Group();
            // red sphere
            var redSphere = new Sphere();

            redSphere.Transform          = Transformation.Translation(-0.6, 1, 0.6);
            redSphere.Material           = new Material();
            redSphere.Material.Color     = new Color(1, 0.3, 0.2);
            redSphere.Material.Specular  = 0.4;
            redSphere.Material.Shininess = 5;
            fgGroup.AddShape(redSphere);

            // blue glass sphere
            var blueGlassSphere = new Sphere();

            blueGlassSphere.Transform                = Transformation.Translation(0.6, 0.7, -0.6) * Transformation.Scaling(0.7, 0.7, 0.7);
            blueGlassSphere.Material                 = new Material();
            blueGlassSphere.Material.Color           = new Color(0, 0, 0.2);
            blueGlassSphere.Material.Ambient         = 0;
            blueGlassSphere.Material.Diffuse         = 0.4;
            blueGlassSphere.Material.Specular        = 0.9;
            blueGlassSphere.Material.Shininess       = 300;
            blueGlassSphere.Material.Reflective      = 0.9;
            blueGlassSphere.Material.Transparency    = 0.9;
            blueGlassSphere.Material.RefractiveIndex = 1.5;
            fgGroup.AddShape(blueGlassSphere);

            // green glass sphere
            var greenGlassSphere = new Sphere();

            greenGlassSphere.Transform                = Transformation.Translation(-0.7, 0.5, -0.8) * Transformation.Scaling(0.5, 0.5, 0.5);
            greenGlassSphere.Material                 = new Material();
            greenGlassSphere.Material.Color           = new Color(0, 0.2, 0);
            greenGlassSphere.Material.Ambient         = 0;
            greenGlassSphere.Material.Diffuse         = 0.4;
            greenGlassSphere.Material.Specular        = 0.9;
            greenGlassSphere.Material.Shininess       = 300;
            greenGlassSphere.Material.Reflective      = 0.9;
            greenGlassSphere.Material.Transparency    = 0.9;
            greenGlassSphere.Material.RefractiveIndex = 1.5;
            fgGroup.AddShape(greenGlassSphere);

            World world = new World();

            world.Shapes = new List <Shape> {
                floor, ceiling, westWall, eastWall, northWall, southWall, bgGroup1, bgGroup2, fgGroup
            };

            // ======================================================
            // light sources
            // ======================================================

            world.Lights = new List <ILight> {
                new PointLight(new Point(-4.9, 4.9, -1), new Color(1, 1, 1))
            };

            // ======================================================
            // the camera
            // ======================================================

            Camera camera = new Camera(400, 300, 1.152);

            camera.Transform = Transformation.ViewTransform(
                new Point(-2.6, 1.5, -3.9),              // view from
                new Point(-0.6, 1, -0.8),                // view to
                new Vector(0, 1, 0));                    // vector up

            Canvas canvas = camera.Render(world);


            string filename = imagePath.ToString() + "BasicRefraction.ppm";

            if (File.Exists(filename))
            {
                File.Delete(filename);
            }
            FileStream   stream = File.OpenWrite(filename);
            StreamWriter writer = new StreamWriter(stream);

            PpmWriter.WriteCanvasToPpm(writer, canvas);
            writer.Close();
        }
Exemple #21
0
        public void RenderBasicScene()
        {
            var floor = new Plane();

            floor.Material                   = new Material();
            floor.Material.Pattern           = new Checkers(new Color(0.5, 0.5, 0.5), new Color(0.75, 0.75, 0.75));
            floor.Material.Pattern.Transform = Transformation.Rotation_y(0.3) * Transformation.Scaling(0.25, 0.25, 0.25);
            floor.Material.Ambient           = 0.2;
            floor.Material.Diffuse           = 0.9;
            floor.Material.Specular          = 0;

            var cone = new Cone();

            cone.Minimum             = 0;
            cone.Maximum             = 1;
            cone.IsClosed            = true;
            cone.Transform           = Transformation.Translation(-1, 0, 1) * Transformation.Scaling(0.5, 1, 0.5);
            cone.Material            = new Material();
            cone.Material.Color      = new Color(0, 0, 0.6);
            cone.Material.Diffuse    = 0.1;
            cone.Material.Specular   = 0.9;
            cone.Material.Shininess  = 300;
            cone.Material.Reflective = 0.9;

            var cone2 = new Cone();

            cone2.Minimum            = -1;
            cone2.Maximum            = 1;
            cone2.IsClosed           = true;
            cone2.Transform          = Transformation.Translation(0, 0, -0.75) * Transformation.Scaling(0.05, 1, 0.05);
            cone2.Material           = new Material();
            cone2.Material.Color     = new Color(1, 0, 0);
            cone2.Material.Ambient   = 0.1;
            cone2.Material.Diffuse   = 0.9;
            cone2.Material.Specular  = 0.9;
            cone2.Material.Shininess = 300;

            var cone3 = new Cone();

            cone3.Minimum            = -1;
            cone3.Maximum            = 0;
            cone3.IsClosed           = true;
            cone3.Transform          = Transformation.Translation(0, 0, -2.25) * Transformation.Rotation_y(-0.15) * Transformation.Translation(0, 0, 1.5) * Transformation.Scaling(0.05, 1, 0.05);
            cone3.Material           = new Material();
            cone3.Material.Color     = new Color(1, 1, 0);
            cone3.Material.Ambient   = 0.1;
            cone3.Material.Diffuse   = 0.9;
            cone3.Material.Specular  = 0.9;
            cone3.Material.Shininess = 300;

            var cone4 = new Cone();

            cone4.Minimum            = 0;
            cone4.Maximum            = 2;
            cone4.IsClosed           = false;
            cone4.Transform          = Transformation.Translation(0, 0, -2.25) * Transformation.Rotation_y(-0.3) * Transformation.Translation(0, 0, 1.5) * Transformation.Scaling(0.05, 1, 0.05);
            cone4.Material           = new Material();
            cone4.Material.Color     = new Color(0, 1, 0);
            cone4.Material.Ambient   = 0.1;
            cone4.Material.Diffuse   = 0.9;
            cone4.Material.Specular  = 0.9;
            cone4.Material.Shininess = 300;

            World world = new World();

            world.Shapes = new List <Shape> {
                floor, cone, cone2, cone3, cone4
            };

            // ======================================================
            // light sources
            // ======================================================

            world.Lights = new List <ILight> {
                new PointLight(new Point(1, 6.9, -4.9), new Color(1, 1, 1))
            };

            // ======================================================
            // the camera
            // ======================================================

            Camera camera = new Camera(400, 200, 0.314);

            camera.Transform = Transformation.ViewTransform(
                new Point(8, 3.5, -9),               // view from
                new Point(0, 0.3, 0),                // view to
                new Vector(0, 1, 0));                // vector up

            Canvas canvas = camera.Render(world);


            string filename = imagePath.ToString() + "Cones.ppm";

            if (File.Exists(filename))
            {
                File.Delete(filename);
            }
            FileStream   stream = File.OpenWrite(filename);
            StreamWriter writer = new StreamWriter(stream);

            PpmWriter.WriteCanvasToPpm(writer, canvas);
            writer.Close();
        }