示例#1
0
        public MainWindow()
        {
            InitializeComponent();
            var foxDraw = new FoxDraw(canvas);

            // Create a square drawing function that takes 2 parameters:
            // The square size, and the fill color,
            // and draws a square of that size and color to the center of the canvas.
            // Create a loop that fills the canvas with rainbow colored squares.

            Rainbows(Height, Colors.Blue);



            void Rainbows(double squareSize, Color color)
            {
                var colorsList = new List <Color>();


                for (byte i = 0; i < 20; i += 10)
                {
                    colorsList.Add(Color.FromRgb(i, 255, 255));
                }

                for (byte j = 0; j < 40; j += 20)
                {
                    colorsList.Add(Color.FromRgb(255, j, 255));
                }

                for (byte k = 0; k < 80; k += 30)
                {
                    colorsList.Add(Color.FromRgb(255, 255, k));
                }



                //Color[] colors = { Colors.Red, Colors.Green, Colors.Blue, Colors.Yellow };

                double centreX = (Width / 2) - (squareSize / 2);
                double centreY = (Height / 2) - (squareSize / 2);

                foxDraw.FillColor(color);

                foxDraw.DrawRectangle(centreX, centreY, squareSize, squareSize);



                for (int i = 0; i < colorsList.Count; i++)
                {
                    squareSize /= 1.3;

                    centreX = (Width / 2) - (squareSize / 2);
                    centreY = (Height / 2) - (squareSize / 2);

                    foxDraw.FillColor(colorsList[i]);
                    foxDraw.DrawRectangle(centreX, centreY, squareSize, squareSize);
                }
            }
        }
示例#2
0
        public MainWindow()
        {
            InitializeComponent();
            var foxDraw = new FoxDraw(canvas);

            // Fill the canvas with a checkerboard pattern.

            DrawCheckerBoard(8);

            void DrawCheckerBoard(int amountOfSquares)
            {
                double squareSize = canvas.Width / amountOfSquares;


                //Set mainwindow and canvas width and height to 800
                double x = 0 + 10;
                double y = 0 + 30;

                foxDraw.FillColor(Colors.Black);
                foxDraw.StrokeColor(Colors.Black);

                foxDraw.DrawRectangle(x, y, squareSize, squareSize);

                for (int i = 0; i < amountOfSquares; i++)
                {
                    for (int j = 0; j < amountOfSquares; j++)
                    {
                        if (i % 2 == 0)
                        {
                            if (j % 2 == 0)
                            {
                                foxDraw.FillColor(Colors.White);
                            }
                            else
                            {
                                foxDraw.FillColor(Colors.Black);
                            }

                            foxDraw.DrawRectangle(x + (j * squareSize), y, squareSize, squareSize);
                        }
                        else
                        {
                            if (j % 2 == 0)
                            {
                                foxDraw.FillColor(Colors.Black);
                            }
                            else
                            {
                                foxDraw.FillColor(Colors.White);
                            }

                            foxDraw.DrawRectangle(x + (j * squareSize), y, squareSize, squareSize);
                        }
                    }
                    y += squareSize;
                }
            }
        }
        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;
                }
            }
        }
示例#4
0
        public MainWindow()
        {
            InitializeComponent();
            var foxDraw = new FoxDraw(canvas);
            // Reproduce this:
            // [https://github.com/greenfox-academy/teaching-materials/blob/master/workshop/drawing/purple-steps/r3.png]

            var startLocation = new Point(50, 50);

            purpleStepGenerator(6, 10, startLocation);

            void purpleStepGenerator(double repetitions, double size, Point start)
            {
                double x = start.X;
                double y = start.Y;

                foxDraw.StrokeColor(Colors.Black);
                foxDraw.FillColor(Colors.Purple);

                for (int i = 0; i < repetitions; i++)
                {
                    foxDraw.DrawRectangle(x, y, size, size);

                    x += size;
                    y += size;

                    size *= 1.5;
                }
            }
        }
        public MainWindow()
        {
            InitializeComponent();
            var foxDraw = new FoxDraw(canvas);

            // create a square drawing function that takes 1 parameter:
            // the square size
            // and draws a square of that size to the center of the canvas.
            // draw 3 squares with that function.
            // avoid code duplication.



            DrawSquareInCenter(50);
            DrawSquareInCenter(100);
            DrawSquareInCenter(150);

            void DrawSquareInCenter(double squareSize)
            {
                var centre = new Point((Width / 2) - (squareSize / 2), (Height / 2) - (squareSize / 2));

                foxDraw.FillColor(Color.FromArgb(0, 0, 0, 0));
                foxDraw.DrawRectangle(centre.X, centre.Y, squareSize, squareSize);
            }
        }
示例#6
0
        public MainWindow()
        {
            InitializeComponent();
            var foxDraw = new FoxDraw(canvas);

            int canvasWidth  = Convert.ToInt32(canvas.Width);
            int canvasHeight = Convert.ToInt32(canvas.Height);

            int stepSize = 20;

            DrawGridBottomLeft(stepSize, foxDraw, canvasWidth, canvasHeight);
            DrawGridTopRight(stepSize, foxDraw, canvasWidth, canvasHeight);

            int radius = 250;

            foxDraw.FillColor(Colors.Gray);
            foxDraw.DrawEllipse((canvasWidth / 2) - (radius / 2), (canvasHeight / 2) - (radius / 2), radius, radius);
            radius -= 100;
            foxDraw.FillColor(Colors.DarkGray);
            foxDraw.DrawEllipse((canvasWidth / 2) - (radius / 2), (canvasHeight / 2) - (radius / 2), radius, radius);
        }
示例#7
0
        public static void DrawFourRectangles(double rectangleWidth, double rectangleHeight, FoxDraw foxDraw, Point center, Color[] colors)
        {
            for (int i = 0; i < 4; i++)
            {
                double newCenterX = center.X;
                double newCenterY = center.Y;

                if (i > 0)
                {
                    newCenterX += (rectangleWidth * i);
                }

                foxDraw.FillColor(colors[i]);
                foxDraw.DrawRectangle(newCenterX, newCenterY, rectangleWidth, rectangleHeight);
            }
        }
        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;
                }
            }
        }
示例#9
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);
                }
            }
        }