public void LineWidthInterpolation()
        {
            var p1     = new SPoint(1, 0, new Vec3b(0, 0, 0), 1);
            var pTest  = new SPoint(5, 0, new Vec3b(9, 9, 9), 5);
            var p2     = new SPoint(10, 0, new Vec3b(20, 20, 20), 10);
            var stroke = StrokeFactory.CreateInterpolatingStroke(new SPoint[] { p1, p2 });

            PointListsHelper.AssertPointPresence(stroke, new SPoint[] { p1, pTest, p2 });
        }
        public void Interpolate()
        {
            var p1     = new SPoint(0, 0);
            var pTest1 = new SPoint(6, 0);
            var p2     = new SPoint(10, 0);
            var pTest2 = new SPoint(10, 4);
            var p3     = new SPoint(10, 10);
            var stroke = StrokeFactory.CreateInterpolatingStroke(new SPoint[] { p1, p2, p3 });

            Assert.AreEqual(21, stroke.Count());
            PointListsHelper.AssertPointPresence(stroke, new SPoint[] { p1, pTest1, p2, pTest2, p3 });
        }
예제 #3
0
        static void Main(string[] args)
        {
            Mat img = new Mat(1000, 1000, MatType.CV_8UC3, new Scalar(0, 0, 0));

            const int NumberOfAnimationIterations = 10;
            const int NumberOfIterationsInAFrame  = 3;
            const int NumberOfFullRotations       = 50;
            var       topLeftControlPoint         = StrokeFactory.CreateInterpolatingStroke(
                new SPoint[] { new SPoint(100, 100, red), new SPoint(900, 100, yellow) }, NumberOfAnimationIterations);
            var topRightControlPoint = StrokeFactory.CreateInterpolatingStroke(
                new SPoint[] { new SPoint(900, 100, blue), new SPoint(900, 900, blue) }, NumberOfAnimationIterations);
            var bottomRightControlPoint = StrokeFactory.CreateInterpolatingStroke(
                new SPoint[] { new SPoint(900, 900, yellow), new SPoint(100, 900, red) }, NumberOfAnimationIterations);
            var bottomLeftControlPoint = StrokeFactory.CreateInterpolatingStroke(
                new SPoint[] { new SPoint(100, 900, blue), new SPoint(100, 100, blue) }, NumberOfAnimationIterations);

            var controlPointAnimation = new AnimationStroke();

            controlPointAnimation.AddStrokeAsTimeDependentControlPoint(topLeftControlPoint);
            controlPointAnimation.AddStrokeAsTimeDependentControlPoint(topRightControlPoint);
            controlPointAnimation.AddStrokeAsTimeDependentControlPoint(bottomRightControlPoint);
            controlPointAnimation.AddStrokeAsTimeDependentControlPoint(bottomLeftControlPoint);
            controlPointAnimation.AddStrokeAsTimeDependentControlPoint(topLeftControlPoint);
            controlPointAnimation.NumberOfIterations = NumberOfIterationsInAFrame;
            var strokeToDraw = new RotatingStroke(
                new InterpolatingStroke(controlPointAnimation), 2.0, 50.0);

            var drawer = new Drawer();

            while (controlPointAnimation.NextFrame())
            {
                img.SetTo(new Scalar(0, 0, 0));
                strokeToDraw.AngularSpeed = CalculateAngularVelocity(strokeToDraw.Count(), NumberOfFullRotations);
                drawer.Draw(img, strokeToDraw, true);
                Cv2.ImShow("Spirograph", img.Clone());
                if (Cv2.WaitKey(20) == Key_Esc)
                {
                    break;
                }
            }
        }
        public void AnimateInterpolatingStroke()
        {
            SPoint StartPointInFrame0    = new SPoint(0, 0);
            SPoint StartPointInFrame10   = new SPoint(0, 10);
            SPoint EndPointInFrame0      = new SPoint(100, 0);
            SPoint EndPointInFrame10     = new SPoint(100, 10);
            var    controlPointAnimation = new AnimationStroke();
            var    s1 = StrokeFactory.CreateInterpolatingStroke(new SPoint[] { StartPointInFrame0, StartPointInFrame10 });

            controlPointAnimation.AddStrokeAsTimeDependentControlPoint(s1);
            var s2 = StrokeFactory.CreateInterpolatingStroke(new SPoint[] { EndPointInFrame0, EndPointInFrame10 });

            controlPointAnimation.AddStrokeAsTimeDependentControlPoint(s2);
            var s = new InterpolatingStroke(controlPointAnimation);

            for (int t = 0; t <= 10; t++)
            {
                Assert.IsTrue(controlPointAnimation.NextFrame());
                var currentPoints = s.ToArray();
                AssertAllPointsInHorizontalLine(currentPoints, t, 0, 100);
            }
            Assert.IsFalse(controlPointAnimation.NextFrame());
        }