- Commanding a Turtle
- Adding New Commands
- Iteration & Animation
- Hierarchical Structure
- Procedure Inputs
- Operators & Expressions
- Defining Operators
- Words & Sentences
- User Interface Events
- What If? (Predicates)
- Local Variables
- Global Variables
- Word/Sentence Iteration
- Mastermind Project
- Turtles As Actors
- File Input/Output
- A Java Program
- What's a Class?
- Extending Existing Classes
- Turtle Graphics
- Control Flow
- User Interface Events
- What Is TG?
- TG Directives
- jLogo Primitives
- TG Editor
- Java Tables
- Example Programs
- *** New ***:
- December 13, 2008
- March 7, 2009
- January 6, 2012
- March 15, 2013
- January 20, 2014
- February 13, 2014
- July 29, 2014
- January 18, 2016
- January 29, 2016
- August 19, 2016
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 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.
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.
Table 1 summarizes the two new commands.
|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|
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.
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.
|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|
|RUN||sentence||Execute the sentence as if it were typed into the CommandCenter - instructions as data.||RUN :cmdsSent|
Internet links to checkout:
(The Graphics File Formats Page, 2D Bitmap Specifications)
(Sun Microsystems' documentation of the APPLET tag)