This task is part of project02 which is due at 23:00 EDT on 2024-09-17.
You have the option to work with a partner on this task if you wish. Working with a partner requires more work to coordinate schedules, but if you work together and make sure that you are both understanding the code you write, you will make progress faster and learn more.
You can download the starter code for this task using this link.
You can submit this task using this link.
Put all of your work for this task into the file
monsterMash.py
(which is provided among the starter files)
This task is based on mix-and-match paper cut-out toys, where you can create your own monster or animal by combining different body parts (here's an extra-cool example where each paper piece has a crochet pattern).
Your goal in this task is to write functions that use turtle
graphics
to draw monster pieces: tails, bodies, and heads. These functions will be
combined with each other to draw a mixed-up monster. The results might
look something like this image, which combines pieces from orange, green,
and yellow monsters:
Notice how multiple tails, heads, and bodies are combined into a single
monster, and that the sections roughly match up with each other, although
it isn't perfect. The pieces of this monster come from our solution code,
as well as from two files that we have provided: greenMonster.py
and
yellowMonster.py
. You are encouraged to use these files as examples to
work from when building your own monster pieces, but you must do more
than simply copy the code in these files.
For this subtask, you will define three functions: monsterTail
,
monsterBody
, and monsterHead
. These functions must not take any
parameters.
To ensure that the tails, bodies, and heads that your code draws are able to fit together with other monster pieces, each part has to obey certain rules:
monsterTail
: When drawing a
monster tail, the turtle will start off facing east at the top of the
monster's back end. The tail should be drawn so that it touches the
back end of the monster's body, which will generally extend at least
40-50 units south of the cursor's starting position. Stuff you draw
to east of the starting position will overlap the monster body, so
you should draw stuff to the west. By the time it's done, your
monsterTail
function must put the cursor back in the exact same
spot it started at and leave the pen
down. You are not allowed to use any
absolute movement or orientation
functions (like
setposition
, teleport
, setheading
, or realign
) while drawing
your monster tail, because doing so would prevent the tail from
drawing correctly when positioned in different places.
monsterBody
: When drawing a
monster body, the cursor will start at the upper-left corner of the
body facing east, and the body should be drawn such that it extends
about 100 units forward from the starting position, and about 50
units down. (the green monster does this using by drawing a 100x50
rectangle). Just as with monsterTail
, the turtle must end up facing
the same direction as when it started, but instead of leaving the
turtle in the same place, it must move it exactly 100 units
forward. That way, another body segment
or a head can be drawn immediately afterwards. Using absolute
movement or orientation functions is not
allowed for the same
reason as with monsterTail
monsterHead
: When drawing the
monster head, the cursor will be positioned at the north-east corner
of the body facing east. It should generally draw stuff to the east
of this starting position, but it is not required to; whatever it
draws will be drawn on top of the tail and body, since it gets called
last. Just as with the tail and body, you may not use absolute
movement commands in this
function, and as with
the tail, you must put the turtle back where it
started before the function is done (in
case someone wants to draw a second head, for example).
In addition to these specific rules, each of your body part functions must do each of these things:
pensize
function to set the pen width. Do not assume that the pen size will be
1 when the body part is started.
(monsterTail
,
monsterBody
,
monsterHead
).pencolor
and
fillcolor
functions (or just the
color
function) to set both the pen and fill colors (may use the same
color for both). Do not assume that the pen or fill colors will be
black when the body part is started.
(monsterTail
,
monsterBody
,
monsterHead
). penup
without later calling
pendown
).
(
monsterTail
,
monsterBody
,
monsterHead
)Call at least two different turtle
or turtleBeads
drawing
functions from the following list:
fd
,
forward
,
bk
,
back
,
backward
,
circle
,
write
,
begin_fill
,
end_fill
,
drawSquare
,
drawRectangle
,
drawCircle
,
drawDot
,
drawEllipse
,
drawPolygon
,
drawText
Finally, your monsterBody
function must call a custom function that you
define, which calls at least one of the drawing functions from the
list above. It is
completely up to you how to define and use this custom function, but we
recommend using it to help you add things like wings or legs to your
monster. Such a custom function can be especially useful for capturing
and then easily repeating a complex series of drawing commands.
The diagram below shows how the different pieces of the monster are supposed to fit together:
These monster piece examples also show how the different pieces should work independently and fit together.
Once you are done with your monster piece functions, your next task is to
combine them with the pieces of the green and/or yellow monsters to draw
a monster with different parts mashed together. Your monsterMash
function must not take any parameters and must obey the following rules:
greenBody
and then monsterBody
, or yellowBody
and greenBody
.pensize
or call
pencolor
(the
monster part functions must do this themselves).The first example image shown above meets and/or exceeds all of these
criteria; this monsterMash
example shows the
results of code that calls monsterMash
.
As usual, there are a few rules you must follow throughout:
None
) in a variable (a.k.a., box).The test_monsterMash.py
file included in the starter code will call
your functions and print out some information about their start and end
positions. You need to uncomment sections of this file to add tests as
you complete each function.
Demonstration of the monster pieces
These examples illustrate how the different pieces are drawn individually, as well as how they fit together. Note that for the tail and head, the stamps created before and afterward are in the same place.
In []:Prints# Create a stamp of the turtle and print the starting position color("black") stamp() print("Start:", pos()) greenTail() # Create a second stamp and print the final position color("black") stamp() print("End:", pos())
Start: (0.00,0.00) A 18-pensize PaleGreen3 arc from (0, -18) facing West to (-38, -44) facing 250°. A 18-pensize PaleGreen3 arc from (-38, -44) facing 250° to (-101, -61) facing 140°. A 3-pensize PaleGreen3 140° line from (-101, -61) to (-110, -54). Start of filled shape. A 3-pensize PaleGreen3 triangle with side length 32 centered at (-110, -54) with a flat side facing 320°. Filled in shape using PaleGreen3. End: (-0.00,-0.00)Image In []:Prints# move and turn before drawing teleport(-50, -50) lt(90) # Create a stamp of the turtle and print the starting position color("black") stamp() print("Start:", pos()) # draw a body greenBody() # Create a second stamp and print the final position color("black") stamp() print("End:", pos())
Start: (-50.00,-50.00) Start of filled shape. A PaleGreen4 100 by 50 rectangle centered at (-25, 0) with a vertical long axis. Filled in shape using PaleGreen4. A 7-pensize PaleGreen3 150° line from (-37, 25) to (-80, 50). Start of filled shape. A 7-pensize PaleGreen3 horizontal line from (-80, 50) to (-150, 50). A 7-pensize PaleGreen3 60° line from (-115, -11) to (-80, 50). Filled in shape using PaleGreen. Start of filled shape. A 7-pensize PaleGreen3 60° line from (-80, 50) to (-115, -11). A 7-pensize PaleGreen3 120° line from (-45, -11) to (-80, 50). Filled in shape using PaleGreen. End: (-50.00,50.00)Image In []:Prints# Create a stamp of the turtle and print the starting position color("black") stamp() print("Start:", pos()) greenHead() # Create a second stamp and print the final position color("black") stamp() print("End:", pos())
Start: (0.00,0.00) A 18-pensize PaleGreen3 30° line from (0, -18) to (43, 7). Start of filled shape. A 18-pensize PaleGreen3 hexagon with side length 20 centered at (43, 7) with a flat side facing North. Filled in shape using PaleGreen3. A PaleGreen4 dot with radius 5. A 3-pensize PaleGreen4 160° line from (62, -8) to (53, -5). End: (-0.00,-0.00)Image In []:Prints# Back up first leap(-100) # Create a stamp of the turtle and print the starting position color("black") stamp() print("Start:", pos()) # Draw a green tail + body, and then a yellow body + head greenTail() greenBody() yellowBody() yellowHead() # Create a second stamp and print the final position color("black") stamp() print("End:", pos())
Start: (-100.00,0.00) A 18-pensize PaleGreen3 arc from (-100, -18) facing West to (-138, -44) facing 250°. A 18-pensize PaleGreen3 arc from (-138, -44) facing 250° to (-201, -61) facing 140°. A 3-pensize PaleGreen3 140° line from (-201, -61) to (-210, -54). Start of filled shape. A 3-pensize PaleGreen3 triangle with side length 32 centered at (-210, -54) with a flat side facing 320°. Filled in shape using PaleGreen3. Start of filled shape. A PaleGreen4 100 by 50 rectangle centered at (-50, -25) with a horizontal long axis. Filled in shape using PaleGreen4. A 7-pensize PaleGreen3 60° line from (-25, -13) to (0, 30). Start of filled shape. A 7-pensize PaleGreen3 vertical line from (0, 30) to (0, 100). A 7-pensize PaleGreen3 150° line from (-61, 65) to (0, 30). Filled in shape using PaleGreen. Start of filled shape. A 7-pensize PaleGreen3 150° line from (0, 30) to (-61, 65). A 7-pensize PaleGreen3 30° line from (-61, -5) to (0, 30). Filled in shape using PaleGreen. Start of filled shape. A 1-pensize yellow 30° line from (0, 0) to (30, 17). A 1-pensize yellow 150° line from (30, 17) to (70, -6). A 1-pensize yellow 30° line from (70, -6) to (100, 12). A 1-pensize yellow vertical line from (100, 12) to (100, -53). A 1-pensize yellow 30° line from (100, -53) to (70, -71). A 1-pensize yellow 150° line from (70, -71) to (30, -48). A 1-pensize yellow 30° line from (30, -48) to (0, -65). A 1-pensize yellow vertical line from (0, -65) to (0, 0). Filled in shape using yellow. Start of filled shape. A 1-pensize Gold2 10° line from (80, -30) to (55, -34). A 1-pensize Gold2 130° line from (55, -34) to (71, -53). A 1-pensize Gold2 70° line from (71, -53) to (80, -30). Filled in shape using Gold3. A 4-pensize Gold2 10° line from (80, -30) to (55, -34). A 4-pensize Gold2 30° line from (80, -30) to (58, -42). A 4-pensize Gold2 50° line from (80, -30) to (64, -49). A 4-pensize Gold2 70° line from (80, -30) to (71, -53). A 8-pensize Gold2 30° line from (100, -15) to (113, -8). A 8-pensize Gold2 150° line from (113, -8) to (130, -18). A 8-pensize Gold2 30° line from (130, -18) to (143, -10). Start of filled shape. A 1-pensize yellow vertical line from (143, -10) to (143, 10). A 1-pensize yellow 150° line from (143, 10) to (178, -10). A 1-pensize yellow 30° line from (178, -10) to (143, -30). A 1-pensize yellow vertical line from (143, -30) to (143, -10). Filled in shape using yellow. A Gold3 dot with radius 3. End: (100.00,-0.00)Image
Demonstration of the monsterMash function
This example shows how the monsterMash function could work. You are free to choose a different mix of tails, bodies, and heads as long as you draw at least one tail, two bodies, and one head. This example creates one stamp at the start and one at the end, and prints out the position before and afterwards. Since this version draws 3 bodies, it moves 300 units forward (although it's not perfectly precise, it's within 1 unit of the correct destination, which is fine).
In []:Prints# Back up first leap(-150) # Create a stamp of the turtle and print the starting position color("black") stamp() print("Start:", pos()) monsterMash() # Create a second stamp and print the final position color("black") stamp() print("End:", pos())
Start: (-150.00,0.00) Start of filled shape. A 3-pensize DarkOrange2 arc from (-138, 37) facing 120° to (-160, 0) facing East. A 3-pensize DarkOrange2 horizontal line from (-160, 0) to (-150, 0). A 3-pensize DarkOrange2 vertical line from (-150, 0) to (-150, -50). A 3-pensize DarkOrange2 horizontal line from (-150, -50) to (-160, -50). A 3-pensize DarkOrange2 arc from (-160, -50) facing West to (-220, 10) facing North. A 3-pensize DarkOrange2 arc from (-220, 10) facing North to (-172, 58) facing East. A 3-pensize DarkOrange2 arc from (-172, 58) facing East to (-137, 38) facing 300°. Filled in shape using DarkOrange2. A 18-pensize PaleGreen3 arc from (-150, -18) facing West to (-188, -44) facing 250°. A 18-pensize PaleGreen3 arc from (-188, -44) facing 250° to (-251, -61) facing 140°. A 3-pensize PaleGreen3 140° line from (-251, -61) to (-260, -54). Start of filled shape. A 3-pensize PaleGreen3 triangle with side length 32 centered at (-260, -54) with a flat side facing 320°. Filled in shape using PaleGreen3. Start of filled shape. A 1-pensize yellow 30° line from (-150, 0) to (-120, 17). A 1-pensize yellow 150° line from (-120, 17) to (-80, -6). A 1-pensize yellow 30° line from (-80, -6) to (-50, 12). A 1-pensize yellow vertical line from (-50, 12) to (-50, -53). A 1-pensize yellow 30° line from (-50, -53) to (-80, -71). A 1-pensize yellow 150° line from (-80, -71) to (-120, -48). A 1-pensize yellow 30° line from (-120, -48) to (-150, -65). A 1-pensize yellow vertical line from (-150, -65) to (-150, 0). Filled in shape using yellow. Start of filled shape. A 1-pensize Gold2 10° line from (-70, -30) to (-95, -34). A 1-pensize Gold2 130° line from (-95, -34) to (-79, -53). A 1-pensize Gold2 70° line from (-79, -53) to (-70, -30). Filled in shape using Gold3. A 4-pensize Gold2 10° line from (-70, -30) to (-95, -34). A 4-pensize Gold2 30° line from (-70, -30) to (-92, -42). A 4-pensize Gold2 50° line from (-70, -30) to (-86, -49). A 4-pensize Gold2 70° line from (-70, -30) to (-79, -53). Start of filled shape. A 3-pensize DarkOrange4 circle centered at (0, -25) with radius 55.9 Filled in shape using DarkOrange4. A 16-pensize DarkOrange2 80° line from (-25, -50) to (-32, -89). A 16-pensize DarkOrange2 60° line from (-32, -89) to (-42, -107). Start of filled shape. A 16-pensize DarkOrange2 triangle with side length 12 centered at (-42, -107) with a flat side facing 240°. Filled in shape using DarkOrange4. A 16-pensize DarkOrange2 120° line from (25, -50) to (45, -85). A 16-pensize DarkOrange2 100° line from (45, -85) to (48, -104). Start of filled shape. A 16-pensize DarkOrange2 triangle with side length 12 centered at (48, -104) with a flat side facing 280°. Filled in shape using DarkOrange4. Start of filled shape. A PaleGreen4 100 by 50 rectangle centered at (100, -25) with a horizontal long axis. Filled in shape using PaleGreen4. A 7-pensize PaleGreen3 60° line from (125, -13) to (150, 30). Start of filled shape. A 7-pensize PaleGreen3 vertical line from (150, 30) to (150, 100). A 7-pensize PaleGreen3 150° line from (89, 65) to (150, 30). Filled in shape using PaleGreen. Start of filled shape. A 7-pensize PaleGreen3 150° line from (150, 30) to (89, 65). A 7-pensize PaleGreen3 30° line from (89, -5) to (150, 30). Filled in shape using PaleGreen. Start of filled shape. A 3-pensize darkOrange2 30° line from (150, 0) to (193, 25). A 3-pensize darkOrange2 100° line from (193, 25) to (197, 5). A 3-pensize darkOrange2 50° line from (197, 5) to (150, -50). A 3-pensize darkOrange2 vertical line from (150, -50) to (150, 0). Filled in shape using darkOrange2. Start of filled shape. A 3-pensize darkOrange2 ellipse centered at (199, 13) with a 36-unit horizontal major axis and a 30-unit minor axis Filled in shape using darkOrange2. A OrangeRed4 dot with radius 6. A 3-pensize OrangeRed4 arc from (228, -6) facing 170° to (209, 3) facing 140°. A 3-pensize OrangeRed4 arc from (209, 3) facing 320° to (228, -6) facing 350°. A 8-pensize Gold2 20° line from (148, -30) to (162, -24). A 8-pensize Gold2 140° line from (162, -24) to (177, -37). A 8-pensize Gold2 20° line from (177, -37) to (191, -32). Start of filled shape. A 1-pensize yellow 80° line from (191, -32) to (195, -13). A 1-pensize yellow 140° line from (195, -13) to (226, -38). A 1-pensize yellow 20° line from (226, -38) to (188, -52). A 1-pensize yellow 80° line from (188, -52) to (191, -32). Filled in shape using yellow. A Gold3 dot with radius 3. End: (150.49,0.15)Image
=
or by defining a parameter for a function) you must also later use that variable as part of another expression. If you need to create a variable that you won't use, it must have the name _
, but you should only do this if absolutely necessary.monsterTail
net turtle movement
monsterTail
net turtle movement (test 1/2)
monsterTail
net turtle movement (test 2/2)
monsterBody
net turtle movement
monsterBody
net turtle movement (test 1/2)
monsterBody
net turtle movement (test 2/2)
monsterHead
net turtle movement
monsterHead
net turtle movement (test 1/2)
monsterHead
net turtle movement (test 2/2)
monsterTail
with 0 parameters
def
to define monsterTail
with 0 parameterspensize
monsterTail
with 0 parameters, call pensize
or penSize
in at least one place.pencolor
monsterTail
with 0 parameters, call pencolor
, color
, fillcolor
, penColor
, or fillColor
in at least one place.setpos
monsterTail
with 0 parameters, do not call setpos
, setposition
, goto
, setx
, sety
, teleport
, seth
, setheading
, realign
, reset
, setPosition
, setX
, setY
, or setHeading
.turtle
or turtleBeads
drawing functions.
monsterTail
with 0 parameters, use at least two different drawing functions from the following list: fd
, forward
, bk
, back
, backward
, circle
, write
, begin_fill
, end_fill
, drawSquare
, drawRectangle
, drawCircle
, drawDot
, drawEllipse
, drawPolygon
, drawText
, beginFill
, endFill
monsterBody
with 0 parameters
def
to define monsterBody
with 0 parameterspensize
monsterBody
with 0 parameters, call pensize
or penSize
in at least one place.pencolor
monsterBody
with 0 parameters, call pencolor
, color
, fillcolor
, penColor
, or fillColor
in at least one place.setpos
monsterBody
with 0 parameters, do not call setpos
, setposition
, goto
, setx
, sety
, teleport
, seth
, setheading
, realign
, reset
, setPosition
, setX
, setY
, or setHeading
.turtle
or turtleBeads
drawing functions.
monsterBody
with 0 parameters, use at least two different drawing functions from the following list: fd
, forward
, bk
, back
, backward
, circle
, write
, begin_fill
, end_fill
, drawSquare
, drawRectangle
, drawCircle
, drawDot
, drawEllipse
, drawPolygon
, drawText
, beginFill
, endFill
monsterBody
with 0 parameters
def
to define monsterBody
with 0 parametersmonsterBody
with 0 parameters, your code must call a custom function, and that function must use a drawing command.turtle
or turtleBeads
drawing functions.
monsterBody
with 0 parameters, use at least two different drawing functions from the following list: fd
, forward
, bk
, back
, backward
, circle
, write
, begin_fill
, end_fill
, drawSquare
, drawRectangle
, drawCircle
, drawDot
, drawEllipse
, drawPolygon
, drawText
, beginFill
, endFill
monsterHead
with 0 parameters
def
to define monsterHead
with 0 parameterspensize
monsterHead
with 0 parameters, call pensize
or penSize
in at least one place.pencolor
monsterHead
with 0 parameters, call pencolor
, color
, fillcolor
, penColor
, or fillColor
in at least one place.setpos
monsterHead
with 0 parameters, do not call setpos
, setposition
, goto
, setx
, sety
, teleport
, seth
, setheading
, realign
, reset
, setPosition
, setX
, setY
, or setHeading
.turtle
or turtleBeads
drawing functions.
monsterHead
with 0 parameters, use at least two different drawing functions from the following list: fd
, forward
, bk
, back
, backward
, circle
, write
, begin_fill
, end_fill
, drawSquare
, drawRectangle
, drawCircle
, drawDot
, drawEllipse
, drawPolygon
, drawText
, beginFill
, endFill
monsterMash
def
to define monsterMash
pensize
monsterMash
, do not call pensize
.pencolor
monsterMash
, do not call pencolor
, color
, or fillcolor
.monsterMash
, use at least one of monsterTail
, greenTail
, or yellowTail
.monsterMash
, use at least two of monsterBody
, greenBody
, or yellowBody
.monsterMash
, use at least one of monsterHead
, greenHead
, or yellowHead
.