fork download
  1. import random
  2. from math import *
  3. import matplotlib.pyplot as plt
  4. import numpy as np
  5. import seaborn as sns
  6.  
  7. def marchemassive (r, m) :
  8. x = 0
  9. y = 0
  10. d2 = 0
  11. s = 0
  12. while d2<r*r:
  13. w = random.random()
  14. if w <= 1/3 :
  15. x = x + 1
  16. elif 1/3< w<= 2/3:
  17. x = x - 0.5
  18. y = y + sqrt(3)/2
  19. else:
  20. x = x - 0.5
  21. y = y - sqrt(3)/2
  22. d2 = x*x+y*y
  23. s=s+1
  24. return (x/r , y/r, (1-m**2)**s)
  25.  
  26.  
  27.  
  28. def marchemassiverepete (r ,m, n) :
  29. npx = []
  30. npy = []
  31. npp = []
  32. max=0
  33. for i in range (n) :
  34. x , y , p = marchemassive (r, m)
  35. pos=-1
  36. for i in range (len(npx)) :
  37. if npx[i]==x and npx[i]==y :
  38. pos =i
  39. if pos == -1 :
  40. npx.append (x)
  41. npy.append (y)
  42. npp.append (p)
  43. if max<p :
  44. max = p
  45. else :
  46. npp[i] = npp[i] + p
  47. if npp[i]>max :
  48. max = npp[i]
  49.  
  50. return (npx, npy, [elem/max for elem in npp])
  51.  
  52. r = 100
  53. m = 0.1
  54. n = 100
  55.  
  56. npx, npy, npp = marchemassiverepete (r, m , n)
  57.  
  58. sns.relplot(x=npx,y=npy, alpha= npp, height=10,s=10)
  59.  
  60. plt.show()
Success #stdin #stdout 3.39s 122420KB
stdin
Standard input is empty
stdout
Standard output is empty