You are on page 1of 2

Etch-a-Sketch

Now that you have practiced calling methods and some basics with Java it is time to try it on your own.
Try to work through your own issues any time you run into something that does not work. Try to limit
the amount of ( ), { }, and ; mistakes you make. Think about what command would be needed to
complete each task and what the syntax is before you begin typing.

You are to recreate an Etch-a-Sketch styled program in Greenfoot. If you have never seen an Etch-a-
Sketch it is a childrens drawing toy that uses aluminum powder under a glass surface which can be
moved around. It contains two knobs: one that moves the stylus horizontally and one that moves it
vertically. The stylus scrapes the aluminum around to draw lines ultimately allowing the user to create
pictures. When the Etch-a-Sketch is shaken upside down it erases all the drawn lines.

Create a modified etch-a-sketch program. The program will do the general idea of the original Etch-A-
Sketch, using the up/down/left/right keys to draw in those directions. Using the space bar will erase all
of the drawings. However, we will also add in a silly eraser that moves around randomly destroying your
picture and we will add in a silly feature that allows the lines that were drawn to move forward if you
desire. The following characteristics identify what should occur in your program:

1) The "Arrow." The arrow image for the Arrow was chosen just to see the direction
the drawing was made in, normally in an actual Etch-A-Sketch these would just be
single dots on the screen that have been drawn. When the spacebar is pressed, the
Arrows should disappear. When the w variable is pressed, the Arrows should move
forward (just for fun). If they happen to hit the edge of the screen, they should
disappear.

2) The "Stylus" which represents the coordinate that the current etch-a-sketch is at
for drawing. It should use the Dot image. Each act, when the up/down/left/right is
pressed the Stylus will move very slightly in the corresponding direction. The Stylus
will always be leaving behind an "Arrow" as it moves. The Arrow should be told to be
rotated to face the same direction the Stylus just moved in. For instance, if the Stylus
was just moved to the right then the Arrow should face east, if it was moved up then
the Arrow should face north.

3) Add two Knob classes, a LeftKnob and a RightKnob. The LeftKnob should rotate
5 degrees left when the left arrow is pressed, and 5 degrees to the right when the
right arrow is pressed. The RightKnob should do similar, except it rotates left 5
degrees when the up arrow is pressed, and rotates right 5 degrees when the down
arrow is pressed. These are just for a visual effect.

4) The "Eraser". Choose any small image to represent an eraser. This annoying
object will spin around in small circles, moving always 1 pixel forward and turning
randomly from 1-10 degrees. It has a 1% chance of teleporting somewhere else on
the screen. The "Eraser" is not part of the original Etch-a-Sketch, but an annoying
programmer decided to add it in as an Easter Egg. Every "Arrow" it runs into should
be deleted.

5) Modify the Stylus to no longer allow it to go outside of the Etch-A-Sketch pictures


boundary (it shouldnt walk into the red ever). To do this, only allow it to move left if
the x coordinate isnt too small, or right if the x coordinate isnt too big, and the same
idea for up and down.
6) Modify the Arrow class to make them automatically be removed from the screen
when they are outside the Etch-A-Sketch boundaries. Any X coordinate < 125 or >
775 is bad, and any Y coordinate < 125 or > 600 is bad. You can ask this using one if
statement by combining multiple conditions together using either && for and or ||
for or. Example: if ( isTouching( Worm.class ) && Greenfoot.isKeyDown(space ) )
Example: if ( getRotation() > 90 || getRotation() < 180 )

*) Challenge: When the Stylus is on the edge of the screen and is told to walk off the
screen it should teleport to the other side of the screen instead. For instance, if the
Stylus is at coordinate ( 0, 30 ) and the screen is 500 wide and 300 tall, it would be on
the left side of the screen. If it was told to move left, it would teleport to the opposite
side of the screen ( 499, 30 ). The symbols that can be used to compare numbers in
an if statement are: <, >, <=, >=, ==

You might also like