Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- import numpy
- x = 0.
- y = 0.
- visited = set()
- xa = []
- ya = []
- leaver = True
- while leaver == True:
- visited.add((x,y))
- check = True
- while check == True:
- f = numpy.random.rand()
- #temporary storage values for coords
- a = x
- b = y
- #pick the direction based on the seed
- if f >= 0.75:
- a += 1
- if f >= 0.50 and f < 0.75:
- a += -1
- if f >= 0.25 and f < 0.50:
- b += 1
- if f < 0.25:
- b += -1
- print 'f: ',f
- print 'a: ',a
- print 'b: ',b
- raw_input()
- #check to make sure you haven't been there before
- check = (a, b) in visited
- x += a
- y += b
- xa.append(x)
- ya.append(y)
- print 'Moved to (',x,',',y,')'
- if numpy.abs(x) > 10: #stops at ten units out
- leaver = False
- plt.plot(xa,ya)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement