First Laboratory: Expressions, Statements, and Interactions
Etch-a-sketch is designed to teach students about expressions and statements
in an interactive environment where behavior is not 100% deterministic.
Students write "recipes" for the movement behavior of a dot in a window.
When the dot moves, it leaves a line from the start point to the end point.
Running the Program
There are several ways to run the code in class. You should choose the one
that your students are ready for. They are presented in an order that
represents an increasing usage of the command line utilities and options.
1. a) Click Here
(requires Java WebStart). If you want to put a link on your course
web site, you may use a link like this (subject to our terms of use
like all materials on the site):
<a href="http://www.cs101.org/psets/etchasketch/demo/etchasketch.jnlp">Click Here</a>
2. a) java -jar etchasketch.jar
b) File > Expand Classpath > (choose jar/dir of package of student code.)
c) File > Load Behavior > (enter fully qualified Class name for student code)
3. a) java -cp etchasketch.jar etchasketch.EtchControl
b) File > Expand Classpath > (choose jar/dir of package of student code.)
c) File > Load Behavior > (enter fully qualified Class name for student code)
4. a) jar -xvf nodenet.jar
b) java etchasketch.EtchControl
c) File > Expand Classpath > (choose jar/dir of package of student code.)
d) File > Load Behavior > (enter fully qualified Class name for student code)
Usage Notes
- Recipes are esentially method bodies for a method with a double return
value. This means every recipe must have a return statement of type
double.
- Recipes must be compiled before they will do anything (recipe menu).
You can tell if a recipe has been compiled since it was last edited by
looking at the message below and to the right of the recipe
entry area.
- Students may reasign which axis the recipe relates to and this will be
shown by the color of the tab and the text below and to the right
of the recipe entry area this is done using the Recipe menu.
- Recipies are executed iteratively, and so only the new position of the
drawing dot needs to be returned. Several variables are available
for use in recipies. The most useful of these is
pos
which holds the current position of dot along the currently assigned
axis. For a full list see the help menu.
- The center of the screen is 0,0. 0,0 is NOT the upper left (standard GUI)
or lower left corner (cartesian quadrant I).
- Simple recipies don't need anything beyond the application provided
variables such as
pos
. More complex paths may require
saved state between iterations. The students may declare fields in which
to save state by clicking on the "Add Fields" button and entering
standard variable declarations in the text box that appears.
- Fields do NOT disappear whe the field text area is closed by clicking
on the button again. You must erase them and re-compile.
- Errors in student code are output to the error console which may be
opend from the Drawing menu.
- The default mode of the program is to interpret the return value of
recipes as a position, but this may be changed to Velocity or
Acceleration by changing the advanced options (from the Drawing menu).
Other advanced options are fairly self explanitory.
- Some students find it useful to compare two or more recipes side by
side without clicking between tabs. This can be accomplished by
selecting any recipe and selecting Standalone View from the Recipe menu.
This view is exactly the same recipe as show on the tab in the main
window. You will notice that text typed in one, appears in the other so
there is no possible confusion about which copy is actually being used.
They are just independant views of the same recipe object.
- Saving Recipies is buggy. Specifically, it is currently done via
Object serialization, and any time the class serial ID changes all
old save files cease to work. This will be fixed in the future, but
This means you should not currently rely on saving behavior,
particularly if you run the program using Java WebStart.
WebStart will automatically grab a newer version if it exists on the
server when you start it. The advantage is you get bugfixes
immediately, and don't have to deal with download and command
lines. The down side is that you have no control over when the
files become useless. This is bug 117 When
this bug is fixed this problem should disappear.
- This application contains a copy of a third-party tool called BeanShell for compiling code at
run-time.
- Etch-a-Sketch now handles infinite loops in student code by stopping
execution of a recipe if it doesn't return within several seconds.
Virtually no correct student code should ever hold onto the thread of
execution for over a second even on the slowest machines.
Screen Shots
Here are two typical recipes. The first is shown in the main control panel, and
the second is shown in a standalone recipe window.
The drawing produced by compiling and executing these two recipes is
shown below.
This page is a part of