BFOIT - Introduction to Computer Programming

New TG Features - BFOIT Saturday - December 13, 2008

Version .0.9.30 of TG has new features that make it easier to use and enhancements that allow you to put together applications that look a lot better, have more powerful interaction with users, and can be deployed in web pages.

Procedure Invocations Before Their Definitions

Every flavor of Logo except for versions of jLogo prior to v.0.9.30 allowed you to write a procedure that referenced a yet-to-be-written procedure. The new version of jLogo defers compilation of user-defined procedures until when they are about to be executed for the first time - at the last possible instant. This means you can put procedures in the Editor (in files you save to long term storage) in any order.

Figure 1

Figure 1 shows a couple of procedures in the Editor of the previous version of TG and the new version of TG. As you can see, the new version handles post-definition of the procedure zzy. It is invoked in the procedure xyzzy, before it is defined.

jLogo in a Webpage

In all of the ItP lessons, when I wanted to show a working version of the program we were writing, I had to write the program twice. For the web page, I wrote an applet version of the program in Java. But for the lesson, we wrote the program in jLogo. In the back of my mind, I had the idea that since TG is an applet and it can run jLogo programs, why not add functionality for TG to load a specified file into the Editor when it starts up...

This is exactly what I have done in version .0.9.30 of TG.

To take advantage of this feature, you need to write a bit of HTML code, specifically, an APPLET tag. Figure 2 shows an example of the APPLET tag from a web page I wrote to startup my Sudoku tool which I've only written in jLogo.

Figure 2

Here are a few links to web pages that I've added to the Applets Appendix of ItP section of BFOIT.org.

Click on one of the links and look at the HTML source code for the page with your browser's "View source" option. In the new Google Chrome browser, it's in the "Developer" sub-menu of the page pull-down menu. In Firefox, use the "Page Source" option of the "View" pull-down menu.

Background and Turtle Images

Now, here's the sizzle...

You now have the ability to put a picture in the background of the graphics canvas of TG. And... you now have the ability to change a turtle's image to a picture.

Figure 3 shows TG with one of my favorite artists in the background and with a picture of a bat as the turtle.

Figure 3

Table 1 summarizes the two new commands.

Name Input(s) Description Example
 LOADPICTURE 
 LOADPICT
 word Load the .BMP picture specified by word into the background of TG's graphics canvas.  LOADPICT  "natalie
 LOADSHAPE  word  number  Load the .BMP picture named word into TG's turtle shapes; the picture is given the identifier number. Number must be in the range of 16 through 31. The SETSHAPE command can then be used to set the turtle's image to the picture.  LOADSHAPE  "bat 16 
Table 1

Now, combining the TG APPLET with these two commands, here is a link to a jLogo program which sets the background color to black, loads a picture of Earth into the background, and then creates a bunch of turtles - giving each its own image.

http://www.bfoit.org/itp/ImagesDemo.html

READWORD and READLIST

There are lots of programs that will need to get input from a user, stuff that just can't be embedded in the program source.

An example is a program that encrypts and decrypts text like we examined in our Introduction to Cryptography lesson. Figure 4 shows an example run of the program and part of the program which uses READWORD.

Figure 4

			
Name Description Example
 READLIST  Get a line of text from the CommandCenter and output it as a sentence  MAKE "sent READLIST
 READWORD  Get a line of text from the CommandCenter and output it as a word  MAKE "yesNo READWORD
Table 2

RUN

Name Input(s) Description Example
 RUN   sentence Execute the sentence as if it were typed into the CommandCenter - instructions as data.  RUN  :cmdsSent
Table 3

Internet links to checkout:

  1. http://www.martinreddy.net/gfx/2d-hi.html
    (The Graphics File Formats Page, 2D Bitmap Specifications)
  2. http://docs.oracle.com/javase/tutorial/deployment/applet/html.html
    (Sun Microsystems' documentation of the APPLET tag)

Further Reading:

  1. In Code, Sarah Flannery with David Flannery, Workman Publishing, 2001.

Public Domain Mark
This work (BFOIT: Introduction to Computer Programming, by Guy M. Haas),
identified by Berkeley Foundation for Opportunities in IT (BFOIT),
is free of known copyright restrictions.