For this milestone, you will be making a more complicated pattern in each cell. You will be splitting the cell into several shapes and individually filling/coloring them in. You can still: decide whether the cells and its patterns are filled or unfilled choose the fill and pen colors using the user inputs Like the previous milestone, you will be asking for the fill colors for each individual shape/section as well. Sample output: Grid size (n): (input) Pen color: (input) Fill color: (input) Rectangle color: (input) Triangle color: (input) Each cell should have this drawing. The specific of this drawing is: A rectangle with a width 1/4 of the cell width and height the same as the cell Two triangles created by a diagonal line starting from the top right corner of the rectangle and ending on the bottom right of the cell You can simplify drawing the triangles by only drawing and filling in one of them, leaving the other as part of the cell background Here is a full grid with the cell drawing: import turtle import random def draw_rectangle(width, height, color): turtle.color(color) turtle.begin_fill() for _ in range(2): turtle.forward(width) turtle.left(90) turtle.forward(height) turtle.left(90) turtle.end_fill() def draw_triangle(side, color): turtle.color(color) turtle.begin_fill() for _ in range(2): turtle.forward(side) turtle.left(135) turtle.end_fill() def draw_cell(cell_size, rect_color, tri_color): rect_width = cell_size / 4 draw_rectangle(rect_width, cell_size, rect_color) turtle.forward(rect_width) draw_triangle(cell_size * (3 ** 0.5) / 2, tri_color) def draw_grid(n, cell_size, pen_color, fill_color, rect_color, tri_color): turtle.color(pen_color, fill_color) for i in range(n): for j in range(n): turtle.up() turtle.goto(-n * cell_size / 2 + j * cell_size, n * cell_size / 2 - i * cell_size) turtle.down() turtle.begin_fill() for _ in range(4): turtle.forward(cell_size) turtle.right(90) turtle.end_fill() draw_cell(cell_size, rect_color, tri_color) def main(): # turtle.tracer(False) n = int(input("Grid size (n): \n")) pen_color = input("Pen color: \n") fill_color = input("Fill color: \n") rect_color = input("Rectangle color: \n") tri_color = input("Triangle color: \n") size_for_canvas = 500 cell_size = size_for_canvas / n s = turtle.Screen() s.setup(width=size_for_canvas + 10, height=size_for_canvas + 10) s.screensize(size_for_canvas, size_for_canvas) draw_grid(n, cell_size, pen_color, fill_color, rect_color, tri_color) turtle.tracer(True) turtle.mainloop() main() it not doing the grid of the shape is all over the place
For this milestone, you will be making a more complicated pattern in each cell. You will be splitting the cell into several shapes and individually filling/coloring them in.
You can still:
- decide whether the cells and its patterns are filled or unfilled
- choose the fill and pen colors using the user inputs
Like the previous milestone, you will be asking for the fill colors for each individual shape/section as well.
Sample output:
Grid size (n): (input) Pen color: (input) Fill color: (input) Rectangle color: (input) Triangle color: (input)
Each cell should have this drawing. The specific of this drawing is:
- A rectangle with a width 1/4 of the cell width and height the same as the cell
- Two triangles created by a diagonal line starting from the top right corner of the rectangle and ending on the bottom right of the cell
You can simplify drawing the triangles by only drawing and filling in one of them, leaving the other as part of the cell background
Here is a full grid with the cell drawing:
import turtleimport random
def draw_rectangle(width, height, color):turtle.color(color)turtle.begin_fill()for _ in range(2):turtle.forward(width)turtle.left(90)turtle.forward(height)turtle.left(90)turtle.end_fill()
def draw_triangle(side, color):turtle.color(color)turtle.begin_fill()for _ in range(2):turtle.forward(side)turtle.left(135)turtle.end_fill()
def draw_cell(cell_size, rect_color, tri_color):rect_width = cell_size / 4draw_rectangle(rect_width, cell_size, rect_color)
turtle.forward(rect_width)draw_triangle(cell_size * (3 ** 0.5) / 2, tri_color)
def draw_grid(n, cell_size, pen_color, fill_color, rect_color, tri_color):turtle.color(pen_color, fill_color)for i in range(n):for j in range(n):turtle.up()turtle.goto(-n * cell_size / 2 + j * cell_size, n * cell_size / 2 - i * cell_size)turtle.down()turtle.begin_fill()for _ in range(4):turtle.forward(cell_size)turtle.right(90)turtle.end_fill()
draw_cell(cell_size, rect_color, tri_color)
def main():# turtle.tracer(False)
n = int(input("Grid size (n): \n"))pen_color = input("Pen color: \n")fill_color = input("Fill color: \n")rect_color = input("Rectangle color: \n")tri_color = input("Triangle color: \n")
size_for_canvas = 500cell_size = size_for_canvas / n
s = turtle.Screen()s.setup(width=size_for_canvas + 10, height=size_for_canvas + 10)s.screensize(size_for_canvas, size_for_canvas)
draw_grid(n, cell_size, pen_color, fill_color, rect_color, tri_color)
turtle.tracer(True)turtle.mainloop()
main()it not doing the grid of the shape is all over the place
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Tip: You can simplify drawing the triangles by only drawing and filling in one of them, leaving the other as part of the cell background
Here is a full grid with the cell drawing:
Each cell should have this drawing. The specific of this drawing is:
- A rectangle with a width 1/4 of the cell width and height the same as the cell
- Two triangles created by a diagonal line starting from the top right corner of the rectangle and ending on the bottom right of the cell
Here is what the cell should look like if colored, each section should be a different color (if filled):
![The image displays a geometric pattern composed of rows and columns of squares, each divided into two triangles along a diagonal line from the bottom-left to the top-right. The pattern has the following features:
- **Color Arrangement**:
- Each square is divided into two triangles. The lower-left triangle is colored red, while the upper-right triangle is orange.
- There are blue vertical stripes that separate each column of patterns.
- **Layout**:
- The pattern consists of several columns, each containing rows of these squares.
- The columns are separated by blue vertical lines, creating a visual separation between the sets of squares.
This type of pattern can be used to teach concepts related to symmetry, color theory, and geometric transformations, such as rotation and reflection.](https://content.bartleby.com/qna-images/question/d0dac0b6-5a17-4cd9-bac9-9e2e50ac9cbc/641f6dcc-a193-4342-a7ee-0c4d57cc2c1a/4zuilm_thumbnail.png)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)