-
- #!/usr/bin/env python3
-
- #./mandelbrot 1 0.747030114917 -0.09923298762 1200 38
- #./mandelbrot `python3 -c 'print(2**38)'` 0.747030114917 -0.09923298762 1200 38
- #./mandelbrot `python -c 'print(2**42)'` 1.84992346501385 0.0000000001117 800 42
-
-
- from os import system
- from sys import argv
- from math import ceil
- from time import sleep
- from shutil import get_terminal_size
-
- Scale = 0.35
- X = -0.4
- Y = 0.0
- Max = 70
- Maxdepth = 0
-
- try:
- Scale = float(argv[1])
- X = -1.0*float(argv[2])
- Y = -1.0*float(argv[3])
-
- Max = int(argv[4])
-
- Maxdepth = int(argv[5])
- except:
- pass
-
- R = 4
- ScaleX = 1 / Scale
- ScaleY = 0.7 * ScaleX
- Maxdepth_n = 2**Maxdepth
-
-
- def color(iters):
- c = ceil( iters / (Max/7) )
- return str(c)
-
- def iterate(zx=0, zy=0, cx=0, cy=0):
- znx = 0
- zny = 0
-
- znx = zx*zx - zy*zy + cx
- zny = 2*zx*zy + cy
-
- return [znx, zny]
-
- def plot(cx, cy):
- zx = 0
- zy = 0
- iters = 0
-
- while zx*zx + zy*zy <= R and iters < Max:
- zx, zy = iterate(zx, zy, cx, cy)
- iters += 1
-
- if iters < Max:
- c = color(iters)
- #print('[1;3'+c+'m'+c+'[0m', end='')
- return '[1;3'+c+'m'+c
- else:
- return '[1;30m-'
-
-
-
- system('clear')
- print('')
-
- loop_cnt = 0
- while Scale <= Maxdepth_n or not Maxdepth:
- print('[0;0H')
-
- width,height = get_terminal_size()
- width -= 5
- height -= 6
- #height = width/3.3
-
- print('[0mScale: '+str(Scale)+' - Loop: '+str(loop_cnt)+' ')
- y = ScaleY/2 + Y
- while y > ScaleY/-2 + Y:
- x = ScaleX/-2 + X
-
- minval = 1.0
- while x < ScaleX/2 + X:
- print(plot(x, y), end='')
- x += ScaleX / width
- print('')
- y -= ScaleY / height
-
- loop_cnt += 1
-
- Scale *= 2
- ScaleX = 1 / Scale
- ScaleY = 0.7 * ScaleX
-
- # Max = 100 + 1100*(loop_cnt/38)
-
- print('[0mMax: '+str(Max))
-
- if not Maxdepth:
- break
-