Changes

Jump to navigation Jump to search
125 bytes added ,  17:09, 26 February 2010
Line 541: Line 541:  
The following feature is only available in versions 44+ of Turtle Art.
 
The following feature is only available in versions 44+ of Turtle Art.
   −
=== myblock.py ===
      
And a block that can be programmed by the Pippy interface:
 
And a block that can be programmed by the Pippy interface:
Line 554: Line 553:     
Examples:
 
Examples:
 +
def myblock(lc, x):
 +
    ###########################################################################
 +
    #
 +
    # 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
 +
 +
[[Image:TA-dotted-line.png]]
 +
 +
You can pass a list of up to three arguments to tamyblock.py as in this example that converts the input to an rgb value.
    
  def myblock(lc, x):
 
  def myblock(lc, x):
Line 580: Line 606:  
     return
 
     return
   −
def myblock(lc, x):
+
[[Image:TA-rgb.png]]
    ###########################################################################
  −
    #
  −
    # 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
     −
[[Image:TA-dotted-line.png]]
      
  def myblock(lc, x):
 
  def myblock(lc, x):

Navigation menu