diff options
author | Walter Bender <walter@sugarlabs.org> | 2010-08-22 13:38:24 (GMT) |
---|---|---|
committer | Walter Bender <walter@sugarlabs.org> | 2010-08-22 13:38:24 (GMT) |
commit | 0adbe793bb5454ed08a050f4f0edf1a92553c4fc (patch) | |
tree | a562c76be6fc7794441b79bc1c9aa5e7fbaf7873 /TurtleArt/taturtle.py | |
parent | 36bdd8452d23ab2d4703bc5d4e65ce4b972bb7bc (diff) |
using turtle name to generate turtle color
Diffstat (limited to 'TurtleArt/taturtle.py')
-rw-r--r-- | TurtleArt/taturtle.py | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/TurtleArt/taturtle.py b/TurtleArt/taturtle.py index abfb415..f5e2c5e 100644 --- a/TurtleArt/taturtle.py +++ b/TurtleArt/taturtle.py @@ -21,6 +21,7 @@ from taconstants import TURTLE_LAYER from tasprite_factory import SVG, svg_str_to_pixbuf +from tacanvas import wrap100, color_table from sprites import Sprite def generate_turtle_pixbufs(colors): @@ -102,7 +103,7 @@ class Turtles: # A class for the individual turtles # class Turtle: - def __init__(self, turtles, key, colors=None): + def __init__(self, turtles, key, turtle_colors=None): """ The turtle is not a block, just a sprite with an orientation """ self.x = 0 self.y = 0 @@ -116,11 +117,25 @@ class Turtle: self.pen_size = 5 self.pen_state = True - if colors is None: - self.shapes = turtles.get_pixbufs() - else: - self.colors = colors[:] + # If the turtle key is an int, we'll use a palette color as the + # turtle color + try: + int_key = int(key) + use_color_table = True + except ValueError: + use_color_table = False + + if turtle_colors is not None: + self.colors = turtle_colors[:] self.shapes = generate_turtle_pixbufs(self.colors) + elif use_color_table: + fill = wrap100(int_key) + stroke = wrap100(fill + 10) + self.colors = ['#%06x' % (color_table[fill]), + '#%06x' % (color_table[stroke])] + self.shapes = generate_turtle_pixbufs(self.colors) + else: + self.shapes = turtles.get_pixbufs() if turtles.sprite_list is not None: self.spr = Sprite(turtles.sprite_list, 0, 0, self.shapes[0]) |