public MainWindow()
        {
            InitializeComponent();
            var foxDraw = new FoxDraw(canvas);
            // Create a function that takes 1 parameter:
            // A list of (x, y) points
            // and connects them with green lines.
            // connect these to get a box: {new Point(10, 10), new Point(290, 10), new Point(290, 290), new Point(10, 290)}
            // Connect these: {new Point(50, 100), new Point(70, 70), new Point(80, 90), new Point(90, 90), new Point(100, 70),
            // new Point(120, 100), new Point(85, 130), new Point(50, 100)}

            var greenFox = new List <Point>();

            greenFox.Add(new Point(50, 100));
            greenFox.Add(new Point(70, 70));
            greenFox.Add(new Point(80, 90));
            greenFox.Add(new Point(90, 90));
            greenFox.Add(new Point(100, 70));
            greenFox.Add(new Point(120, 100));
            greenFox.Add(new Point(85, 130));
            greenFox.Add(new Point(50, 100));

            foxDraw.StrokeColor(Colors.White);
            foxDraw.BackgroundColor(Colors.Black);
            foxDraw.FillColor(Colors.Green);

            ConnectTheDots(greenFox);

            var box = new List <Point>();

            //Box
            box.Add(new Point(10, 10));
            box.Add(new Point(290, 10));
            box.Add(new Point(290, 290));
            box.Add(new Point(10, 290));
            foxDraw.FillColor(Color.FromArgb(0, 0, 0, 0));

            ConnectTheDots(box);



            void ConnectTheDots(List <Point> inputPoints)
            {
                var from = inputPoints[0];
                var to   = new Point(0, 0);

                foreach (var point in inputPoints)
                {
                    to = point;
                    foxDraw.DrawPolygon(inputPoints);
                    from = point;
                }
            }
        }
        public MainWindow()
        {
            InitializeComponent();
            var foxDraw = new FoxDraw(canvas);
            // Create a function that takes 1 parameter:
            // A list of (x, y) points
            // and connects them with green lines.
            // connect these to get a box: {new Point(10, 10), new Point(290, 10), new Point(290, 290), new Point(10, 290)}
            // Connect these: {new Point(50, 100), new Point(70, 70), new Point(80, 90), new Point(90, 90), new Point(100, 70),
            // new Point(120, 100), new Point(85, 130), new Point(50, 100)}

            Random rng = new Random();

            var points = new List <Point>();

            foxDraw.StrokeColor(Colors.White);
            foxDraw.BackgroundColor(Colors.Black);
            foxDraw.FillColor(Colors.Gray);

            for (int i = 0; i < 30; i++)
            {
                points.Add(new Point(rng.Next(700), rng.Next(700)));
            }


            ConnectTheDots(points);

            void ConnectTheDots(List <Point> inputPoints)
            {
                var from = inputPoints[0];
                var to   = new Point(0, 0);

                foreach (var point in inputPoints)
                {
                    to = point;
                    foxDraw.DrawLine(from, to);
                    from = point;
                }
            }
        }
Beispiel #3
0
        public MainWindow()
        {
            InitializeComponent();
            var foxDraw = new FoxDraw(canvas);

            // Draw the night sky:
            //  - The background should be black
            //  - The stars can be small squares
            //  - The stars should have random positions on the canvas
            //  - The stars should have random color (some shade of grey)

            double sizeOfStar    = 3;
            int    amountOfStars = 200;

            foxDraw.BackgroundColor(Colors.Black);

            DrawStars(sizeOfStar, amountOfStars);

            void DrawStars(double size, int amount)
            {
                Random rng = new Random();

                int margin = 10;

                int width  = Convert.ToInt32(canvas.Width) - margin;
                int height = Convert.ToInt32(canvas.Height) - margin;

                for (int i = 0; i < amount; i++)
                {
                    byte randomColor = Convert.ToByte(rng.Next(0, 255));
                    foxDraw.FillColor(Color.FromRgb(randomColor, randomColor, randomColor));
                    foxDraw.StrokeColor(Color.FromRgb(randomColor, randomColor, randomColor));
                    foxDraw.DrawEllipse(rng.Next(0, width), rng.Next(0, height), sizeOfStar, sizeOfStar);
                }
            }
        }