Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/taturtle.py
diff options
context:
space:
mode:
Diffstat (limited to 'taturtle.py')
-rw-r--r--taturtle.py34
1 files changed, 29 insertions, 5 deletions
diff --git a/taturtle.py b/taturtle.py
index 9de4f58..9c8fe26 100644
--- a/taturtle.py
+++ b/taturtle.py
@@ -19,12 +19,12 @@
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#THE SOFTWARE.
-from taconstants import *
+from taconstants import TURTLE_LAYER
from tasprite_factory import SVG, svg_str_to_pixbuf
from sprites import Sprite
-from gettext import gettext as _
def generate_turtle_pixbufs(colors):
+ """ Generate pixbufs for generic turtles """
shapes = []
svg = SVG()
svg.set_scale(1.0)
@@ -38,11 +38,13 @@ def generate_turtle_pixbufs(colors):
#
class Turtles:
def __init__(self, sprite_list):
+ """ Class to hold turtles """
self.dict = dict()
self.sprite_list = sprite_list
self.default_pixbufs = []
def get_turtle(self, k, append=False):
+ """ Find a turtle """
if self.dict.has_key(k):
return self.dict[k]
elif append is False:
@@ -52,22 +54,27 @@ class Turtles:
return self.dict[k]
def get_turtle_key(self, turtle):
+ """ Find a turtle's name """
for k in iter(self.dict):
if self.dict[k] == turtle:
return k
return None
def turtle_count(self):
+ """ How many turtles are there? """
return(len(self.dict))
def add_to_dict(self, k, turtle):
+ """ Add a new turtle """
self.dict[k] = turtle
def remove_from_dict(self, k):
+ """ Delete a turtle """
if self.dict.has_key(k):
del(self.dict[k])
def show_all(self):
+ """ Make all turtles visible """
for k in iter(self.dict):
self.dict[k].show()
@@ -75,23 +82,25 @@ class Turtles:
# sprite utilities
#
def spr_to_turtle(self, spr):
+ """ Find the turtle that corresponds to sprite spr. """
for k in iter(self.dict):
if spr == self.dict[k].spr:
return self.dict[k]
return None
def get_pixbufs(self):
+ """ Get the pixbufs for the default turtle shapes. """
if self.default_pixbufs == []:
- self.default_pixbufs = generate_turtle_pixbufs(
- ["#008000", "#00A000"])
+ self.default_pixbufs = generate_turtle_pixbufs(
+ ["#008000", "#00A000"])
return(self.default_pixbufs)
#
# A class for the individual turtles
#
class Turtle:
- # The turtle is not a block, just a sprite with an orientation
def __init__(self, turtles, key, colors=None):
+ """ The turtle is not a block, just a sprite with an orientation """
self.x = 0
self.y = 0
self.hidden = False
@@ -113,6 +122,7 @@ class Turtle:
turtles.add_to_dict(key, self)
def set_heading(self, heading):
+ """ Set the turtle heading (and shape: one per 10 degrees) """
self.heading = heading
i = (int(self.heading+5)%360)/10
if self.hidden is False:
@@ -123,46 +133,60 @@ class Turtle:
print "Turtle shape IndexError %f -> %d" % (heading, i)
def set_color(self, color):
+ """ Set the pen color for this turtle. """
self.pen_color = color
def set_shade(self, shade):
+ """ Set the pen shade for this turtle. """
self.pen_shade = shade
def set_pen_size(self, pen_size):
+ """ Set the pen size for this turtle. """
self.pen_size = pen_size
def set_pen_state(self, pen_state):
+ """ Set the pen state (down==True) for this turtle. """
self.pen_state = pen_state
def hide(self):
+ """ Hide the turtle. """
self.spr.hide()
self.hidden = True
def show(self):
+ """ Show the turtle. """
self.spr.set_layer(TURTLE_LAYER)
self.hidden = False
self.move((self.x, self.y))
self.set_heading(self.heading)
def move(self, pos):
+ """ Move the turtle. """
self.x, self.y = pos[0], pos[1]
if self.hidden is False:
self.spr.move(pos)
+ return(self.x, self.y)
def get_xy(self):
+ """ Return the turtle's x, y coordinates. """
return(self.x, self.y)
def get_heading(self):
+ """ Return the turtle's heading. """
return(self.heading)
def get_color(self):
+ """ Return the turtle's color. """
return(self.pen_color)
def get_shade(self):
+ """ Return the turtle's shade. """
return(self.pen_shade)
def get_pen_size(self):
+ """ Return the turtle's pen size. """
return(self.pen_size)
def get_pen_state(self):
+ """ Return the turtle's pen state. """
return(self.pen_state)