Commit baf09a0a authored by Jerico Moeyersons 's avatar Jerico Moeyersons 🏘
Browse files

Finished kernel worker

parent 829b4b79
......@@ -69,7 +69,7 @@ class Kernel(object):
return "Another job is running, please try again later..."
def __set_next_worker(self):
if self.next_worker == self.worker:
if self.next_worker == self.workers:
self.next_worker = 1
else:
self.next_worker += 1
__author__ = 'Jerico Moeyersons'
import sys
import math
import numpy as np
from PIL import Image
from itertools import repeat
from multiprocessing import Pool
MAX_ITER = 80
class Kernel(object):
def start(self, i_height=1000, proc=2, name='test'):
height = int(i_height)
width = int(height * 1.5)
print(f'Attempting to image of size {width} x {height}. This will result in a {width*height} pixel image!')
max_iterations = 255
result = np.zeros((height, width))
processes = int(proc)
po = Pool(processes)
iy = np.arange(height)
test = po.map_async(self.get_col, zip(iy, repeat(width), repeat(height), repeat(max_iterations) )).get()
for i in np.arange(height):
result[i,:] = test[i]
mandelbrot = result
mandelbrot = np.clip(mandelbrot*255, 0, 255).astype(np.uint8)
mandelbrot = Image.fromarray(mandelbrot)
mandelbrot.save(f'{name}.png')
print(f'saved {name}.png')
def get_col(self, args):
iy, width, height, max_iterations = args
result = np.zeros((1, width))
for ix in np.arange(width):
x0 = ix*3.0/width - 2.0
y0 = iy*2.0/height - 1.0
x = 0.0
y = 0.0
for iteration in range(max_iterations):
x_new = x*x - y*y + x0
y = 2*x*y + y0
x = x_new
if x*x + y*y > 4.0:
# color using pretty linear gradient
color = 1.0 - 0.02*(iteration - np.log2(np.log2(x*x + y*y)))
break
else:
# failed, set color to black
color = 0.0
result[0, ix] = color
return result
if __name__ == "__main__":
test = Kernel()
test.start()
\ No newline at end of file
numpy
pillows
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment