Exemplo n.º 1
0
        public void ShouldExtendInBothXAndZInRingPattern(float x, float y, float z, bool expectingWhite)
        {
            var pattern = new RingPattern(VColor.White, VColor.Black);

            AssertActualEqualToExpected(
                pattern.GetColorAt(CreatePoint(x, y, z)),
                expectingWhite ? VColor.White : VColor.Black);
        }
Exemplo n.º 2
0
        public void RingPattern()
        {
            var p = new RingPattern(Color.White, Color.Black);

            Assert.That.VectorsAreEqual(p.At(Point(0f, 0f, 0f)), Color.White);
            Assert.That.VectorsAreEqual(p.At(Point(1f, 0f, 0f)), Color.Black);
            Assert.That.VectorsAreEqual(p.At(Point(0f, 0f, 1f)), Color.Black);
            Assert.That.VectorsAreEqual(p.At(Point(.708f, 0f, .708f)), Color.Black);
        }
        public void RingPattern()
        {
            var pattern = new RingPattern(ColourFactory.White, ColourFactory.Black);

            Assert.AreEqual(ColourFactory.White,pattern.PatternAt(new Point(0,0,0)));
            Assert.AreEqual(ColourFactory.Black, pattern.PatternAt(new Point(1, 0, 0)));
            Assert.AreEqual(ColourFactory.Black, pattern.PatternAt(new Point(0, 0, 1)));
            Assert.AreEqual(ColourFactory.Black, pattern.PatternAt(new Point(0.708, 0, 0.708)));
        }
        public void ARingShouldExtendInBothXAndZ()
        {
            var pattern = new RingPattern(Color.WHITE, Color.BLACK);

            Assert.AreEqual(Color.WHITE, pattern.PatternAt(new Point(0, 0, 0)));
            Assert.AreEqual(Color.BLACK, pattern.PatternAt(new Point(1, 0, 0)));
            Assert.AreEqual(Color.BLACK, pattern.PatternAt(new Point(0, 0, 1)));
            Assert.AreEqual(Color.BLACK, pattern.PatternAt(new Point(0.708, 0, 0.708)));
        }
Exemplo n.º 5
0
        public void TestPatternRingCreate()
        {
            var pattern = new RingPattern(Color.White, Color.Black);

            Assert.AreEqual(pattern.PatternAt(Point.Zero), Color.White);
            Assert.AreEqual(pattern.PatternAt(Point.PointX), Color.Black);
            Assert.AreEqual(pattern.PatternAt(Point.PointZ), Color.Black);
            Assert.AreEqual(pattern.PatternAt(new Point(0.708, 0, 0.708)), Color.Black);
        }
Exemplo n.º 6
0
        public void TestRingPatternTransform()
        {
            var pattern = new RingPattern(_white, _black);

            Assert.AreEqual(_white, pattern.ColorAt(Tuple.Point(0, 0, 0)));
            Assert.AreEqual(_black, pattern.ColorAt(Tuple.Point(1, 0, 0)));
            Assert.AreEqual(_black, pattern.ColorAt(Tuple.Point(0, 0, 1)));
            Assert.AreEqual(_black, pattern.ColorAt(Tuple.Point(0.708, 0, 0.708)));
        }
Exemplo n.º 7
0
        public void RingPattern()
        {
            RingPattern pattern = new RingPattern(SolidPattern.White, SolidPattern.Black);

            Assert.True(Color.White == pattern.PatternAt(new Point(0, 0, 0)));
            Assert.True(Color.Black == pattern.PatternAt(new Point(1, 0, 0)));
            Assert.True(Color.Black == pattern.PatternAt(new Point(0, 0, 1)));
            Assert.True(Color.Black == pattern.PatternAt(new Point(0.708f, 0.708f, 0.708f)));
        }
Exemplo n.º 8
0
        public void RingShouldExtendInXAndY()
        {
            var pat = new RingPattern(white, black);

            Assert.Equal(white, pat.GetColor(Vector4.CreatePosition(0, 0, 0)));
            Assert.Equal(black, pat.GetColor(Vector4.CreatePosition(1, 0, 0)));
            Assert.Equal(black, pat.GetColor(Vector4.CreatePosition(0, 0, 1)));
            Assert.Equal(black, pat.GetColor(Vector4.CreatePosition(0.708, 0, 0.708)));
        }
Exemplo n.º 9
0
        public void RingPattern()
        {
            RingPattern pattern = new RingPattern(white, black);

            Assert.AreEqual(pattern.PatternAt(Tuple.Point(0, 0, 0)), white);
            Assert.AreEqual(pattern.PatternAt(Tuple.Point(1, 0, 0)), black);
            Assert.AreEqual(pattern.PatternAt(Tuple.Point(0, 0, 1)), black);
            Assert.AreEqual(pattern.PatternAt(Tuple.Point(0.708, 0, 0.708)), black);
        }
Exemplo n.º 10
0
        public void ColorAt()
        {
            var pattern = new RingPattern(SolidPattern.White, SolidPattern.Black);

            Assert.Equal(Color.White, pattern.ColorAt(new Sphere(), Point.Zero));
            Assert.Equal(Color.Black, pattern.ColorAt(new Sphere(), new Point(1, 0, 0)));
            Assert.Equal(Color.Black, pattern.ColorAt(new Sphere(), new Point(0, 0, 1)));
            Assert.Equal(Color.Black, pattern.ColorAt(new Sphere(), new Point(0.708f, 0, 0.708f)));
        }
        public void A_ring_should_extend_in_both_x_and_z()
        {
            var pattern = new RingPattern(Color.White, Color.Black);

            Assert.AreEqual(Color.White, pattern.ColorAt(Tuple.Point(0, 0, 0)));
            Assert.AreEqual(Color.Black, pattern.ColorAt(Tuple.Point(1, 0, 0)));
            Assert.AreEqual(Color.Black, pattern.ColorAt(Tuple.Point(0, 0, 1)));
            Assert.AreEqual(Color.Black, pattern.ColorAt(Tuple.Point(0.708, 0, 0.708)));
        }
        public void BasicTest()
        {
            var pattern = new RingPattern(Color.White, Color.Black);

            Check.That(pattern.GetColor(Helper.CreatePoint(0, 0, 0))).IsEqualTo(Color.White);
            Check.That(pattern.GetColor(Helper.CreatePoint(1, 0, 0))).IsEqualTo(Color.Black);
            Check.That(pattern.GetColor(Helper.CreatePoint(0, 0, 1))).IsEqualTo(Color.Black);
            Check.That(pattern.GetColor(Helper.CreatePoint(0.708, 0, 0.708))).IsEqualTo(Color.Black);
        }
Exemplo n.º 13
0
        public void T07_Ring()
        {
            Pattern pattern = new RingPattern(new SolidColorPattern(Color.white),
                                              new SolidColorPattern(Color.black));

            Assert.AreEqual(Color.white, pattern.PatternAt(new Point(0, 0, 0)));
            Assert.AreEqual(Color.black, pattern.PatternAt(new Point(1, 0, 0)));
            Assert.AreEqual(Color.black, pattern.PatternAt(new Point(0, 0, 1)));
            Assert.AreEqual(Color.black, pattern.PatternAt(new Point(0.708, 0, 0.708)));
        }
Exemplo n.º 14
0
        private static void TestCase06()
        {
            // A ring should extend in both x and z
            Pattern pattern = new RingPattern(white, black);

            Assert.Equal(white, pattern.ColorAt(Tuple.Point(0, 0, 0)));
            Assert.Equal(black, pattern.ColorAt(Tuple.Point(1, 0, 0)));
            Assert.Equal(black, pattern.ColorAt(Tuple.Point(0, 0, 1)));
            Assert.Equal(black, pattern.ColorAt(Tuple.Point(0.708f, 0, 0.708f)));
        }
        public void ColorAt_should_extend_in_both_x_and_z()
        {
            var pattern = new RingPattern(Colors.White, Colors.Black);

            pattern.ColorAt(new Point(0, 0, 0)).Should().Be(Colors.White);
            pattern.ColorAt(new Point(1, 0, 0)).Should().Be(Colors.Black);
            pattern.ColorAt(new Point(0, 0, 1)).Should().Be(Colors.Black);

            // 0.708 is just slightly more than sqrt(2)/2
            pattern.ColorAt(new Point(0.708, 0, 0.708)).Should().Be(Colors.Black);
        }
Exemplo n.º 16
0
        public void Ring_Extend_In_Both_X_And_Z()
        {
            var pattern    = new RingPattern(Color.White, Color.Black);
            var unitSphere = new Sphere();

            pattern.ColorAt(new Point(0, 0, 0), unitSphere).ShouldBe(Color.White);
            pattern.ColorAt(new Point(1, 0, 0), unitSphere).ShouldBe(Color.Black);
            pattern.ColorAt(new Point(0, 0, 1), unitSphere).ShouldBe(Color.Black);
            pattern.ColorAt(new Point(0, 1, 0), unitSphere).ShouldBe(Color.White);
            pattern.ColorAt(new Point(0.708, 0, 0.708), unitSphere).ShouldBe(Color.Black);
        }
Exemplo n.º 17
0
        public void T11_NestedPatterns()
        {
            if (Scene.current == null)
            {
                new Scene();
            }

            Scene.current.Clear();

            //RadialGradientPattern radialPattern = new RadialGradientPattern();
            RingPattern checkerboard = new RingPattern();

            checkerboard.a = new CheckersPattern(new SolidColorPattern(Color.white), new SolidColorPattern(Color.black));
            checkerboard.b = new CheckersPattern(new SolidColorPattern(Color.red), new SolidColorPattern(Color.green));

            Light light = new Light(new Point(-5, 5, -5), Color.white);
            Plane floor = new Plane();

            floor.material.pattern = checkerboard;

            Plane wall = new Plane();

            wall.SetMatrix(Mat4.RotateXMatrix(Constants.pi / 2.0) *
                           Mat4.TranslateMatrix(0, 0, 4.1));
            wall.material.pattern = checkerboard;
            List <RayObject> temp = Scene.current.GetRayObjects();

            Sphere sphere1 = new Sphere();

            sphere1.SetMatrix(Mat4.TranslateMatrix(0, 0.5, -3) *
                              Mat4.ScaleMatrix(0.5, 0.5, 0.5));
            sphere1.material.pattern = checkerboard;

            Sphere sphere2 = new Sphere();

            sphere2.SetMatrix(Mat4.TranslateMatrix(2, 1.0, -1));
            sphere2.material.pattern = checkerboard;

            Camera camera = new Camera(640, 480, Constants.pi / 3.0);

            //Need to halt execution if I end up with NaN
            camera.ViewTransform(new Point(0, 2, -10),
                                 new Point(0, 2, 4),
                                 new Vector(0, 1, 0));

            Canvas canvas = Scene.current.Render(camera);

            Save.SaveCanvas(canvas, "Chapter10_NestedPatterns");
        }
Exemplo n.º 18
0
        public RingerStatusEventArgs(XmlNode root)
        {
            XmlNodeList nodelist = root.ChildNodes;

            foreach (XmlNode node in nodelist)
            {
                switch (node.Name)
                {
                case "ringMode":
                    ringMode = node.InnerText;
                    break;

                case "ringPattern":
                    ringPattern = (RingPattern)Int32.Parse(node.InnerText);
                    break;

                case "device":
                    device = node.InnerText;
                    break;
                }
            }
        }
 public void Given_ring_pattern(string id, string aId, string bId)
 {
     patterns[id] = new RingPattern(colors[aId], colors[bId]);
 }
Exemplo n.º 20
0
        public static World Example3()
        {
            var world = new World();

            var ringPattern1 = new RingPattern(
                new Color(0.4, 0.4, 0.4),
                new Color(0.7, 0.7, 0.7))
            {
                Transform =
                    Transform.Scale(4, 4, 4),
            };

            var stripePattern1 = new StripePattern(
                new Color(0.2, 0.2, 0.2),
                new Color(0.5, 0.5, 1.0))
            {
                Transform =
                    Transform.Scale(0.1, 0.1, 0.1),
            };

            var checkers = new CheckersPattern(
                Color.White,
                Color.Black)
            {
                Transform =
                    Transform.Scale(1, 1, 1),
            };

            var nestedPattern = new NestedPattern(
                checkers,
                ringPattern1,
                stripePattern1);

            var pertubedPattern = new PertubedPattern(
                new SolidPattern(Color.Black),
                new SolidPattern(new Color(0.1, 0.2, 0.3)))
            {
                Transform = Transform.Scale(5.5, 5.5, 5.5),
            };

            var floor = new Plane
            {
                Material = new Material
                {
                    Pattern  = pertubedPattern,
                    Specular = 0,
                },
            };

            world.Objects.Add(floor);

            var gradientTransform =
                Transform.Translate(1, 0, 0) *
                Transform.Scale(2, 1, 1);

            var sphere = new Sphere
            {
                Transform =
                    Transform.Translate(0, 1, 0),

                Material = new Material
                {
                    Pattern = new GradientPattern(
                        new Color(1.0, 0.0, 0.0),
                        new Color(0.0, 0.0, 1.0))
                    {
                        Transform = gradientTransform,
                    },
                },
            };

            world.Objects.Add(sphere);

            var gradients = new[]
            {
                new GradientPattern(
                    new Color(1.0, 0.0, 0.0),
                    new Color(0.0, 0.0, 1.0))
                {
                    Transform = gradientTransform,
                },
                new GradientPattern(
                    new Color(1.0, 0.0, 0.0),
                    new Color(0.0, 1.0, 0.0))
                {
                    Transform = gradientTransform,
                },
                new GradientPattern(
                    new Color(0.0, 1.0, 0.0),
                    new Color(0.0, 0.0, 1.0))
                {
                    Transform = gradientTransform,
                },
                new GradientPattern(
                    new Color(0.5, 0.5, 0.0),
                    new Color(0.0, 0.5, 0.5))
                {
                    Transform = gradientTransform,
                },
                new GradientPattern(
                    new Color(0.5, 0.0, 0.5),
                    new Color(0.0, 1.0, 0.0))
                {
                    Transform = gradientTransform,
                },
            };

            const int n   = 1024;
            var       arc = 2 * Math.PI / n;

            for (var i = 0; i < n; i++)
            {
                const double r  = 0.15;
                var          gi = i % gradients.Length;

                var          ni      = (double)i / n;
                const double scatter = 15;
                var          q       = scatter * Rng.NextDouble();
                var          s       = new Sphere
                {
                    Transform =
                        Transform.RotateY(i * arc) *
                        Transform.Translate(0, r, 2 - r + q) *
                        Transform.Scale(r, r, r),

                    Material = new Material
                    {
                        Pattern = gradients[gi],
                    },
                };

                world.Objects.Add(s);
            }

            var light = new PointLight(
                Vector4.CreatePosition(-10, 10, -10),
                Color.White);

            world.Lights.Add(light);

            return(world);
        }
Exemplo n.º 21
0
        protected override Canvas Render(CameraRenderOptions options)
        {
            // Patterns
            var checkerPattern = new CheckerPattern(
                new StripePattern(
                    Colors.LightGray,
                    Colors.Gray,
                    Matrix4x4.CreateScaling(0.25, 0.25, 0.25).RotateY(-Math.PI / 8)),
                new GradientPattern(new Color(1, 0.75, 0.75), new Color(1, 0.5, 0.5)),
                Matrix4x4.CreateScaling(0.4, 0.4, 0.4));

            var blendedPattern = new BlendedPattern(
                new StripePattern(new Color(0.9, 1, 0.9), new Color(0, 1, 0), Matrix4x4.CreateRotationY(Math.PI / 2)),
                new StripePattern(new Color(0.9, 1, 0.9), new Color(0, 1, 0)),
                0.5);

            var stripePattern = new StripePattern(
                new GradientPattern(new Color(0.8, 0.8, 1), Colors.Blue),
                new GradientPattern(Colors.Blue, new Color(0.8, 0.8, 1)),
                Matrix4x4.CreateScaling(0.25, 0.25, 0.25)
                .RotateZ(-Math.PI / 4)
                .RotateY(-Math.PI / 6)
                .Translate(0.4, 0, 0));

            var gradientPattern = new RadialGradientPattern(
                Colors.Green,
                Colors.Yellow,
                Matrix4x4.CreateScaling(0.25, 0.25, 0.25).RotateX(-Math.PI / 2));

            var ringPattern = new RingPattern(
                Colors.Red,
                Colors.White,
                Matrix4x4.CreateScaling(0.15, 0.15, 0.15).RotateX(-Math.PI / 2));

            // Shapes
            var floor = new Plane(
                "Floor",
                Matrix4x4.CreateRotationY(Math.PI / 4),
                new Material(pattern: blendedPattern, specular: 0));

            var backWall = new Plane(
                "BackWall",
                Matrix4x4.CreateRotationX(Math.PI / 2).Translate(0, 0, 5),
                new Material(pattern: checkerPattern));

            var left = new Sphere(
                "Left",
                Matrix4x4.CreateScaling(0.33, 0.33, 0.33).Translate(-2, 0.33, -0.75),
                new Material(pattern: ringPattern, diffuse: 0.7, specular: 0.3));

            var middle = new Sphere(
                "Middle",
                Matrix4x4.CreateTranslation(-0.5, 1, 0.5),
                new Material(pattern: stripePattern, diffuse: 0.7, specular: 0.3));

            var right = new Sphere(
                "Right",
                Matrix4x4.CreateScaling(0.5, 0.5, 0.5).Translate(1.5, 0.5, -0.5),
                new Material(pattern: gradientPattern, diffuse: 0.7, specular: 0.3));

            var light = new PointLight(new Point(-10, 10, -10), Colors.White);
            var world = new World(light, floor, backWall, left, middle, right);

            var cameraTransform = Matrix4x4.CreateLookAt(new Point(0, 1.5, -5), new Point(0, 1, 0), Vector.UnitY);
            var camera          = new Camera(CanvasWidth, CanvasHeight, Math.PI / 3, cameraTransform);

            Canvas canvas = camera.Render(world, options);

            return(canvas);
        }