From 8ff521173bcb6eb073c8413d62a570189ce40d3f Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Wed, 27 Jan 2010 23:08:43 +0000 Subject: *turtle imporvements --- diff --git a/tacanvas.py b/tacanvas.py index bf81876..e283f5a 100644 --- a/tacanvas.py +++ b/tacanvas.py @@ -97,6 +97,7 @@ class TurtleGraphics: self.xcor, self.ycor, self.heading = 0, 0, 0 self.move_turtle() self.turn_turtle() + self.tw.turtle_list.show_all() def forward(self, n): n *= self.tw.coord_scale @@ -192,6 +193,7 @@ class TurtleGraphics: self.pensize = ps except: pass + self.tw.turtle.set_pen_size(ps) self.gc.set_line_attributes(int(self.pensize*self.tw.coord_scale), gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_MITER) @@ -201,6 +203,7 @@ class TurtleGraphics: self.tcolor = c except: pass + self.tw.turtle.set_color(c) self.set_fgcolor() self.set_textcolor() @@ -222,6 +225,7 @@ class TurtleGraphics: self.shade = s except: pass + self.tw.turtle.set_shade(s) self.set_fgcolor() self.set_textcolor() @@ -297,7 +301,7 @@ class TurtleGraphics: h+self.pensize*self.tw.coord_scale+6) def turn_turtle(self): - self.tw.turtle.rotate(self.heading) + self.tw.turtle.set_heading(self.heading) def move_turtle(self): x, y = self.width/2+int(self.xcor), self.height/2-int(self.ycor) @@ -309,20 +313,24 @@ class TurtleGraphics: self.tw.area.invalidate_rect(rect, False) def set_turtle(self, i): - # TODO: associate pen state with individual turtles + # TODO: associate pen up/down state with individual turtles # TODO: reskin active turtle print "switching to Turtle %d" % (i) if i > self.tw.turtle_list.turtle_count()-1: - # if it is a new turtle, put it in the center of the screen + # if it is a new turtle, start it in the center of the screen self.tw.turtle = self.tw.turtle_list.get_turtle(i, True) self.xcor = 0 self.ycor = 0 self.heading = 0 - self.tw.turtle.move_turtle() - self.tw.turtle.rotate(self.heading) + self.move_turtle() + self.turn_turtle() self.tw.turtle = self.tw.turtle_list.get_turtle(i, True) tx, ty = self.tw.turtle.get_xy() self.xcor = tx+30-self.width/2 self.ycor = self.height/2-ty-30 self.heading = self.tw.turtle.get_heading() + self.setcolor(self.tw.turtle.get_color()) + self.setshade(self.tw.turtle.get_shade()) + self.setpensize(self.tw.turtle.get_pen_size()) self.tw.turtle_list.show_all() + diff --git a/talogo.py b/talogo.py index ec34570..ef276a1 100644 --- a/talogo.py +++ b/talogo.py @@ -63,16 +63,8 @@ class logoerror(Exception): return repr(self.value) def run_blocks(lc, blk, blocks, run_flag): - print "run blocks: %s" % (blk.name) - for b in blocks: - if b is None: - print " None" - else: - print " %s" % b.name - # user-defined stacks for x in lc.stacks.keys(): lc.stacks[x] = None - # two built-in stacks lc.stacks['stack1'] = None lc.stacks['stack2'] = None for b in blocks: @@ -177,7 +169,6 @@ def setup_cmd(lc, str): def start_eval(lc, list): icall(lc, evline, list); yield True - # turn off stop icon when execution is finished if hasattr(lc.tw,"activity"): lc.tw.activity.stop_button.set_icon("stopitoff") yield False @@ -981,7 +972,6 @@ def show(lc, string, center=False): y -= lc.tw.textsize lc.tw.canvas.draw_text(string,x,y,lc.tw.textsize,lc.tw.canvas.width-x) -# audio only def play_sound(lc, audio): play_audio(lc, audio) diff --git a/taproject.py b/taproject.py index 2eea89d..ffbe064 100644 --- a/taproject.py +++ b/taproject.py @@ -61,8 +61,7 @@ def new_project(tw): stop_logo(tw) for b in tw._just_blocks(): b.spr.hide() - tw.turtle.canvas.set_layer(CANVAS_LAYER) - clearscreen(tw.turtle) + tw.canvas.clearscreen() tw.save_file_name = None def load_file(tw, create_new_project=True): @@ -186,8 +185,8 @@ def load_block(tw, b): label = None """ blk = block.Block(tw.block_list, tw.sprite_list, - btype, b[2]+tw.turtle.cx, - b[3]+tw.turtle.cy, 'block', labels) + btype, b[2]+tw.canvas.cx, + b[3]+tw.canvas.cy, 'block', labels) """ if media is not None and media not in nolabel: try: @@ -209,11 +208,11 @@ def load_block(tw, b): def load_turtle(tw, b): id, name, xcor, ycor, heading, color, shade, pensize = b - setxy(tw.turtle, xcor, ycor) - seth(tw.turtle, heading) - setcolor(tw.turtle, color) - setshade(tw.turtle, shade) - setpensize(tw.turtle, pensize) + tw.canvas.setxy(xcor, ycor) + tw.canvas.seth(heading) + tw.canvas.setcolor(color) + tw.canvas.setshade(shade) + tw.canvas.setpensize(pensize) # start a new project with a start brick def load_start(tw): @@ -287,11 +286,11 @@ def _assemble_data_to_save(tw, save_turtle=True): connections = None print connections (sx, sy) = b.spr.get_xy() - data.append((b.id, name, sx-tw.turtle.cx, sy-tw.turtle.cy, connections)) + data.append((b.id, name, sx-tw.canvas.cx, sy-tw.canvas.cy, connections)) if save_turtle is True: data.append((-1,'turtle', - tw.turtle.xcor,tw.turtle.ycor,tw.turtle.heading, - tw.turtle.color,tw.turtle.shade,tw.turtle.pensize)) + tw.canvas.xcor,tw.canvas.ycor,tw.canvas.heading, + tw.canvas.color,tw.canvas.shade,tw.canvas.pensize)) return data # Serialize a stack to save to the clipboard diff --git a/taturtle.py b/taturtle.py index 7dd63c1..a1874da 100644 --- a/taturtle.py +++ b/taturtle.py @@ -85,6 +85,9 @@ class Turtle: self.shapes = [] self.type = 'turtle' self.heading = 0 + self.color = 0 + self.shade = 50 + self.pen_size = 5 _svg = SVG() _svg.set_scale(scale) self.spr = sprites.Sprite(turtle_list.sprite_list, self.x, self.y, @@ -94,7 +97,7 @@ class Turtle: _svg.set_orientation(i*10) self.shapes.append(svg_str_to_pixbuf(_svg.turtle(colors))) - def rotate(self, heading): + def set_heading(self, heading): self.heading = heading i = (int(self.heading+5)%360)/10 try: @@ -103,6 +106,15 @@ class Turtle: self.spr.set_shape(self.shapes[0]) print "Turtle shape IndexError %f -> %d" % (heading, i) + def set_color(self, color): + self.color = color + + def set_shade(self, shade): + self.shade = shade + + def set_pen_size(self, pen_size): + self.pen_size = pen_size + def hide(self): self.spr.set_layer(HIDE_LAYER) @@ -118,3 +130,12 @@ class Turtle: def get_heading(self): return(self.heading) + + def get_color(self): + return(self.color) + + def get_shade(self): + return(self.shade) + + def get_pen_size(self): + return(self.pen_size) -- cgit v0.9.1