-
Notifications
You must be signed in to change notification settings - Fork 34
/
mymod.py
48 lines (39 loc) · 1.72 KB
/
mymod.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
40
41
42
43
44
45
46
47
48
"""Example module to contain methods, functions and variables for reuse.
This file gets loaded as a module (sometimes also called a library) when
you call `import mymod` in your scripts.
"""
import codestudio
class Zombie(codestudio.Artist):
"""An Artist with a propensity for brains and drawing squares.
While class definitions look like function definitions they are different.
The parameter inside the parenthesis () is the parent class. This means
all Zombies are Artists and can do everything an Artist can do.
The `start_direction` and `speed` are special variables that goes with
all Zombies. These are called class or static attributes. An attribute
is a variable that goes with a class or the objects created from a class.
"""
start_direction = 90 # facing the east, or right of screen
speed = 'slow' # it is a zombie after all
color = 'green' # it is a zombie after all
def draw_square(self,length):
for count in range(4):
self.move_forward(length)
self.turn_right(90)
def draw_circle(self):
saved_speed = zombie.speed
zombie.speed = 'fastest'
for count in range(360):
zombie.move_forward(1)
zombie.turn_right(1)
zombie.speed = saved_speed
def draw_snowman(self,length):
self.left()
distances = [length * 0.5, length * 0.3, length * 0.2]
for counter in range(6):
distance = distances[counter if counter < 3 else 5 - counter] / 57.5
for degree in range(90):
self.move(distance)
self.right(2)
if counter != 2:
self.left(180)
self.left()