A Random walk is a series of steps in random directions from a starting point. Random walks can be used to simulate motion of particles in fluids, wanderings of animals, eye movements, escaping prisoners of war, and many other things.
For this lab we will simulate random walks starting from (0, 0) where each step is 0.05 units long. Each walk will end when it is first more than 0.4 units from the starting point.
The positions can be represented by Vector objects. Vector has methods that will produce a random vector of a given length, add two vectors together, and determine a vector's length (the distance from the end to (0, 0)). See the documentation for more details.
When drawing the lines, you will have to convert from position values that whose coordinates range from -0.5 to 0.5 to pixel coordinates that range from -200 to 200. You can do so by multiplying by 400 (DEFAULT_SIZE).
For debugging, you may wish to use System.out.println statements to display the current position during the walk and the number of steps after the walk. Beware that if you write an ininite loop you will not see anything on the screen.
You can also keep track of the color of the shortest walk and the color of the longest walk. Initialize those to null where you initialized the accumulators. After each walk, if you see that the last walk was the shortest (or longest) walk, then update the color of the shortest walk so far (or the color of the longest walk so far). Use drawString to display these values in the lower left corner of the applet.
How would you test to make sure there is no bias in the random steps generated? Think about how you would expect the exit points to be distributed if the walks were uniformly random.
Suppose we wanted to highlight the shortest walk and the longest walk to make them easier to see. We could not highlight them as we draw the walk, because as we are drawing a walk we don't know if it is going to end up the longest or shortest walk. What would you need to know in order to draw the highlighted paths at the end of init? Do we have a type that can store all of that information?