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(Colors.Purple, 19, 10, startLocation); void purpleStepGenerator(Color color, double repetitions, double size, Point start) { double x = start.X; double y = start.Y; foxDraw.FillColor(color); foxDraw.DrawRectangle(x, y, size, size); for (int i = 0; i < repetitions; i++) { x += size; y += size; foxDraw.FillColor(color); foxDraw.DrawRectangle(x, y, size, size); } } }
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); } } }
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 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); } }
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 static void SquareInTheCenter(double squareSize, FoxDraw foxDraw, Point center) { foxDraw.DrawRectangle(center.X, center.Y, squareSize, squareSize); }
public static void DrawThreeSquaresFrom(double x, double y, FoxDraw foxDraw) { double squareSize = 50; foxDraw.DrawRectangle(x, y, squareSize, squareSize); }