Exemplo n.º 1
0
        private void OnPaintingShapes(object sender, SKPaintSurfaceEventArgs e)
        {
            var surface = e.Surface;
            var canvas  = surface.Canvas;

            // clear the surface
            canvas.Clear(SKColors.White);

            // get the radius of the screen
            var radius = Math.Min(e.Info.Width / 2f, e.Info.Height / 2f);

            // create the paint for a star
            var starPaint = new SKPaint
            {
                IsAntialias = true,
                Color       = SKColors.Gold
            };

            // draw the star
            canvas.DrawStar(e.Info.Width / 2f, e.Info.Height / 2f, radius * 0.4f, radius * 0.2f, 5, starPaint);

            // create the paint for the pie
            var piePaint = new SKPaint
            {
                IsAntialias = true,
                Color       = SKColors.Green
            };

            // calculate the pie
            var piePath = SKGeometry.CreatePiePath(sectors, radius * 0.9f, radius * 0.5f, 6f);

            // draw the pie
            canvas.Translate(e.Info.Width / 2f, e.Info.Height / 2f);
            canvas.DrawPath(piePath, piePaint);
        }
Exemplo n.º 2
0
        public static void DrawStar(this SKCanvas canvas, float cx, float cy, float outerRadius, float innerRadius, int points, SKPaint paint)
        {
            var path = SKGeometry.CreateRegularStarPath(outerRadius, innerRadius, points);

            path.Offset(cx, cy);
            canvas.DrawPath(path, paint);
        }
Exemplo n.º 3
0
        public static void DrawSquare(this SKCanvas canvas, float cx, float cy, float side, SKPaint paint)
        {
            var path = SKGeometry.CreateSquarePath(side);

            path.Offset(cx, cy);
            canvas.DrawPath(path, paint);
        }
Exemplo n.º 4
0
        public static void DrawRegularPolygon(this SKCanvas canvas, float cx, float cy, float radius, int points, SKPaint paint)
        {
            var path = SKGeometry.CreateRegularPolygonPath(radius, points);

            path.Offset(cx, cy);
            canvas.DrawPath(path, paint);
        }
Exemplo n.º 5
0
        public static void DrawTriangle(this SKCanvas canvas, float cx, float cy, float radius, SKPaint paint)
        {
            var path = SKGeometry.CreateTrianglePath(radius);

            path.Offset(cx, cy);
            canvas.DrawPath(path, paint);
        }
Exemplo n.º 6
0
        public static void DrawRect(this SKCanvas canvas, float cx, float cy, float width, float height, SKPaint paint)
        {
            var path = SKGeometry.CreateRectanglePath(width, height);

            path.Offset(cx, cy);
            canvas.DrawPath(path, paint);
        }
Exemplo n.º 7
0
        public void PerimeterCalculation()
        {
            var points = new[]
            {
                new SKPoint(10, 10),
                new SKPoint(10, 40),
                new SKPoint(50, 40),
            };
            var perimeter = SKGeometry.Perimeter(points);

            Assert.AreEqual(120f, perimeter);
        }
Exemplo n.º 8
0
        public void TriangleAreaCalculation()
        {
            var points = new[]
            {
                new SKPoint(10, 10),
                new SKPoint(10, 20),
                new SKPoint(20, 20),
            };
            var area = SKGeometry.Area(points);

            Assert.AreEqual(50f, area);
        }
Exemplo n.º 9
0
        public void CreateInterpolationReturnsOriginals()
        {
            var path1 = new SKPath();
            var path2 = new SKPath();

            var interpolated = SKGeometry.CreateInterpolation(path1, path2, -1);

            Assert.AreEqual(path1, interpolated);

            interpolated = SKGeometry.CreateInterpolation(path1, path2, 0);
            Assert.AreEqual(path1, interpolated);

            interpolated = SKGeometry.CreateInterpolation(path1, path2, 0.5f);
            Assert.AreNotEqual(path1, interpolated);
            Assert.AreNotEqual(path2, interpolated);

            interpolated = SKGeometry.CreateInterpolation(path1, path2, 1);
            Assert.AreEqual(path2, interpolated);

            interpolated = SKGeometry.CreateInterpolation(path1, path2, 2);
            Assert.AreEqual(path2, interpolated);
        }
Exemplo n.º 10
0
        public void GeometryGeneratesRectPath()
        {
            var rectPath = SKGeometry.CreateTrianglePath(100);

            Assert.AreEqual(3, rectPath.PointCount);
        }
Exemplo n.º 11
0
        public void DistanceCalculation()
        {
            var dist = SKGeometry.Distance(new SKPoint(10, 10), new SKPoint(10, 40));

            Assert.AreEqual(30f, dist);
        }
Exemplo n.º 12
0
        protected override void OnDraw(SKCanvas canvas, SKPaint paint, float size)
        {
            using var star = SKGeometry.CreateRegularStarPath(size, size / 2, Points);

            canvas.DrawPath(star, paint);
        }