# shapes.py # --------- # By MWC contributors import turtle import math # Set up the turtle t = turtle.Turtle() t.speed(3) t.hideturtle() # Draw triangle with lines (left side, unfilled) t.penup() t.goto(-200, 0) t.pendown() for _ in range(3): # Unfilled triangle t.forward(200) t.left(120) # Draw internal diagonal lines t.penup() t.goto(-200, 0) # Bottom-left t.pendown() t.goto(-100, 100 * math.sqrt(3)) # Top t.penup() t.goto(-200, 0) # Bottom-left t.pendown() t.goto(0, 100 * math.sqrt(3)) # Top-right t.penup() t.goto(0, 100 * math.sqrt(3)) # Top-right t.pendown() t.goto(-200, 0) # Bottom-left # Move to a separate position for upside-down rectangle grid (right side) t.penup() t.goto(100, 225) # Start at the top for upside-down grid t.pendown() # Draw upside-down smaller grid rectangle with 9 units length, decreasing to 1 unit = 25 # Unit size is 25 pixels for a smaller rectangle for i in range(9): # 9 rows, starting from top and decreasing for j in range(9 - i): # Decreases from 9 to 1 t.penup() t.goto(100 + j * unit, 225 - i * unit) # Invert y-coordinate for upside-down t.pendown() for _ in range(4): t.forward(unit) t.right(90) # Keep window open turtle.done()