コード例 #1
0
        public void Then_PatternAt_Of_pattern_Should_Be_Color(double x, double y, double z, double red, double green, double blue)
        {
            var expectedColor = new RtColor(red, green, blue);
            var actualColor   = _patternsContext.Pattern.PatternAt(new RtPoint(x, y, z));

            Assert.Equal(expectedColor, actualColor);
        }
コード例 #2
0
        public void Run(Sphere shape)
        {
            var rayOrigin = new RtPoint(0, 0, -5);
            var wallZ     = 10;
            var color     = new RtColor(1.0, 0, 0);

            var wallSize   = 7.0;
            var canvasSize = 800;

            var canvas = new Canvas(canvasSize, canvasSize);

            var pixelSize = wallSize / canvasSize;

            var half = wallSize / 2;

            Parallel.For(0, canvasSize, y =>
            {
                for (int x = 0; x < canvasSize; x++)
                {
                    var worldY = half - pixelSize * y;
                    var worldX = -half + pixelSize * x;

                    var position = new RtPoint(worldX, worldY, wallZ);

                    var ray = new Ray(rayOrigin, (position - rayOrigin).Normalize());

                    if (shape.Intersect(ray).Count > 0)
                    {
                        canvas[x, y] = color;
                    }
                }
            });

            PpmOutput.WriteToFile("sphere.ppm", canvas.GetPPMContent());
        }
コード例 #3
0
        public void Then_pixel_at_Should_Equal_Color(int x, int y, double red, double green, double blue)
        {
            var expectedColor = new RtColor(red, green, blue);

            var actaulColor = _cameraContext.Image[x, y];

            Assert.Equal(expectedColor, actaulColor);
        }
コード例 #4
0
        public void Then_color1_Multiplied_By_color2_Should_Equal_Color(double red, double green, double blue)
        {
            var expectedColor = new RtColor(red, green, blue);

            var actualColor = _colorContext.Color1 * _colorContext.Color2;

            Assert.Equal(expectedColor, actualColor);
        }
コード例 #5
0
        private static void Draw(Canvas canvas, RtPoint position)
        {
            var x = (int)Math.Round(position.X);
            var y = canvas.Height - (int)Math.Round(position.Y) - 1;

            if (x >= 0 && x <= canvas.Width - 1 && y >= 0 && y <= canvas.Height - 1)
            {
                canvas[x, y] = new RtColor(1, 0, 0);
            }
        }
コード例 #6
0
 public void When_Every_Pixel_Of_canvas_Is_Set_To_Color(double red, double green, double blue)
 {
     for (int i = 0; i < _canvas.Width; i++)
     {
         for (int j = 0; j < _canvas.Height; j++)
         {
             _canvas[i, j] = new RtColor(red, green, blue);
         }
     }
 }
コード例 #7
0
        public void Then_Every_Pixel_Of_canvas_Is_Color(double red, double green, double blue)
        {
            var expectedColor = new RtColor(red, green, blue);

            for (int x = 0; x < _canvas.Width - 1; x++)
            {
                for (int y = 0; y < _canvas.Height - 1; y++)
                {
                    RtColor actualColor = _canvas[x, y];
                    Assert.Equal(expectedColor, actualColor);
                }
            }
        }
コード例 #8
0
 private static Plane CreateWall(double yRotate, RtPoint location, RtColor color)
 {
     return(new Plane()
     {
         Transform = new Transform()
                     .RotateX(Math.PI / 2)
                     .RotateY(yRotate)
                     .Translation(location),
         Material = new Material()
         {
             Color = color,
             Specular = 1
         }
     });
 }
コード例 #9
0
        //public RtMatrix Multiplication()
        //{
        //    var results = new RtMatrix(0, 0);
        //    for (int c = 0; c < 1000; c++)
        //    {
        //        var matrix1 = CreateMatrix(256);
        //        var matrix2 = CreateMatrix(256);
        //        results = matrix1 * matrix2;
        //    }

        //    return results;
        //}

        //private static RtMatrix CreateMatrix(int size)
        //{
        //    var matrix = new RtMatrix(size, size);
        //    var rnd = new Random(unchecked((int)DateTime.Now.Ticks));
        //    for (int x = 0; x < size; x++)
        //    {
        //        for (int y = 0; y < size; y++)
        //        {
        //            matrix[x, y] = rnd.NextDouble() * 10;
        //        }
        //    }

        //    return matrix;
        //}

        public void BuildImageFromChapterFix()
        {
            var rayOrigin = new RtPoint(0, 0, -5);

            var wallZ      = 10;
            var wallSize   = 7.0;
            var canvasSize = 800;

            var canvas = new Canvas(canvasSize, canvasSize);

            var pixelSize = wallSize / canvasSize;

            var half = wallSize / 2;

            var color = new RtColor(1, 0, 0);
            var shape = new Sphere
            {
                Transform = new Transform()
                            .Scaling(0.5, 1, 1)
                            .Shearing(1, 0, 0, 0, 0, 0)
            };

            for (int y = 0; y < canvasSize; y++)
            {
                var worldY = half - pixelSize * y;
                for (int x = 0; x < canvasSize; x++)
                {
                    var worldX = -half + pixelSize * x;

                    var position = new RtPoint(worldX, worldY, wallZ);

                    var ray           = new Ray(rayOrigin, (position - rayOrigin).Normalize());
                    var intersections = shape.Intersect(ray);
                    if (intersections.HasHit())
                    {
                        canvas[x, y] = color;
                    }
                }
            }
        }
コード例 #10
0
        public void Then_result_Should_Equal_Color(double red, double green, double blue)
        {
            var expectedColor = new RtColor(red, green, blue);

            Assert.Equal(expectedColor, _materialsContext.Results);
        }
コード例 #11
0
        public void Then_Color_Of_material_Should_Equal_Color(double red, double green, double blue)
        {
            var expectedColor = new RtColor(red, green, blue);

            Assert.Equal(expectedColor, _materialsContext.Material.Color);
        }
コード例 #12
0
        public void Then_PatternAt_Of_pattern_Should_Equal_white(double x, double y, double z)
        {
            RtColor actualColor = _patternsContext.Pattern.PatternAt(new RtPoint(x, y, z));

            Assert.Equal(_colorContext.White, actualColor);
        }