using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

// At design time:
//      Set the window's Background to Transparent.
//      Name the content control mainGrid.

namespace WpfRenderShapes
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        // Draw some shapes.
        protected override void OnRender(DrawingContext drawingContext)
        {
            // Clear the background.
            Rect bgRect = new Rect(0, 0, this.ActualWidth, this.ActualHeight);
            drawingContext.DrawRectangle(Brushes.White, null, bgRect);

            // Define polygon points.
            const double lineThickness = 10;
            double centerX = mainGrid.ActualWidth / 2;
            double centerY = mainGrid.ActualHeight / 2;
            double radiusX = centerX - 2 * lineThickness;
            double radiusY = centerY - 2 * lineThickness;
            double theta = -Math.PI / 2;
            const double dtheta = Math.PI * 4 / 5;
            Point[] points = new Point[5];
            for (int i = 0; i < 5; i++)
            {
                points[i] = new Point(
                    centerX + radiusX * Math.Cos(theta),
                    centerY + radiusY * Math.Sin(theta));
                theta += dtheta;
            }

            // Draw the polygon.
            Pen pen = new Pen(Brushes.Green, lineThickness);
            pen.LineJoin = PenLineJoin.Round;
            drawingContext.DrawPolygon(Brushes.LightGreen,
                pen, points, FillRule.EvenOdd);

            // Make polyline points.
            theta = Math.PI / 2;
            radiusX *= 0.75;
            radiusY *= 0.75;
            for (int i = 0; i < 5; i++)
            {
                points[i] = new Point(
                    centerX + radiusX * Math.Cos(theta),
                    centerY + radiusY * Math.Sin(theta));
                theta += dtheta;
            }

            // Draw the polyline.
            pen = new Pen(Brushes.Blue, lineThickness / 2);
            drawingContext.DrawPolyline(null, pen,
                points, FillRule.EvenOdd);
        }
    }
}
