turtle art vs. python

Talk about how to use and get the most out of Activities for the XO.

turtle art vs. python

Postby manymny » Mon Aug 31, 2009 4:46 pm

turtle art is a really incredible way to introduce yourself to programming. the little boxes that let you plug in values to build a turtle art program are fantastic. it's a little more like "real programming" than some people might realize (for a more extensive language that uses similar boxes, try scratch.)

but what if you wanted to learn a "serious" language like... python? it's not too serious, but you can get real jobs done. before you do real jobs with python, you'll need to learn python. fortunately python and turtle art have a lot in common.

python doesn't have built in turtle art commands. to illustrate how turtle art and python are similar, i'm going to pretend there's a "module" (a group of extra commands) called "art." in reality there is a module very much like turtle art, but my imaginary one is probably closer still. instead of using the command "forward" in turtle art, and putting a number box with 10 next to it, we'll say: art.forward(10) ... special art module commands begin with "art." regular python commands will not.

Code: Select all
import art
# load an imaginary module for commands nearly identical to turtle art.

here is a program in turtle art you may have seen before: http://en.flossmanuals.net/floss/publis ... tch4_1.png i would love to just add the picture here, instead i'm going to link to it out of some politeness to the author rather than copy the image (thus the entire license) here. click on the link, then come back to read the program version.

before we begin imitating that program in python, a couple things. #this is a comment.

comments are anything after the # sign, python ignores them. they're only for humans. also to help the "store in box" commands in turtle art (it uses box1 and box2) we're going to make boxes using real python commands:

Code: Select all
# make a group of three boxes: box[0], box[1], box[2]
# put a zero in each of the three boxes

box[1] is for the "store in box 1" command, it currently contains a zero.

other than that, here is a python program that looks a lot like the turtle art program. if someone wrote a python module called "art" with the proper code, this program could do the same thing it does in turtle art:

Code: Select all
box[1]=0  # store in box1: 0

# a_unique_name should have a unique name
# otherwise the program may not do what you want

# repeat 1300
for a_unique_name in range(1300):
     art.set_color(art.xcor() / 6)

if you can compare this code with the picture on the next page, you see that typing code is a little more trouble than using cartoon boxes, but it's also very similar. how you're expected to type the code depends on the language, we did it in a python way, which is a lot like the turtle art way. one of the most important differences between turtle art and python is that you can have much longer programs, you can write smaller programs and "call" them from a larger program, and you don't have to "fit" it all on the screen, or scroll from side to side like you would have to with a picture, or with turtle art.

now that you see real python code, and depending on what the functions are called (because they shouldn't overlap with existing python commands) you may be able to load the whole art.module like this:

Code: Select all
from art import *

now art.commands are just "commands." this makes it even easier to see what a turtle art program would look like in python:

# make a group of three boxes: box[0], box[1], box[2]
# put a zero in each

box[1]=0 # store in box1: 0

# repeat 1300
for a_unique_name in range(1300):
set_color(xcor() / 6)

that's turtle art vs. python!

if you like turtle art and you think you'd like to learn more about python, try some of the examples in "pippy" (the sugar icon looks like a snake.) most of sugar is written in python, so it's the source when you use the "view source" key..
Posts: 26
Joined: Mon Aug 17, 2009 11:26 am

Return to Activities / Software

Who is online

Users browsing this forum: No registered users and 3 guests