Ejemplo n.º 1
0
        public async void Ellipse(RGBA color, Point center, float width, float height, bool fill = true, bool border = true, float thickness = 5)
        {
            // http://www.williammalone.com/briefs/how-to-draw-ellipse-html5-canvas/
            var hex = ColorCache(color);

            if (border)
            {
                await Surface.SetLineWidthAsync(thickness < 1f? 1f : thickness);

                await Surface.SetStrokeStyleAsync(hex);
            }
            else
            {
                await Surface.SetStrokeStyleAsync(hex);
            }
            await Surface.BeginPathAsync();

            {
                await Surface.MoveToAsync(center.X, center.Y - (height / 2f));

                await Surface.BezierCurveToAsync(
                    center.X + (width * 0.67f), center.Y - (height / 2f), // C1
                    center.X + (width * 0.67f), center.Y + (height / 2f), // C2
                    center.X, center.Y + (height / 2f));                  // A2

                await Surface.BezierCurveToAsync(
                    center.X - (width * 0.67f), center.Y + (height / 2f), // C3
                    center.X - (width * 0.67f), center.Y - (height / 2f), // C4
                    center.X, center.Y - (height / 2f));                  // A1

                if (fill)
                {
                    await Surface.SetFillStyleAsync(hex);

                    await Surface.FillAsync();
                }
                else
                {
                    await Surface.StrokeAsync();
                }
            }
            await Surface.ClosePathAsync();
        }
Ejemplo n.º 2
0
        public async void Polygon(RGBA color, Point[] points, bool fill = true, bool border = false, float thickness = 5)
        {
            var hex = ColorCache(color);

            if (border)
            {
                await Surface.SetLineWidthAsync(thickness < 1f? 1f : thickness);

                await Surface.SetStrokeStyleAsync(ColorCache(RGBA.Black));
            }
            else
            {
                await Surface.SetStrokeStyleAsync(hex);
            }
            await Surface.BeginPathAsync();

            {
                await Surface.MoveToAsync(points[0].X, points[0].Y);

                for (int i = 1; i < points.Length; i++)
                {
                    await Surface.LineToAsync(points[i].X, points[i].Y);
                }
                await Surface.LineToAsync(points[0].X, points[0].Y);

                if (fill)
                {
                    await Surface.SetFillStyleAsync(hex);

                    await Surface.FillAsync();
                }
                else
                {
                    await Surface.StrokeAsync();
                }
            }
            await Surface.ClosePathAsync();
        }