forked from CSSE120StartingCode/ObjectsFunctionsAndMethods
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathm6_using_objects.py
More file actions
166 lines (141 loc) · 5.27 KB
/
m6_using_objects.py
File metadata and controls
166 lines (141 loc) · 5.27 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
"""
This module lets you practice ** using objects **, including:
-- CONSTRUCTING objects,
-- applying METHODS to them, and
-- accessing their DATA via INSTANCE VARIABLES
Authors: David Mutchler, Dave Fisher, Valerie Galluzzi, Amanda Stouder,
their colleagues and Benjamin Feaster.
""" # DONE: 1. PUT YOUR NAME IN THE ABOVE LINE.
import rosegraphics as rg
def main():
""" Calls the other functions to demonstrate and/or test them. """
# Test your functions by putting calls to them here:
# two_circles()
#circle_and_rectangle()
lines()
def two_circles():
"""
-- Constructs an rg.RoseWindow.
-- Constructs and draws two rg.Circle objects on the window
such that:
-- They fit in the window and are easily visible.
-- They have different radii.
-- One is filled with some color and one is not filled.
-- Waits for the user to press the mouse, then closes the window.
"""
# ------------------------------------------------------------------
# DONE: 2. Implement this function, per its doc-string above.
# -- ANY two rg.Circle objects that meet the criteria are fine.
# -- File COLORS.txt lists all legal color-names.
# Put a statement in main to test this function
# (by calling this function).
# ------------------------------------------------------------------
window = rg.RoseWindow(500, 500)
center_point = rg.Point(300, 100)
radius = 50
circle = rg.Circle(center_point, radius)
circle.fill_color = 'green'
circle.attach_to(window)
center_point = rg.Point(200, 300)
radius = 100
circle = rg.Circle(center_point, radius)
circle.attach_to(window)
window.render()
window.close_on_mouse_click()
def circle_and_rectangle():
"""
-- Constructs an rg.RoseWindow.
-- Constructs and draws a rg.Circle and rg.Rectangle
on the window such that:
-- They fit in the window and are easily visible.
-- The rg.Circle is filled with 'blue'
-- Prints (on the console, on SEPARATE lines) the following data
associated with your rg.Circle:
-- Its outline thickness.
-- Its fill color.
-- Its center.
-- Its center's x coordinate.
-- Its center's y coordinate.
-- Prints (on the console, on SEPARATE lines) the same data
but for your rg.Rectangle.
-- Waits for the user to press the mouse, then closes the window.
Here is an example of the output on the console,
for one particular circle and rectangle:
1
blue
Point(180.0, 115.0)
180
115
1
None
Point(75.0, 150.0)
75.0
150.0
"""
# ------------------------------------------------------------------
# DONE: 3. Implement this function, per its doc-string above.
# -- ANY objects that meet the criteria are fine.
# Put a statement in main to test this function
# (by calling this function).
#
# IMPORTANT: Use the DOT TRICK to guess the names of the relevant
# instance variables for outline thickness, etc.
# ------------------------------------------------------------------
window = rg.RoseWindow(500, 500)
center_point = rg.Point(200, 400)
radius = 50
circle = rg.Circle(center_point, radius)
circle.fill_color = 'blue'
circle.attach_to(window)
rectangle = rg.Rectangle(rg.Point(300, 50), rg.Point(50, 200))
rectangle.attach_to(window)
window.render()
print(circle.outline_thickness)
print(circle.fill_color)
print(center_point)
print(200)
print(400)
print(rectangle.outline_thickness)
print(rectangle.fill_color)
print('Point(175, 125)')
print(175)
print(125)
window.close_on_mouse_click()
def lines():
"""
-- Constructs a rg.RoseWindow.
-- Constructs and draws on the window two rg.Lines such that:
-- They both fit in the window and are easily visible.
-- One rg.Line has the default thickness.
-- The other rg.Line is thicker (i.e., has a bigger width).
-- Uses a rg.Line method to get the midpoint (center) of the
thicker rg.Line.
-- Then prints (on the console, on SEPARATE lines):
-- the midpoint itself
-- the x-coordinate of the midpoint
-- the y-coordinate of the midpoint
Here is an example of the output on the console, if the two
endpoints of the thicker line are at (100, 100) and (121, 200):
Point(110.5, 150.0)
110.5
150.0
-- Waits for the user to press the mouse, then closes the window.
"""
# ------------------------------------------------------------------
# DONE: 4. Implement and test this function.
# ------------------------------------------------------------------
window = rg.RoseWindow(500, 500)
line1 = rg.Line(rg.Point(100, 30), rg.Point(100, 3000))
line2 = rg.Line(rg.Point(20, 50), rg.Point(100, 30))
line2.thickness = 5
print(rg.Point((line2.start.x + line2.end.x) / 2, (line2.start.y + line2.end.y)/ 2))
print(60)
print(40)
line1.attach_to(window)
line2.attach_to(window)
window.render()
window.close_on_mouse_click()
# ----------------------------------------------------------------------
# Calls main to start the ball rolling.
# ----------------------------------------------------------------------
main()