class Snail
-----------
Snail(center, radius, name) # center - Point at the center of snail's shell
# radius - radius of snail's shell
# name - a String with snail's name
draw(graphwin)
move(dx, dy)
setFill(color)
undraw()
setName(name)
getName() # Returns snail's name
getRadius()
getCenter() # Return Point at center of Snail's shell
frontPoint() # Returns the right-most point on the Snail
clone()
The following program imports the Zelle graphics library, the Snail class, and the time libray. It creates a pink snail named Gary, draws Gary to the left of the screen, and then animates Gary's snail-like movement across the screen. Then it waits for a mouse click before using the getName() method to retrieve Gary's full name and print a message.
"""
Move a snail named Gary across the screen.
"""
from graphics import *
from snail import *
from time import *
def main():
width = 400
height = 400
window = GraphWin("Gary the snail", width, height)
gary = Snail(Point(width/5, height/2), width/10, "Gary the pink snail")
gary.setFill("pink")
gary.draw(window)
for i in range(200):
gary.move(1, 0)
sleep(0.05)
window.getMouse()
print("%s is done moving for today." % gary.getName())
main()