""" From "A SURVEY OF COMPUTATIONAL PHYSICS", Python eBook Version by RH Landau, MJ Paez, and CC Bordeianu Copyright Princeton University Press, Princeton, 2012; Book Copyright R Landau, Oregon State Unv, MJ Paez, Univ Antioquia, C Bordeianu, Univ Bucharest, 2012. Support by National Science Foundation , Oregon State Univ, Microsoft Corp""" # # Coastline.py from pylab import * import random Minx = 0 # min value x axis Maxx = 200 # max value x axis Miny = 0 # for y axis Maxy = 60 #g = gdisplay(width=500, height=500, title="Coastline", xtitle='x',ytitle='coast',xmin=Minx, xmax=Maxx, #ymin=Miny, ymax=Maxy) #seacoast = gcurve(color=color.yellow) coast = zeros((200)) # array for i in range(0, 5000): # All particles dropped spot = int(200*random.random()) # generate random number if (spot == 0): # Hitting edge counts as filling hole if (coast[spot] < coast[spot + 1]): coast[spot] = coast[spot + 1] else: coast[spot]= coast[spot] + 1 else: if (spot == 199): if (coast[spot] < coast[spot - 1]): coast[spot] = coast[spot - 1] else: coast[spot]=coast[spot] + 1 else: if ((coast[spot] coast[spot + 1]): coast[spot] = coast[spot - 1] else: coast[spot] = coast[spot + 1] else: coast[spot] = coast[spot] + 1 plot(spot,coast[spot],".",markersize = 3,color = "green") show() #for i in range(0,200): # #seacoast.plot(pos=(i,coast[i])) # plot coastline # plot(i,coast[i],"o",markersize = 4,color = "red") # show() # #plot(coast,color="blue")