Introduction to Programming
Symbolic Values
and the
Graphical User Interface
In this lesson, you will learn
There is a lot more to programming than generating numbers, displaying them, and drawing stuff. Logo (TurtleTalk is a subset of Logo) is a symbolic programming language. Symbolic programming was created to help get computers to do human-like things - the study of artificial intelligence.
So, how do you represent a word in the TurtleTalk language?
When the TurtleTalk interpreter sees a double-quote character, i.e. ("), the collection process for characters composing the word starts. All characters until a space character or the end of the line are considered part of the word. "Word is a word made up of the characters: W, o, r, and d. Note that the double-quote introduces the word - it is not part of the word.
You can display words just like numbers. We'll do this in a moment; but, first let's learn a bit about mouse input.
Graphical User Interfaces and the Mouse
A Graphical User Interface, most commonly called a GUI, (pronounced
goo-ee) is one way of interacting with the software that is in a
computer, or a computer-based device. On a deskside computer
system, the GUI provides ways for you to launch programs, display
stuff, etc... all with a mouse pointing device. When you are
interacting with programs, you use a pointing device (a mouse) to
open up menus, choose items from the menus, check boxes that
determine how your program should do things. It's a
point-and-click environment.
The mouse, or "X-Y position indicator for a display system" which is what it was originally called, was invented by Doug Engelbart at SRI (Stanford Research Institute) in the early 1960's. He and others also invented the concept of breaking the graphical display into pieces called "windows" which held seperate information.
By the 1970's, this magical kingdom in the world of computer science appeared, commonly called PARC. Actually it is Xerox PARC (PARC stands for Palo Alto Research Center) and it still exists. A group of scientists there built what was to be the future of computing: networks of "personal" computers were prototyped. Much of what we see as computing environments these days was invented at PARC.&nbp; The researchers all had computers (Altos) with pixel graphics displays and a pointing device (a mouse). They were connected by a high-speed network (Ethernet). and used this environment to do all their work.
The thing they did that's most applicable to what I'm talking about here was Alan Kay's Dynabook. Alan and a few other researchers including Adele Goldberg and Dan Ingalls, built a graphically-oriented system for working with Personal Dynamic Media, a programming environment they called Smalltalk. As I can fit concepts from their system into our learning, I will.
We've been doing lot's of graphical output, let's get some input via your computer systems' GUI.
Tracking the Mouse - the mouseclick Procedure
The mouse is simply a pointing device which sends the computer motion
information. In the most common form of the mouse, a little ball
spins when you move it across a surface. As you move the mouse
from side to side and forward or backward, it sends this information
to the computer. The GUI uses this information to keep track of
a point where the mouse is. The GUI gives you feedback in the
form of a graphical icon, usually an arrow. The mouse also has
buttons on it. It tells the computer when you press a button
down and when you release it. When this down-up motion is done
quickly it's called a mouse-click. GUIs communicate that a
mouse-click has occured to programs in the form of an event.
The TurtleGraphics applet and TG application receive an event when a mouse button is clicked. If you enter a procedure with the name mouseclick it will be performed when a mouse click occurs. Here is the TurtleGraphics applet. Type in the following definition of mouseclick.
to mouseclick
println "mouseclicked
end
| TurtleGraphics Applet |
Click the mouse in the graphics area and watch what happens...
Enter the operators mousex and mousey. They output the coordinates where the mouse was when it was clicked.
Exercises:
One more new primitive command: label. The label command draws text in the graphics area. The text is displayed where the turtle is. You use label similarly to how you can use the print command. The difference is where the characters are displayed.
Either go back up to the TG applet or use a small popup TG applet and play with the label a bit...
Exercise: LabelPoints
Once you've mastered all of these new commands, write a program that
labels each point in the graphics area that you click on.
Figure 8.1 shows an example screen after six mouse clicks.
|
| Figure 8.1 |
You learned about the label command which draws textual representations of things into the graphics area of the TurtleGraphics applet and TG application.
And, finally, you learned how to do something when the mouse is clicked in the graphics area - by writing a procedure that you name "mouseclick." You learned about the mousex and mousey operators which output the X and Y values for the coordinate where the mouse was when it was clicked.
| New TurtleTalk Procedures Used In This Lesson | |||
| Name | Input | Description | Example |
| LABEL | thing | Draw the textual representation of thing in the graphics area, at the turtle's current position. | LABEL "Hi! |
| MOUSECLICK | When a mouse-click is received by the TurtleTalk system, it performs a user-defined procedure with the name MOUSECLICK, if one has been defined. | ||
| MOUSEX | Outputs the X-coordinate where the mouse was when it was last clicked. | ||
| MOUSEY | Outputs the Y-coordinate where the mouse was when it was last clicked. | ||