1
+ import turtle
2
+
3
+ class ShapeDrawer :
4
+ def __init__ (self , color , pensize ):
5
+ self .turtle = turtle .Turtle ()
6
+ self .turtle .color (color )
7
+ self .turtle .pensize (pensize )
8
+
9
+ def draw_rectangle (self , width , height ):
10
+ for _ in range (2 ):
11
+ self .turtle .forward (width )
12
+ self .turtle .left (90 )
13
+ self .turtle .forward (height )
14
+ self .turtle .left (90 )
15
+
16
+ def draw_triangle (self , length ):
17
+ for _ in range (3 ):
18
+ self .turtle .forward (length )
19
+ self .turtle .left (120 )
20
+
21
+ def main ():
22
+ scrn = turtle .Screen ()
23
+ scrn .bgcolor ("lavender" )
24
+
25
+ # Draw Rectangle
26
+ rectangle_drawer = ShapeDrawer ("blue" , 3 )
27
+ rectangle_drawer .draw_rectangle (180 , 75 )
28
+
29
+ # Draw Triangle
30
+ triangle_drawer = ShapeDrawer ("hot pink" , 4 )
31
+ triangle_drawer .turtle .penup ()
32
+ triangle_drawer .turtle .goto (- 90 , - 75 )
33
+ triangle_drawer .turtle .pendown ()
34
+ triangle_drawer .draw_triangle (100 )
35
+
36
+ # Add more drawings as needed
37
+ # ...
38
+
39
+ # Example: Draw a circle
40
+ circle_drawer = ShapeDrawer ("green" , 2 )
41
+ circle_drawer .turtle .penup ()
42
+ circle_drawer .turtle .goto (0 , 0 )
43
+ circle_drawer .turtle .pendown ()
44
+ circle_drawer .turtle .circle (50 )
45
+
46
+ scrn .exitonclick ()
47
+
48
+ if __name__ == "__main__" :
49
+ main ()
0 commit comments