Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/pysamples/forward_push.py
diff options
context:
space:
mode:
authorWalter Bender <walter@sugarlabs.org>2013-11-13 22:42:18 (GMT)
committer Walter Bender <walter@sugarlabs.org>2013-11-13 22:42:18 (GMT)
commit6acdbc3db543f2692ee336a99722f5ab0b46c77e (patch)
tree97b84e77c63bddeb49bcb804e25e2457008f6a8d /pysamples/forward_push.py
parent3865e3c912f70fd7fcef2d20831a0231d30d96f1 (diff)
convert to new primitive type
Diffstat (limited to 'pysamples/forward_push.py')
-rw-r--r--pysamples/forward_push.py31
1 files changed, 17 insertions, 14 deletions
diff --git a/pysamples/forward_push.py b/pysamples/forward_push.py
index b98c726..80fe818 100644
--- a/pysamples/forward_push.py
+++ b/pysamples/forward_push.py
@@ -1,13 +1,16 @@
-#Copyright (c) 2012, Walter Bender
+#Copyright (c) 2012-2013, Walter Bender
# Usage: Import this code into a Python (user-definable) block; when
-# this code is run, the turtle will draw a line of the length of the
-# numeric argument block docked to the Python block. But before
-# drawing the line, it pushes the rgb values of the destination to the
-# FILO.
+# this code is run, a new block will be added to the Turtle Palette.
+# This block will be named 'name', the value of the argument block
+# docked to the Python block.
+#
+# The new block will cause the turtle to draw a line of the
+# length. But before drawing the line, it pushes the rgb values of the
+# destination to the FILO.
-def myblock(tw, name):
+def myblock(tw, args):
''' '''
def _prim_forward_push(tw, line_length):
@@ -15,16 +18,16 @@ def myblock(tw, name):
line_length = float(line_length)
except ValueError:
return
- penstatus = tw.canvas.pendown
- tw.canvas.setpen(False)
- tw.canvas.forward(line_length)
- r, g, b, a = tw.canvas.get_pixel()
+ penstatus = tw.turtles.get_active_turtle().get_pen_status()
+ tw.turtles.get_active_turtle().set_pen_state(False)
+ tw.turtles.get_active_turtle().forward(line_length)
+ r, g, b, a = tw.turtles.get_active_turtle().get_pixel()
tw.lc.heap.append(b)
tw.lc.heap.append(g)
tw.lc.heap.append(r)
- tw.canvas.forward(-line_length)
- tw.canvas.setpen(penstatus)
- tw.canvas.forward(line_length)
+ tw.turtles.get_active_turtle().forward(-line_length)
+ tw.turtles.get_active_turtle().set_pen_state(penstatus)
+ tw.turtles.get_active_turtle().forward(line_length)
return
from TurtleArt.tapalette import make_palette, palette_name_to_index
@@ -39,7 +42,7 @@ def myblock(tw, name):
# Create a new block prototype.
palette.add_block('forwardpush',
style='basic-style-1arg',
- label=name,
+ label=args[0],
default=100,
prim_name='forwardpush',
help_string=_('push destination rgb value to heap'))