public void GradientLinearlyInterpolatesBetweenColors()
        {
            var pattern = new GradientPattern(ColourFactory.White, ColourFactory.Black);

            Assert.AreEqual(ColourFactory.White, pattern.PatternAt(new Point(0, 0, 0)));
            Assert.AreEqual(new Colour(0.75,0.75,0.75), pattern.PatternAt(new Point(0.25, 0, 0)));
            Assert.AreEqual(new Colour(0.5, 0.5, 0.5), pattern.PatternAt(new Point(0.5, 0, 0)));
            Assert.AreEqual(new Colour(0.25, 0.25, 0.25), pattern.PatternAt(new Point(0.75, 0, 0)));
        }
Exemplo n.º 2
0
        public void TestPatternGradientCreate()
        {
            var pattern = new GradientPattern(Color.White, Color.Black);

            Assert.AreEqual(pattern.PatternAt(Point.Zero), Color.White);
            Assert.AreEqual(pattern.PatternAt(new Point(0.25, 0, 0)), new Color(0.75, 0.75, 0.75));
            Assert.AreEqual(pattern.PatternAt(new Point(0.5, 0, 0)), new Color(0.5, 0.5, 0.5));
            Assert.AreEqual(pattern.PatternAt(new Point(0.75, 0, 0)), new Color(0.25, 0.25, 0.25));
        }
Exemplo n.º 3
0
        public void Gradient()
        {
            GradientPattern pattern = new GradientPattern(SolidPattern.White, SolidPattern.Black);

            Assert.True(Color.White == pattern.PatternAt(new Point(0, 0, 0)));
            Assert.True(new Color(0.75f, 0.75f, 0.75f) == pattern.PatternAt(new Point(0.25f, 0, 0)));
            Assert.True(new Color(0.5f, 0.5f, 0.5f) == pattern.PatternAt(new Point(0.5f, 0, 0)));
            Assert.True(new Color(0.25f, 0.25f, 0.25f) == pattern.PatternAt(new Point(0.75f, 0, 0)));
        }
Exemplo n.º 4
0
        public void GradientPattern()
        {
            GradientPattern pattern = new GradientPattern(white, black);

            Assert.AreEqual(pattern.PatternAt(Tuple.Point(0, 0, 0)), white);
            Assert.AreEqual(pattern.PatternAt(Tuple.Point(0.25, 0, 0)), new Color(0.75, 0.75, 0.75));
            Assert.AreEqual(pattern.PatternAt(Tuple.Point(0.5, 0, 0)), new Color(0.5, 0.5, 0.5));
            Assert.AreEqual(pattern.PatternAt(Tuple.Point(0.75, 0, 0)), new Color(0.25, 0.25, 0.25));
        }
        public void AGradientLinearlyInterpolatesBetweenTwoColors()
        {
            var pattern = new GradientPattern(Color.WHITE, Color.BLACK);

            Assert.AreEqual(Color.WHITE, pattern.PatternAt(new Point(0, 0, 0)));
            Assert.AreEqual(new Color(0.75, 0.75, 0.75), pattern.PatternAt(new Point(0.25, 0, 0)));
            Assert.AreEqual(new Color(0.5, 0.5, 0.5), pattern.PatternAt(new Point(0.5, 0, 0)));
            Assert.AreEqual(new Color(0.25, 0.25, 0.25), pattern.PatternAt(new Point(0.75, 0, 0)));
        }
Exemplo n.º 6
0
        public void T06_Gradient()
        {
            Pattern pattern = new GradientPattern(new SolidColorPattern(Color.white),
                                                  new SolidColorPattern(Color.black));

            Assert.AreEqual(Color.white, pattern.PatternAt(new Point(0, 0, 0)));
            Assert.AreEqual(new Color(0.75, 0.75, 0.75), pattern.PatternAt(new Point(0.25, 0, 0)));
            Assert.AreEqual(new Color(0.5, 0.5, 0.5), pattern.PatternAt(new Point(0.5, 0, 0)));
            Assert.AreEqual(new Color(0.25, 0.25, 0.25), pattern.PatternAt(new Point(0.75, 0, 0)));
        }
Exemplo n.º 7
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>   Main entry-point for this application. </summary>
        ///
        /// <remarks>   Kemp, 1/18/2019. </remarks>
        ///
        /// <param name="args"> An array of command-line argument strings. </param>
        ///-------------------------------------------------------------------------------------------------

        static void Main(string[] args)
        {
            World defaultWorld = new World();

            defaultWorld.AddLight(new LightPoint(new Point(-10, 10, -10), new Color(1, 1, 1)));

            Sphere s1 = new Sphere();

            s1.Material          = new Material();
            s1.Material.Color    = new Color(0.8, 1.0, 0.6);
            s1.Material.Diffuse  = new Color(0.7, 0.7, 0.7);
            s1.Material.Specular = new Color(0.2, 0.2, 0.2);

            Sphere s2 = new Sphere();

            s2.Transform = MatrixOps.CreateScalingTransform(0.5, 0.5, 0.5);
            defaultWorld.AddObject(s1);
            defaultWorld.AddObject(s2);
            Color  white = new Color(1, 1, 1);
            Color  black = new Color(0, 0, 0);
            Sphere s     = new Sphere();


            {
                Material m = new Material();
                m.Pattern   = new StripePattern(white, black);
                m.Ambient   = new Color(1, 1, 1);
                m.Diffuse   = new Color(0, 0, 0);
                m.Specular  = new Color(0, 0, 0);
                m.Shininess = 0;
                RayTracerLib.Vector eyev    = new RayTracerLib.Vector(0, 0, -1);
                RayTracerLib.Vector normalv = new RayTracerLib.Vector(0, 0, -1);
                Point      p1    = new Point(0.9, 0, 0);
                Point      p2    = new Point(1.1, 0, 0);
                LightPoint light = new LightPoint(new Point(0, 0, -10), new Color(1, 1, 1));
                Color      c1    = Ops.Lighting(m, s, light, p1, eyev, normalv, false);
                Color      c2    = Ops.Lighting(m, s, light, p2, eyev, normalv, false);
                bool       foo1  = (c1.Equals(white));
                bool       foo2  = (c2.Equals(black));
                Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~");
            }
            //public void PatternWithObjectTransformation()

            {
                Shape shape = new Sphere()
                {
                    Transform = MatrixOps.CreateScalingTransform(2, 2, 2)
                };
                Pattern pattern = new TestPattern {
                    Transform = MatrixOps.CreateTranslationTransform(0.5, 1, 1.5)
                };
                Color c    = pattern.PatternAtObject(shape, new Point(2.5, 3, 3.5));
                bool  foo1 = (c.Equals(new Color(0.75, 0.5, 0.25)));

                Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~");
            }

            //public void GradientInterpolates()
            {
                Pattern pattern = new GradientPattern(black, white);
                bool    foo1    = (pattern.PatternAt(new Point(0, 0, 0)).Equals(black));
                bool    foo2    = (pattern.PatternAt(new Point(0.25, 0, 0)).Equals(new Color(0.25, 0.25, 0.25)));
                bool    foo3    = (pattern.PatternAt(new Point(0.5, 0, 0)).Equals(new Color(0.5, 0.5, 0.5)));
                bool    foo4    = (pattern.PatternAt(new Point(0.75, 0, 0)).Equals(new Color(0.75, 0.75, 0.75)));

                Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~");
            }
            {
                Pattern pattern = new CheckedPattern(black, white);
                bool    foo1    = (pattern.PatternAt(new Point(0, 0, 0)).Equals(black));
                bool    foo2    = (pattern.PatternAt(new Point(0.99, 0, 0)).Equals(black));
                bool    foo3    = (pattern.PatternAt(new Point(1.01, 0, 0)).Equals(white));

                Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~");
            }
            Console.Write("Press Enter to finish ... ");
            Console.Read();
        }