I'm trying to generate a Mandelbrot Set image, but the image takes ages. The code is annoyingly slow, so If you can help me speed it up, that would be very helpful. thanks. Note that code compiles and runs from my IDE. I am new to multiprocessing, so please dumb it down a bit for me.
def daemon_summoner(r):
'''allows code to be restarted with different file if crash during super high res generation'''
t = Thread(target=process_job(r))
t.start()
def process_job(r):
"""creates a slice of the set"""
img = Image.new('1', size, color) # B&W image
print(int(r + 2*resolution100+1), 'of', int(resolution100 *3))
r = r * 100
for rval in range(100):
for i in range(-resolution, resolution, 1):
if abrot(((r + rval) / resolution), (i / resolution * 1j)):
try:
img.putpixel((rval, i + resolution,), 0)
except:
print(r, rval, i + resolution)
img.save(('z_images/' + str(resolution) + '/' + str(int(r/100)+int(resolution*.02)) + '.png'))
def abrot(x, y):
"""tests a point"""
c = (x + y)
z = 0 + 0j
for _ in range(5):
z = z * z + c
if abs(real(z*z+c))>=2and abs(imag(z*z+c))>=2:
return False
for _ in range(int(resolution / 10)):
if real(z + 0.0001) > float(real(z*z+c)) > real(z - 0.0001):
return True
z = z * z + c
if abs(real(z)) >= 2:
return False
return True
Mandelbrot迭代z * z + c
可能需要数十亿次操作才能生成单个图像,因此加快速度的第一步是删除iterate_once
函数并在线完成工作。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.