-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mouse.py
39 lines (33 loc) · 1.12 KB
/
Mouse.py
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
__author__ = 'zhengxiaoyu'
from Turtle import Turtle
from Vector import *
from Color import *
class Mouse(Turtle): #### Inherit behavior from Turtle
"""This turtle walks in a straight line forever.
>>> mouse = mouse(Vector(450,350),1)
>>> mouse.getnextstate()[0].x
>>> 345.0
>>> round(mouse.getshape()[0].y,3)
>>> 351.750
"""
def __init__(self, position, heading, angle, fill=blue, **style):
'''
init the mouse
'''
Turtle.__init__(self, position, heading, fill=fill, **style)
self.angle = float(angle)/60
self.dead = False
self.degree = 0
def getshape(self):
"""Return a list of vectors giving the polygon for this turtle."""
return [self.position + Vector(0,5),
self.position - Vector(5,0),
self.position - Vector(0,5),
self.position + Vector(5,0)]
def getnextstate(self):
'''
:return the shape of the mouse
'''
if self.dead:
return self.position, 0
return self.position.counterclockwise(Vector(450,350),self.angle), 0