Pi with Sugar and turtles as a learning tool

Laying the Foundations

As an example of how to use the Raspberry Pi and Sugar in a classroom context, imagine you are teaching a group of 8- to 10-year-olds how to draw a house on their computer screen using turtle graphics (see the "Turtle Graphics" box). This activity might seem ridiculously easy to complete, but the process by which you will lead a group of young students with zero knowledge of programming to creating a script that will do the job is anything but simple.

Turtle Graphics

Turtle graphics is a learning tool comprising a robot and a controlling computer. Originally, a robot turtle was set on the floor and directed to move according to instructions typed on the computer. The instructions manipulated the direction the turtle faced and the number of steps the robot advanced. Eventually, the turtle moved from the physical world to the computer screen, where simple instructions could be combined to create complex images through the manipulation of three aspects of the turtle (now, the cursor): location, direction, and a pen with attributes (up, down, color, etc.).

Logo is an early turtle graphics language. A dialect of Lisp, Logo was developed in the 1960s as a tool for self-directed learning. The modular language allows new concepts (e.g., flowers, house) to be created from existing "primitives" and defined modules (e.g., square, triangle, swirl, spiral). Many versions of logo exist, including compiled, parallel, and massively parallel versions.

Scratch, which is included in most Rasp Pi distros, is a version of logo released in 2004 that uses on-screen interlocking "blocks" to help with the logical development of a program. Logo and its derivatives are modular, extensible, interactive, and flexible, encouraging experimentation and problem solving. (rls)

Each house must have at least a square front wall, two windows with four panes each, a rectangular door, and a triangular roof. As mentioned previously, this task is good for students in the 8- to 10-year age bracket; the younger students will find this activity quite difficult, will need more hand-holding, and will have to take more things as an article of faith (something most kids this age are fine with). The 10-year-olds will still find the activity challenging enough to make it engaging. As a warm-up, you can ask your students to draw their ideal house on a piece of paper with colored pencils or crayons. Then, put up a picture of your own "ideal house" on the board, which is the house I described above (Figure 3).

Figure 3: Your "ideal house," which students have to draw using Turtle Blocks.

Tip: Breaking Scripts Apart

When you string several blocks together, you can move them around (and out of the way) by clicking, holding, and dragging on the topmost block. You break off pieces of script from the bottom up and from right to left. So, if you wanted to extract a certain block from the middle of a script, you would click, hold, and drag on the block you wanted to extract. This action will break of all the blocks from that block downwards. Next, you click, hold, and drag on the block immediately below it to break off the rest of the blocks you don't need. You can then drag them back to the original script, leaving the block you needed to decouple on its own in the workspace.

To get students started, have them click on the tortoise icon on the home screen to open TurtleArt. Along the top of the screen is a menubar with different icons. Although these should be self-explanatory (the scissors are for cutting, copying, and pasting; the eye lets you adjust the display area; etc.), mousing over an icon will bring up a text hint and more options that can be accessed with that choice. By the way, this behavior is a common feature in Sugar, along with mouse-sensitive corners (see "Navigating Sugar" for a more in-depth explanation of this feature).

Navigating Sugar

Apart from the menus that are visible in each screen, more options are hidden away around the edges of the screen. If you take the cursor to any corner, a black border appears with several other icons (Figure 4).

In the top left-hand corner, for example, are four circles. The leftmost, with many dots, represents the Neighborhood (i.e., the community of other Sugar installations on nearby networks). The next circle, with just three dots, represents Groups; you can organize your students in groups to carry out and share tasks with this option. The circle with the single dot in the center always takes you back to the home screen, and the circle with a rectangle takes you to a list of activities. The notebook icon opens the Journal.

Toward the top of the right edge is the user symbol, which allows you to shut down, log out, or adjust the settings. Whatever you copy to the clipboard appears along the left edge, and at the bottom, on the right, you can adjust the volume and network setting, if available.

Figure 4: Moving the cursor to a corner reveals more options.

For the time being, though, you are interested in the next toolbar down, which holds the blocks with which you can build your scripts. The blocks are grouped into what are called palettes (Figure 5), and exploration is the key here.

Figure 5: The TurtleArt blocks are organized in "palettes."

At this point, you should let your students play for a while so they learn their way around. You can always get back to a clean slate with the turtle in the center of the screen by dragging out and double-clicking on the clean block in the Turtle commands palette.

Once students have the basic hang of things, you can gradually get to the job of drawing a house by setting tasks that incrementally grow the students knowledge.

One way would be to set the following tasks:

  1. Draw a vertical straight line (a "wall" – introduces the forward block).
  2. Draw a horizontal straight line (the "floor" – introduces the right and/or left blocks).
  3. Draw two unconnected parallel "walls" (introduces pen up and pen down blocks).
  4. Draw a straight angle in one go (introduces combining commands to make scripts).
  5. Draw a square (introduces loops via the repeat block).
  6. Draw 40 squares, one inside the other; the first must measure 400, the second 390, the third 380, and so on, as shown in Figure 6 (introduces the concept of nested loops and variables – known as boxes in TurtleArt parlance).
Figure 6: Nested loops.

Now your students have the knowledge they need to draw the house. One way to start is with a "main" routine in which you can set the size you want for the house and then call the subroutine house, which does all the work:

The house routine then makes sure the pen is down, sets the color, and creates a new box (which makes things simpler down the line):

The front routine draws the front wall,

which in turns calls the square routine. This is a separate routine, because it will be used a lot.

To draw the door, you first have to move the turtle along the baseline of the front wall and then draw a square one third the size of the wall.

Next, you can run the windows routine, which first moves the turtle up the front wall and slightly to the right, as shown in the following:

Then, call the window subroutine. This subroutine draws four small squares around the turtle, offset 90 degrees from each other.

The window subroutine then moves the turtle to the left and draws another window.

Finally, roof moves the turtle to the upper left-hand corner of the wall and draws a triangle on top of the house.

This is just one way of completing the task. Any other solution your students come up with should be considered correct as long as it gets the job done, but you should help them improve their solutions if they are too long or confusing.

As a follow-up, younger students can print and color their pictures and work on their own designs. More advanced students should try to program their own "ideal house" from their hand-drawn pictures or add more details to the base house drawing, like a chimney and smoke or maybe a garden with some trees.

Conclusion

Consider for a moment what students this age can learn from this exercise. They will learn about angles and how to carry out arithmetic operations with symbols, and they will have to exert logic and learn how to break problems down into smaller parts to solve them (the top-down approach mentioned earlier). If you put them in pairs or groups of three – something I wholeheartedly recommend – they will learn how to cooperate with one another and learn from their peers. The usefulness of tasks like these cannot be stressed enough.

The Raspberry Pi was originally designed for education and, although the seminal educational environment working correctly on the Pi is a bit hit and miss, Sugar just seems the right fit for the Raspberry Pi. The solid educational criteria that went into the design of Sugar matches the intent of the Pi's original creators perfectly. Even teachers on tight budgets can take advantage of the perfectly good hardware and the first class educational software the Raspberry Pi provides.

In future articles, I'll explore more uses of the Raspberry Pi as an educational tool and look at more practical ways it can be used in your classroom.

Infos

  1. Sugar Labs: http://sugarlabs.org/
  2. Sugar activities: http://activities.sugarlabs.org

Buy this article as PDF

Express-Checkout as PDF

Pages: 6

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content