-
Notifications
You must be signed in to change notification settings - Fork 2
/
FrameGenerator.py
62 lines (43 loc) · 1.92 KB
/
FrameGenerator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from PIL import Image
from Point import Point
class FrameGenerator:
def __init__(self, root_degree=4, width=720, height=720, x_start=-1, x_end=1, y_start=-1, y_end=1):
self.root_degree = root_degree
self.height = height
self.width = width
self.x_start = x_start
self.x_end = x_end
self.y_start = y_start
self.y_end = y_end
self.x_increment = (x_end - x_start) / width
self.y_increment = (y_end - y_start) / height
self.is_first_iteration = True
self.points_left = []
self.last_image = None
def iterate(self, num_of_iterations=1):
if self.is_first_iteration:
img = Image.new('RGB', (self.width, self.height))
pixels = img.load()
self.is_first_iteration = False
for x_offset in range(self.width):
for y_offset in range(self.height):
coord_x = self.x_start + x_offset * self.x_increment
coord_y = self.y_start + y_offset * self.y_increment
x_n = Point(coord_x + coord_y*1j, self.root_degree)
x_n.iterate(num_of_iterations)
if not x_n.has_converged:
self.points_left.append((x_offset, y_offset, x_n))
pixels[x_offset, y_offset] = x_n.get_color()
self.last_image = img.copy()
return img
else:
img = self.last_image.copy()
pixels = img.load()
for (x_offset, y_offset, x_n) in self.points_left:
x_n.iterate(num_of_iterations)
pixels[x_offset, y_offset] = x_n.get_color()
self.points_left = [(x_offset, y_offset, x_n)
for (x_offset, y_offset, x_n) in self.points_left
if not x_n.has_converged]
self.last_image = img.copy()
return img