PixelWalker

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

The RandomWalker class

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

The PixelWalker class

In Processing, the main program (in this case PixelWalker) has to 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 RandomWalker) that should be included in the project.

The main program in the sketch will include the void setup() method to establish a graphical window and 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.

Extensions

  1. Using separate colors to identify the origin, the walker's current position, and the walker's path as it moves.
  2. 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.
  3. 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.
  4. 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 expands the walker's displayed size and position on the screen.