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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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
  •  
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question
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): "))
    pen_color = input("\nPen color: ")
    fill_color = input("\nFill color: ")
    rect_color = input("\nRectangle color: ")
    tri_color = input("\nTriangle color: ")

    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()
 
can you fix this 

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):

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education