-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
46 lines (38 loc) · 1.92 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from canvas import Canvas
from shapes import Rectangle, Square
# Get canvas width and height from the user
canvas_width = int(input("Enter canvas width: "))
canvas_height = int(input("Enter canvas height: "))
# make a dictionary of color codes and prompt for color
colors = {"white": (255, 255, 255), "black": (0, 0, 0)}
canvas_color = input("Enter canvas color (white or black): ")
# Create a canvas with user data
canvas = Canvas(height=canvas_height, width=canvas_width, color=colors[canvas_color])
while True:
shape_type = input("What do you like to draw rectangle or square? Enter 'quit' to stop. ")
# Ask for rectangle data and create rectangle if user entered 'rectangle'
if shape_type.lower() == 'rectangle':
rec_x = int(input("Enter x of the rectangle: "))
rec_y = int(input("Enter y of the rectangle: "))
rec_width = int(input("Enter the width of the rectangle: "))
rec_height = int(input("Enter the height of the rectangle: "))
red = int(input("How much red should the rectangle have? "))
green = int(input("How much green? "))
blue = int(input("How much blue?"))
# Create the rectangle
r1 = Rectangle(x=rec_x, y=rec_y, height=rec_height, width=rec_width, color=(red, green, blue))
r1.draw(canvas)
# Ask for square data and create square if user entered 'square'
if shape_type.lower() == 'square':
rec_x = int(input("Enter x of the square: "))
rec_y = int(input("Enter y of the square: "))
rec_side = int(input("Enter the side of the square: "))
red = int(input("How much red should the square have? "))
green = int(input("How much green? "))
blue = int(input("How much blue?"))
s1 = Square(x=rec_x, y=rec_y, side=rec_side, color=(red, green, blue))
s1.draw(canvas)
# Break the loop if user entered 'quit'
if shape_type.lower() == 'quit':
break
canvas.make('canvas.png')