Saturday, February 07, 2009

Using the insert function block in TurtleArt

TurtleArt in its current experimental fork, TurtleArtPortfolio , allows students to use Python functions in a special block.
The intention of this feature is to provide a "higher ceiling" for open ended learning. I decided to try this function to do an analogue clock , a task that I had previously done in Gamemaker.

It turned out to be a trivial exercise for some learning goals because trigonometric functions of sin() cos() and pi() were not required, I could just use set heading.

I required the time library functions from Python which had not been imported, this meant I had to hack the TurtleArt source file adding the line
from time import localtime
(as of V13, this is not required)

The programmming in TA visual blocks is shown in the picture below.

The code to the right draws 12 hour marks from radius 200 to 220. The code to the left draws the second, minute and hour hand. The heading for the second hand, for example, is calculated as
seth=localtime().tm_sec * 6
for the minute and hour use tm_min and tm_hour respectively.

The output:
What I found hard
The time function that I required was not already imported into TurtleArt. Can you use the insert function block to import a library? Apparently not because import does not return a value. Could the block be reprogrammed so that it does not need to return a value? If all likely imports are already programmed in, does TurtleArt become clumsy, slow to load and a memory hog? If students can't access all functions they don't have a sufficiently high ceiling.

Finding the correct syntax for time . There was a lack of documentation or programming examples that explained that localtime() returns a structure with elements including tm_hour. Also the correct syntax depending on whether one function or the whole library was imported. Specifically, it was hard to discover that the correct syntax could be:

import time

from time import localtime
and that the two lines of code above could be combined, eliminating the need for the temporary structure variable mytime
from time import localtime
It either needs better documentation, more code examples or both.

What didn't work

The block has insufficient space to type in long expressions, you can't edit an expression, you have to retype it, when dragging a block containing a long expression, it leaves bits of text on the canvas.

Labels: , , ,


Blogger Bill Kerr said...

Great work Tony (and Walter)!

How did you solve the problems that you found hard?

Saturday, February 07, 2009 10:47:00 PM  
Blogger Walter Bender said...

Adding the time module as part of the standard set of imports to is a great suggestion. Any other libraries I should include?

Sunday, February 08, 2009 12:40:00 AM  
Blogger Unknown said...

"How did you solve the problems that you found hard?"
Importing the time library was not really so hard because of the time I had already put in hacking python source. It would have been a big roadblock otherwise.
Getting the right syntax for localtime() was hard. I Googled a lot of pages and tried bits of code in Pippy. I drew on prior knowledge about libraries, structures and functions.

"Any other libraries I should include?" I dont know enough Python, try to do stuff and see what roadblocks I run into

Sunday, February 08, 2009 7:07:00 AM  
Blogger Caber said...

Don't want to spoil anybody's party, but I think that we can't import every useful library. It doesn't scale, some other way must be found. TA is increasingly slow, and we can't afford to make it slower...

Great post and example.

Tuesday, February 10, 2009 8:24:00 PM  
Blogger Unknown said...

sounds reasonable, what's needed then is a TA block that you can use to import a library.

Tuesday, February 10, 2009 9:34:00 PM  

Post a Comment

<< Home