spacepaste

  1.  
  2. #!/usr/bin/env python3
  3. #./mandelbrot 1 0.747030114917 -0.09923298762 1200 38
  4. #./mandelbrot `python3 -c 'print(2**38)'` 0.747030114917 -0.09923298762 1200 38
  5. #./mandelbrot `python -c 'print(2**42)'` 1.84992346501385 0.0000000001117 800 42
  6. from os import system
  7. from sys import argv
  8. from math import ceil
  9. from time import sleep
  10. from shutil import get_terminal_size
  11. Scale = 0.35
  12. X = -0.4
  13. Y = 0.0
  14. Max = 70
  15. Maxdepth = 0
  16. try:
  17. Scale = float(argv[1])
  18. X = -1.0*float(argv[2])
  19. Y = -1.0*float(argv[3])
  20. Max = int(argv[4])
  21. Maxdepth = int(argv[5])
  22. except:
  23. pass
  24. R = 4
  25. ScaleX = 1 / Scale
  26. ScaleY = 0.7 * ScaleX
  27. Maxdepth_n = 2**Maxdepth
  28. def color(iters):
  29. c = ceil( iters / (Max/7) )
  30. return str(c)
  31. def iterate(zx=0, zy=0, cx=0, cy=0):
  32. znx = 0
  33. zny = 0
  34. znx = zx*zx - zy*zy + cx
  35. zny = 2*zx*zy + cy
  36. return [znx, zny]
  37. def plot(cx, cy):
  38. zx = 0
  39. zy = 0
  40. iters = 0
  41. while zx*zx + zy*zy <= R and iters < Max:
  42. zx, zy = iterate(zx, zy, cx, cy)
  43. iters += 1
  44. if iters < Max:
  45. c = color(iters)
  46. #print('[1;3'+c+'m'+c+'', end='')
  47. return '[1;3'+c+'m'+c
  48. else:
  49. return '-'
  50. system('clear')
  51. print('')
  52. loop_cnt = 0
  53. while Scale <= Maxdepth_n or not Maxdepth:
  54. print('')
  55. width,height = get_terminal_size()
  56. width -= 5
  57. height -= 6
  58. #height = width/3.3
  59. print('Scale: '+str(Scale)+' - Loop: '+str(loop_cnt)+' ')
  60. y = ScaleY/2 + Y
  61. while y > ScaleY/-2 + Y:
  62. x = ScaleX/-2 + X
  63. minval = 1.0
  64. while x < ScaleX/2 + X:
  65. print(plot(x, y), end='')
  66. x += ScaleX / width
  67. print('')
  68. y -= ScaleY / height
  69. loop_cnt += 1
  70. Scale *= 2
  71. ScaleX = 1 / Scale
  72. ScaleY = 0.7 * ScaleX
  73. # Max = 100 + 1100*(loop_cnt/38)
  74. print('Max: '+str(Max))
  75. if not Maxdepth:
  76. break
  77.