forked from CSSE120StartingCode/IntroductionToPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathm3_turtles.py
More file actions
144 lines (133 loc) · 5.59 KB
/
m3_turtles.py
File metadata and controls
144 lines (133 loc) · 5.59 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
"""
Demonstrates using OBJECTS via Turtle Graphics.
Concepts include:
-- CONSTRUCT an INSTANCE of a CLASS (we call such instances OBJECTS).
-- Make an object ** DO ** something by using a METHOD.
-- Reference an object's ** DATA ** by using an INSTANCE VARIABLE.
Also:
-- ASSIGNING a VALUE to a NAME (VARIABLE).
Authors: David Mutchler, Dave Fisher, Valerie Galluzzi, Amanda Stouder,
their colleagues and Benjamin Feaster.
"""
########################################################################
#
# DONE: 1.
# (Yes, that means for YOU to DO things per these instructions:)
#
# On Line 13 above, replace PUT_YOUR_OWN_NAME_HERE with your OWN name.
#
# BTW, the top block of text above forms what is called a DOC-STRING.
# It documents what this module does, in a way that exterior programs
# can make sense of. It has no other effect on this program.
#
########################################################################
import rosegraphics as rg
########################################################################
#
# DONE: 2.
# Allow this file to use the rosegraphics.py file by marking the src
# directory as a "Sources Root". Do that by right clicking on the src folder,
# then selector Mark Directory As --> Sources Root
# Watch the red underlines on the line of code above disappear as you do that step.
# You will do that once for every project that uses rosegraphics so get used to it. :)
#
# Run this module by Right clicking in this window and select Run 'filename'
# A window will pop up and Turtles will move around. After the
# Turtles stop moving, *click anywhere in the window to close it*.
#
# Then look at the code below. Raise your hand as you have questions
# about what the code is doing.
#
########################################################################
# ----------------------------------------------------------------------
# Set up a TurtleWindow object for animation. The definition of a
# TurtleWindow is in the rg (shorthand for rosegraphics) module.
# ----------------------------------------------------------------------
window = rg.TurtleWindow()
window.delay(20) # Bigger numbers mean slower animation.
# ----------------------------------------------------------------------
# Makes (constructs) a SimpleTurtle object.
# ----------------------------------------------------------------------
dave = rg.SimpleTurtle()
# ----------------------------------------------------------------------
# Ask the SimpleTurtle objects to do things:
# ----------------------------------------------------------------------
dave.forward(150)
dave.left(40)
dave.forward(100)
# ----------------------------------------------------------------------
# Construct a new turtle and ask it to do things.
# ----------------------------------------------------------------------
matt = rg.SimpleTurtle('turtle')
matt.pen = rg.Pen('red', 30)
matt.speed = 10 # Faster
matt.backward(50)
matt.left(90)
matt.forward(150)
matt.backward(80)
matt.left(10)
matt.forward(150)
########################################################################
#
# DONE: 3.
# Add a few more line of your own code above to make one of the
# existing Turtles move some more and/or have different
# characteristics.
#
# ** Nothing fancy is required. **
# ** A SUBSEQUENT exercise will let you show your creativity. **
#
# As always, test by running the module.
#
########################################################################
########################################################################
#
# DONE: 4.
# The code above CONSTRUCTS two SimpleTurtle objects and gives those objects NAMES:
# dave matt
#
# Below this TO DO comment construct another SimpleTurtle object,
# naming it whatever you want.
# Names cannot have spaces or special characters, but they can have
# digits and underscores like this_1_has (get it?).
#
# After you construct a SimpleTurtle, add a few more lines that
# make YOUR SimpleTurtle move around a bit.
#
# ** Nothing fancy is required. **
# ** A SUBSEQUENT exercise will let you show your creativity. **
#
# As always, test by running the module.
#
########################################################################
turtle = rg.SimpleTurtle('turtle')
turtle.pen = rg.Pen('purple', 10)
matt.speed = 5 # Faster
matt.forward(100)
matt.left(100)
matt.backward(100)
matt.right(10)
########################################################################
#
# TODO: 5.
# Run one more time to be sure that all is still OK.
# Ensure that no blue bars on the scrollbar-thing to the right remain.
#
# Then COMMIT and Push your work using the VCS menu option.
#
# Reminder of those steps...
# COMMIT your work by selecting VCS from the menu bar, then select Commit Changes
# Make sure only the files you want to commit are checked and optionally
# add a quick Commit message to describe your work. Then hover over the
# Commit button and select Commit and Push. Commit saves the work to
# your computer. "and Push" saves a copy of your work up into your Github
# repository (saving to the cloud is a better way to permanently safe work).
#
# You can COMMIT as often as you like. DO FREQUENT COMMITS.
#
########################################################################
# ----------------------------------------------------------------------
# This line keeps the window open until the user clicks in the window:
# Throughout this exercise, close_on_mouse_click should be the last line in the file.
# ----------------------------------------------------------------------
window.close_on_mouse_click()