При приближении фрактала, он приближается не в центр, а в левый верхний угол
Написал программу, создающую изображение множества Жюлиа, но приближение происходит не в центр, а в левый верхний угол. Вот код:
from PIL import Image
from time import time
import numpy as np
import numba
import cv2
x = 1500
y = x
max_iter = 50
img = Image.new("RGB", (x, y), (0, 0, 0))
zoom = x // 2 + 1
pixels = np.array(img)
c = -0.65j
s = "-"
max_num = 2
texture = Image.open("texture_3.jpg") # тут может быть любая картинка с любым градиентом
texture_size = min(texture.size) - 1
texture_array = np.array(texture)
def edit(c, s):
return c
if s == "-":
return c - 0.002j
return c + 0.002j
@numba.njit(fastmath=True, nogil=True, parallel=True)
def main(pixels: np.array, c: complex, zoom: int):
for y2 in numba.prange(-zoom, zoom):
for x2 in numba.prange(-zoom, zoom):
if x2 + zoom > x - 1:
break
elif y2 + zoom > y - 1:
break
a = x2 / (zoom)
b = y2 / (zoom)
z = complex(a, b)
num_iter = 0
for _ in range(max_iter):
z = z ** 2 + c
if abs(z) > max_num:
break
num_iter += 1
col = int(texture_size * num_iter / max_iter)
pixels[x2 + zoom, y2 + zoom] = texture_array[col, col]
return pixels
while True:
cv2.imshow("", main(pixels, c, zoom))
cv2.waitKey(1)
if c.imag > 2j.imag:
s = "-"
if c.imag < -2j.imag:
s = "+"
c = edit(c, s)
zoom += 1
Помогите с этим разобраться
Источник: Stack Overflow на русском