PixelWalker

Using the Processing platform, write a sketch PixelWalker that uses a Walker() class.

The Walker class

The Walker class tracks the x- and y-coordinates of a walker. It includes

The PixelWalker class

In Processing, the main program (in this case PixelWalker) must be the first, leftmost tab in the project. Click on the down-arrow in the tab to create a new tab for additional classes (in this case Walker) that should be included in the project.

The main program in the sketch will include:

  1. instance variables declared
  2. a void setup() method to initialize the instance variables, and establish a graphical window
  3. a void draw() loop that displays the walker and its position as long as the walker hasn't returned to the middle of the screen.

Also, print in the console the coordinates of the walker and the number of steps it has taken.

Note that you don't need to set up an explicit loop for this project: the draw() method itself repeats.

If you have a screen with a large number of pixels, they will be very small. Your PixelWalker may not be easily visible unless you magnify your screen. See Extension #1 below for some ideas on how to improve this.

Extensions

  1. For a walker with small dimensions or a walker that is changing its location by only 1 pixel each move, the movement of the walker may be difficult to see. Include a constant SCALE in the program that allows the walker's motion to be reasonably displayed on the screen.

  1. The walker may wander off-screen, in which case its movements are no longer visible. As the walker moves, check its position, and if it wanders off the horizontal or vertical borders of the window, have it wrap around to the other side of the screen.
  2. Using separate colors to identify the origin, the walker's current position, and the walker's path as it moves.
  3. Processing allows for the display of text on screen. Print the walker's number of steps taken on screen at the bottom, and update that value as the walker moves.