Skip to content

Instantly share code, notes, and snippets.

@IlievskiV
Created September 6, 2020 10:08
Show Gist options
  • Save IlievskiV/8addbb6ccb9aa3515ad599466b3b914a to your computer and use it in GitHub Desktop.
Save IlievskiV/8addbb6ccb9aa3515ad599466b3b914a to your computer and use it in GitHub Desktop.
Implementation of the Julia Set convergence
def julia_quadratic(zx, zy, cx, cy, threshold):
"""Calculates whether the number z[0] = zx + i*zy with a constant c = x + i*y
belongs to the Julia set. In order to belong, the sequence
z[i + 1] = z[i]**2 + c, must not diverge after 'threshold' number of steps.
The sequence diverges if the absolute value of z[i+1] is greater than 4.
:param float zx: the x component of z[0]
:param float zy: the y component of z[0]
:param float cx: the x component of the constant c
:param float cy: the y component of the constant c
:param int threshold: the number of iterations to considered it converged
"""
# initial conditions
z = complex(zx, zy)
c = complex(cx, cy)
for i in range(threshold):
z = z**2 + c
if abs(z) > 4.: # it diverged
return i
return threshold - 1 # it didn't diverge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment