Skip to content

Commit cb8df22

Browse files
committed
Initial import
1 parent d836779 commit cb8df22

File tree

9 files changed

+3210
-0
lines changed

9 files changed

+3210
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea
2+
*.pyc

COLORS.pdf

45.3 KB
Binary file not shown.

COLORS.txt

Lines changed: 771 additions & 0 deletions
Large diffs are not rendered by default.

src/m1e_comments_strings_print.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Authors: David Mutchler, Amanda Stouder, Mark Hays, Valerie Galluzzi,
2+
# Dave Fisher and many others before them.
3+
4+
print('Hello, World')
5+
print('hi there')
6+
print('one', 'two', 'through my shoe')
7+
print(3 + 9)
8+
print('3 + 9', 'versus', 3 + 9)

src/m2_hello_world.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
print('Hello, World')
2+
3+
########################################################################
4+
# This line is a COMMENT -- a note to human readers of this file.
5+
# When a program runs, it ignores everything from a # (hash) mark
6+
# to the end of the line with the # mark.
7+
#
8+
# We call files that have Python code in them MODULES. Line 1 of this
9+
# module (look at it now) prints onto the Console the STRING
10+
# Hello, World
11+
# Anything surrounded by quote marks (single or double) is a STRING.
12+
########################################################################
13+
14+
########################################################################
15+
#
16+
# TODO: 1.
17+
# (Yes, that means for YOU to DO things per these instructions:)
18+
#
19+
# Run this module by using the green arrow on the toolbar up top.
20+
# After running, find the Console tab (to the right) and confirm that
21+
# Hello, World
22+
# did indeed get printed (displayed) on the Console.
23+
#
24+
########################################################################
25+
26+
########################################################################
27+
#
28+
# TODO: 2.
29+
# Notice the small horizontal BLUE bars on the scrollbar-like thing
30+
# on the right. Each blue bar indicates a TODO in this module.
31+
#
32+
# a. You can use the blue bars to go from one TODO to the next
33+
# by clicking on the blue bars. ** Try that now. **
34+
#
35+
# b. When you have completed a TODO, you should change the word
36+
# TODO
37+
# to
38+
# DONE.
39+
# Try it now on line 16 above, and note that its blue bar on
40+
# the scrollbar-like thing to the right has gone away.
41+
#
42+
# If you change TODOs to DONEs like this, you can tell when you have
43+
# finished all the exercises in a module -- there will be no blue bars
44+
# left on the scrollbar-like thing to the right.
45+
#
46+
# You have now completed TODO #2, so change its TODO on line 26 to DONE
47+
# (and proceed similarly for all forthcoming TODOs in this course).
48+
#
49+
########################################################################
50+
51+
########################################################################
52+
#
53+
# TODO: 3.
54+
# Add another print statement below the current Line 1.
55+
# It should print any string that you want (but keep it G-rated!)
56+
# Test your code by re-running this module and looking at
57+
# the Console to be sure that your string printed as expected.
58+
#
59+
########################################################################
60+
61+
########################################################################
62+
#
63+
# TODO: 4.
64+
# Add yet another print statement, just below the previous one.
65+
# This one should print the product of 3,607 and 34,227.
66+
# Let the computer do the arithmetic for you (no calculators!).
67+
# You do NOT have to use strings for this, so no quote marks!
68+
#
69+
# TEST your code by re-running this module, then asking someone
70+
# whom you trust: What number did your print display?
71+
# (HINT: It is an INTERESTING number.) Get help if yours is wrong.
72+
#
73+
########################################################################
74+
75+
########################################################################
76+
#
77+
# TODO: 5.
78+
# Look at the list of files in this project in the
79+
# PyDev Package Explorer
80+
# to the left.
81+
# Note that this file (m2_hello_world.py) has a little black dot
82+
# to the left of the filename. That means that you have
83+
# made changes to this file that you have not yet turned in.
84+
#
85+
# COMMIT your work (which turns it in) by selecting (clicking on)
86+
# the file with the black dot (or the entire project if you prefer)
87+
# and then do SVN ~ Commit... from the SVN menu at the top.
88+
#
89+
# Then check that the black symbol beside the file name in the
90+
# PyDev Package Explorer on the left has gone away.
91+
# That's how you can tell that you have turned in your work.
92+
#
93+
# Oh, one more thing:
94+
# Do you have any blue bars left on the on the scrollbar-like thing
95+
# to the right? If so, click on each blue bar and change
96+
# its TODO to DONE. Then run the file to save it, and COMMIT again.
97+
#
98+
# You can COMMIT as often as you like. DO FREQUENT COMMITS.
99+
#
100+
########################################################################

src/m3_turtles.py

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
"""
2+
Demonstrates using OBJECTS via Turtle Graphics.
3+
4+
Concepts include:
5+
-- CONSTRUCT an INSTANCE of a CLASS (we call such instances OBJECTS).
6+
-- Make an object ** DO ** something by using a METHOD.
7+
-- Reference an object's ** DATA ** by using an INSTANCE VARIABLE.
8+
9+
Also:
10+
-- ASSIGNING a VALUE to a NAME (VARIABLE).
11+
12+
Authors: David Mutchler, Dave Fisher, Valerie Galluzzi, Amanda Stouder,
13+
their colleagues and PUT_YOUR_NAME_HERE. March 2016.
14+
"""
15+
########################################################################
16+
#
17+
# TODO: 1.
18+
# (Yes, that means for YOU to DO things per these instructions:)
19+
#
20+
# On Line 13 above, replace PUT_YOUR_OWN_NAME_HERE with your OWN name.
21+
#
22+
# BTW, the green lines above form what is called a DOC-STRING.
23+
# It documents what this module does, in a way that exterior programs
24+
# can make sense of. It has no other effect on this program.
25+
#
26+
########################################################################
27+
28+
import rosegraphics as rg
29+
30+
# ----------------------------------------------------------------------
31+
# Next two lines after this comment set up a TurtleWindow object
32+
# for animation. The definition of a TurtleWindow is in the
33+
# rg (shorthand for rosegraphics) module.
34+
# ----------------------------------------------------------------------
35+
window = rg.TurtleWindow()
36+
window.delay(20) # Bigger numbers mean slower animation.
37+
38+
# ----------------------------------------------------------------------
39+
# Next two lines make (construct) two SimpleTurtle objects.
40+
# ----------------------------------------------------------------------
41+
nadia = rg.SimpleTurtle()
42+
akil = rg.SimpleTurtle('turtle')
43+
44+
# ----------------------------------------------------------------------
45+
# Next lines ask the SimpleTurtle objects to do things:
46+
# ----------------------------------------------------------------------
47+
nadia.forward(100)
48+
nadia.left(90)
49+
nadia.forward(200)
50+
51+
akil.right(45)
52+
akil.backward(50)
53+
akil.right(60)
54+
55+
nadia.forward(50)
56+
nadia.left(135)
57+
58+
# ----------------------------------------------------------------------
59+
# Next lines set the pen and speed characteristics of the
60+
# SimpleTurtle objects. The pen characteristic is itself an object
61+
# that is constructed, of type Pen.
62+
# ----------------------------------------------------------------------
63+
nadia.pen = rg.Pen('blue', 10) # Second argument is the Pen's thickness
64+
nadia.speed = 10 # big is faster (maxes out about 100), 1 is slowest)
65+
66+
akil.pen = rg.Pen('red', 30)
67+
akil.speed = 1
68+
69+
akil.backward(100)
70+
nadia.forward(100)
71+
72+
nadia.left(60)
73+
nadia.forward(500)
74+
nadia.speed = 1 # was 10, so much slower now
75+
nadia.right(120)
76+
nadia.forward(200)
77+
78+
########################################################################
79+
#
80+
# TODO: 2.
81+
# (Yes, that means for YOU to DO things per these instructions:)
82+
#
83+
# Run this module by using the green arrow on the toolbar up top.
84+
# A window will pop up and Turtles will move around. After the
85+
# Turtles stop moving, click anywhere in the window to close it.
86+
#
87+
# Then look at Lines 47 to 56. Run again and see if you can tell
88+
# what each Turtle command does. We call each such command a
89+
# METHOD.
90+
#
91+
# Then look at Lines 63 to 67. Run again and see if you can tell
92+
# what is different when, for a particular Turtle, its Turtle
93+
# characteristics:
94+
# pen speed
95+
# are assigned a value. We call such characteristics
96+
# INSTANCE VARIABLES, aka DATA ATTRIBUTES and (in Java) FIELDS.
97+
#
98+
# Note especially that although both Turtle objects have the
99+
# same NAMES for their instance variables, each Turtle has
100+
# its own VALUES for those instance variables. For example,
101+
# nadia's Pen has 'blue' as its color while akil's Pen is 'red'.
102+
#
103+
# No need for you to write anything for this part of the TODO.
104+
# Just change the TODO to DONE at Line 80 above, as usual
105+
# (and also the one at Line 17 if you have not already done that).
106+
#
107+
########################################################################
108+
109+
########################################################################
110+
#
111+
# TODO: 3.
112+
# Add a few more line after line 76 above to make one of the
113+
# existing Turtles move some more and/or have different
114+
# characteristics.
115+
#
116+
# ** Nothing fancy is required. KISS. **
117+
# ** A SUBSEQUENT exercise will let you show your creativity. **
118+
#
119+
# As always, test by running the module.
120+
#
121+
########################################################################
122+
123+
########################################################################
124+
#
125+
# TODO: 4.
126+
# Lines 41 and 42 CONSTRUCT two SimpleTurtle objects
127+
# and give those objects NAMES:
128+
# nadia akil
129+
# BTW, the definition for what a SimpleTurtle object knows and can do
130+
# is in the rosegraphics, abbreviated as rg, module, but you do NOT
131+
# need to (and should not) look at that module for this exercise.
132+
#
133+
# After the code that you have already added (from previous TODOs),
134+
# construct another SimpleTurtle object, naming it whatever you want.
135+
# Names cannot have spaces or special characters, but they can have
136+
# digits and underscores like this_1_has (get it?).
137+
#
138+
# Then, just below the line that you just wrote
139+
# to construct a SimpleTurtle, add a few more lines that
140+
# make YOUR SimpleTurtle move around a bit.
141+
#
142+
# ** Nothing fancy is required. KISS. **
143+
# ** A SUBSEQUENT exercise will let you show your creativity. **
144+
#
145+
# As always, test by running the module.
146+
#
147+
########################################################################
148+
149+
########################################################################
150+
#
151+
# TODO: 5.
152+
# After you have completed the above (including testing),
153+
# change the TODO at the beginning of this pink comment to DONE,
154+
# along with any other numbered TODOs that you have not yet done so.
155+
#
156+
# Run one more time to be sure that all is still OK.
157+
# Ensure that no blue bars on the scrollbar-thing to the right remain.
158+
#
159+
# Then COMMIT your work (which turns it in) by selecting (clicking on)
160+
# the file with the black dot (or the entire project if you prefer)
161+
# and then do SVN ~ Commit... from the SVN menu at the top.
162+
#
163+
# Check that the black symbol beside the file name in the
164+
# PyDev Package Explorer on the left has gone away.
165+
# That's how you can tell that you have turned in your work.
166+
#
167+
# You can COMMIT as often as you like. DO FREQUENT COMMITS.
168+
#
169+
########################################################################
170+
171+
# ----------------------------------------------------------------------
172+
# Next line keeps the window open until the user clicks in the window:
173+
# ----------------------------------------------------------------------
174+
window.close_on_mouse_click()

src/m4e_loopy_turtles.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
"""
2+
Demonstrates:
3+
-- LOOPS (doing something repeatedly) and
4+
-- using OBJECTS
5+
via Turtle Graphics.
6+
7+
Concepts include:
8+
* Using OBJECTS:
9+
-- CONSTRUCT an INSTANCE of a CLASS (we call such instances OBJECTS).
10+
-- Make an object ** DO ** something by using a METHOD.
11+
-- Reference an object's ** DATA ** by using an INSTANCE VARIABLE.
12+
13+
* LOOPS:
14+
-- Using a FOR expresssion like this:
15+
for k in range(41):
16+
blah
17+
blah
18+
blah
19+
20+
The above repeats the body of the FOR expression 41 times.
21+
The name k is:
22+
0 the first time the body runs,
23+
then 1 the next time the body runs,
24+
then 2 the next time the body runs,
25+
etc
26+
then 40 the last time the body runs.
27+
28+
* ASSIGNMENT and NAMES
29+
-- ASSIGNING a VALUE to a NAME (VARIABLE), as in these examples:
30+
jack = 45
31+
jill = 'ran down the hill'
32+
size = size - 12
33+
-- The computer's STATE during a run of a program is the set
34+
of current values of all the names that the computer is tracking.
35+
36+
* The DOT trick: Type expressions like the following,
37+
pausing after typing the DOT (period, full stop).
38+
The window that pops up give lots of clues for what you can do!
39+
rg.
40+
rg.SimpleTurtle().
41+
rg.Pen().
42+
rg.PaintBucket()
43+
44+
Authors: David Mutchler, Dave Fisher, Valerie Galluzzi, Amanda Stouder,
45+
and their colleagues. November 2016.
46+
"""
47+
import rosegraphics as rg
48+
49+
window = rg.TurtleWindow()
50+
51+
blue_turtle = rg.SimpleTurtle('turtle')
52+
blue_turtle.pen = rg.Pen('midnight blue', 3)
53+
blue_turtle.speed = 10 # Fast
54+
55+
# The first square will be 300 x 300 pixels:
56+
size = 300
57+
58+
# Do the indented code 13 times. Each time draws a square.
59+
for k in range(13):
60+
61+
# Put the pen down, then draw a square of the given size:
62+
blue_turtle.draw_square(size)
63+
64+
# Move a little below and to the right of where the previous
65+
# square started. Do this with the pen up (so nothing drawn).
66+
blue_turtle.pen_up()
67+
blue_turtle.right(45)
68+
blue_turtle.forward(10)
69+
blue_turtle.left(45)
70+
71+
# Put the pen down again (so drawing resumes).
72+
# Make the size for the NEXT square be 12 pixels smaller.
73+
blue_turtle.pen_down()
74+
size = size - 12
75+
76+
window.close_on_mouse_click()

src/m5_your_turtles.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
Your chance to explore Loops and Turtles!
3+
4+
Authors: David Mutchler, Dave Fisher, Valerie Galluzzi, Amanda Stouder,
5+
their colleagues and PUT_YOUR_NAME_HERE. November 2016.
6+
"""
7+
########################################################################
8+
# TODO: 1.
9+
# On Line 5 above, replace PUT_YOUR_NAME_HERE with your OWN name.
10+
########################################################################
11+
12+
########################################################################
13+
# TODO: 2.
14+
#
15+
# You should have RUN the PREVIOUS module and READ its code.
16+
# (Do so now if you have not already done so.)
17+
#
18+
# Below this comment, add ANY CODE THAT YOUR WANT, as long as:
19+
# 1. You construct at least 2 rg.SimpleTurtle objects.
20+
# 2. Each rg.SimpleTurtle object draws something
21+
# (by moving, using its rg.Pen). ANYTHING is fine!
22+
# 3. Each rg.SimpleTurtle moves inside a LOOP.
23+
#
24+
# Be creative! Strive for way-cool pictures! Abstract pictures rule!
25+
#
26+
# If you make syntax (notational) errors, no worries -- get help
27+
# fixing them at either this session OR at the NEXT session.
28+
#
29+
# Don't forget to COMMIT your work by using SVN ~ Commit.
30+
########################################################################

0 commit comments

Comments
 (0)