from sympy import isprime import matplotlib.pyplot as plt def isgaussprime(z: complex): a, b = int(z.real), int(z.imag) if a*b != 0: return isprime(a**2 + b**2) else: c = abs(a+b) return isprime(c) and c % 4 == 3 def connect(z1: complex, z2: complex): plt.plot([z1.real, z2.real], [z1.imag, z2.imag], 'b') start = 127 + 130j step = 1 z = start next = None while next != start: next = z + step connect(z, next) if isgaussprime(next): step *= 1j z = next plt.gca().set_aspect("equal") plt.show() start = 3 + 5j step = 1 z = start next = None while next != start: next = z + step connect(z, next) if isgaussprime(next): step *= 1j z = next plt.gca().set_aspect("equal") plt.show()