Brownian motion is the random movement of a particle in its environment. For example, a dust particle suspended in a liquid exhibits Brownian motion. In this homework assignment you are going to simulate Brownian motion drawing a pixel on the screen and randomly moving in one of eight possible directions; to the left, right, up, down, or on the diagonals of upper right, lower right, upper left, or lower left.
Have your simulation repeatedly make a random move a large number of times (for example 100,000) inside a 600-by-600 picture. When the simulation is finished write some fancy text in the center of the picture indicating it is done. If a particle tries to move off of the edge of a picture you should also quit the simulation and indicate that it has finished. See what my version looks like by double clicking on the file
T:\Harcourt\Fall2008\CS140\HW5\run.bat
break
statement to quit the loop if the particle runs off the
edge of the picture.
drawOval
method with a width and height of one pixel to
draw a single pixel on the screen.
getHeight()
and getWidth()
functions
on a picture object to determine the size of your picture.
setFont
method. Here's an example of how to use it.
g.setColor(Color.blue); g.setFont(new Font("Curlz MT", Font.BOLD, 40)); g.drawString("Done",x,y);
HW5
and save it in a file on the T: drive
HW5.java
. Watch out for the case, "HW" is capitalized.