diff --git a/shapes.py b/shapes.py index 731ec39..10f9560 100644 --- a/shapes.py +++ b/shapes.py @@ -2,10 +2,53 @@ # --------- # By MWC contributors -from turtle import * +import turtle +import math -def triangle(side_length): - pass +# Set up the turtle +t = turtle.Turtle() +t.speed(3) +t.hideturtle() -def rectangle(height, width): - pass +# 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() \ No newline at end of file