Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tamyblock.py
diff options
context:
space:
mode:
authorWalter Bender <walter@sugarlabs.org>2010-03-17 18:39:20 (GMT)
committer Walter Bender <walter@sugarlabs.org>2010-03-17 18:39:20 (GMT)
commit81ba8fd9fa0e2fbbee1ef3534a96104de4cd7079 (patch)
tree500a2837580b12358f79322621acdbd39b8be5e2 /tamyblock.py
parentb4e53af65b5bb6a8ec2e3f6f5e5e424ab2c01ea0 (diff)
parentf1d5ed75c29961a718eb3c59fde1663c184f20cf (diff)
Merge branch 'master' of git://git.sugarlabs.org/turtleart/refactoringv83
Conflicts: NEWS activity/activity.info tagplay.py tawindow.py
Diffstat (limited to 'tamyblock.py')
-rw-r--r--tamyblock.py100
1 files changed, 61 insertions, 39 deletions
diff --git a/tamyblock.py b/tamyblock.py
index dca0bf8..a90995a 100644
--- a/tamyblock.py
+++ b/tamyblock.py
@@ -1,4 +1,4 @@
-#Copyright (c) 2009, Walter Bender
+#Copyright (c) 2009-10, Walter Bender
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
@@ -23,39 +23,65 @@
# palette is selected. Some examples of how to use this block are included
# below. Try uncommenting an example or write your own Python code.
#
-# To uncomment code, remove the #s before python code
+# To uncomment code, remove the '# ' in the Python code. Take care to preserve
+# the proper indentations.
#
-def myblock(lc,x):
+def myblock(lc, x):
###########################################################################
#
- # draw a dotted line of length x
+ # Set rgb color
#
###########################################################################
- try: # make sure x is a number
- x = float(x)
- except:
- return
-
- pen = lc.tw.turtle.pendown # save current turtle pen state
+ # r = int(x[0])
+ # while r < 0:
+ # r += 256
+ # while r > 255:
+ # r -= 256
+ # g = int(x[1])
+ # while g < 0:
+ # g += 256
+ # while g > 255:
+ # g -= 256
+ # b = int(x[0])
+ # while b < 0:
+ # b += 256
+ # while b > 255:
+ # b -= 256
+ # rgb = "#%02x%02x%02x" % (r,g,b)
+ # lc.tw.canvas.fgcolor = lc.tw.canvas.cm.alloc_color(rgb)
+ # return
- dist = 0
- while dist+lc.tw.turtle.pensize < x: # repeat drawing dots
- setpen(lc.tw.turtle, True)
- forward(lc.tw.turtle, 1)
- setpen(lc.tw.turtle, False)
- forward(lc.tw.turtle, (lc.tw.turtle.pensize*2)-1)
- dist += (lc.tw.turtle.pensize*2)
- forward(lc.tw.turtle, x-dist) # make sure we have moved x
-
- setpen(lc.tw.turtle, pen) # restore pen state
+ ###########################################################################
+ #
+ # Draw a dotted line of length x.
+ #
+ ###########################################################################
+ try: # make sure x is a number
+ x = float(x)
+ except ValueError:
+ return
+ if lc.tw.canvas.pendown:
+ dist = 0
+ while dist+lc.tw.canvas.pensize < x: # repeat drawing dots
+ lc.tw.canvas.setpen(True)
+ lc.tw.canvas.forward(1)
+ lc.tw.canvas.setpen(False)
+ lc.tw.canvas.forward((lc.tw.canvas.pensize*2)-1)
+ dist += (lc.tw.canvas.pensize*2)
+ lc.tw.canvas.forward(x-dist) # make sure we have moved exactly x
+ lc.tw.canvas.setpen(True)
+ else:
+ lc.tw.canvas.forward(x)
+ return
###########################################################################
#
- # push an uppercase version of a string onto the heap
+ # Push an uppercase version of a string onto the heap.
+ # Use a 'pop' block to use the new string.
#
###########################################################################
@@ -63,51 +89,47 @@ def myblock(lc,x):
# X = str(x).upper()
# else:
# X = x.upper()
- # push result onto heap (use the pop block to use the new string)
# lc.heap.append(X)
-
+ # return
###########################################################################
#
- # push hours, minutes, seconds onto the heap
- # use three pop blocks to retrieve the values
- # remember: the heap is a FILO (first in, last out)
- # the first value you will pop will be seconds
+ # Push hours, minutes, seconds onto the FILO.
+ # Use three 'pop' blocks to retrieve these values.
+ # Note: because we use a FILO (first in, last out heap),
+ # the first value you will pop will be seconds.
#
###########################################################################
# lc.heap.append(localtime().tm_hour)
# lc.heap.append(localtime().tm_min)
# lc.heap.append(localtime().tm_sec)
-
+ # return
###########################################################################
#
- # add a third dimension (gray) to the color model
- # calculate the value (brightness) of the current color
- # val = 0.3 * lc.tw.rgb[0] + 0.6 * lc.tw.rgb[1] + 0.1 * lc.tw.rgb[2]
- # make sure gray is in range from 0 to 100
+ # Add a third dimension (gray) to the color model.
#
###########################################################################
-
+ # val = 0.3 * lc.tw.rgb[0] + 0.6 * lc.tw.rgb[1] + 0.1 * lc.tw.rgb[2]
# if x != 100:
# x = int(x)%100
- # mix in gray
# r = int((val*(100-x) + lc.tw.rgb[0]*x)/100)
# g = int((val*(100-x) + lc.tw.rgb[1]*x)/100)
# b = int((val*(100-x) + lc.tw.rgb[2]*x)/100)
# reallocate current color
- # lc.tw.fgcolor = lc.tw.cm.alloc_color(r<<8,g<<8,b<<8)
-
+ # rgb = "#%02x%02x%02x" % (r,g,b)
+ # lc.tw.canvas.fgcolor = lc.tw.canvas.cm.alloc_color(rgb)
+ # return
###########################################################################
#
- # save a screen- image in the journal
+ # Save an image named x to the Sugar Journal.
#
###########################################################################
- # lc.tw.activity._do_save_as_image_cb(lc.tw.activity)
+ # lc.tw.save_as_image(str(x))
+ # return
- return