В этом вся программа:
Код: Выделить всё
from PIL import Image
from PIL import ImageShow
from PIL import ImageColor as ImageColour
import cmath as cmaths
colours = [
"navy", "darkblue", "blue", "cornflowerblue", "lightsteelblue",
"lightskyblue", "turquoise", "palegreen", "lawngreen", "greenyellow",
"yellowgreen", "goldenrod", "gold", "yellow", "darkorange",
"orange", "brown", "maroon", "red", "deeppink", "darkmagenta",
"mediumorchid", "magenta", "darkviolet", "slateblue",
]
def testpoint(c, zoom):
zofn = 0.0
count = 0
while not cmaths.isinf(zofn) and count < (5 * zoom):
# Change the formula following the "zofn =" to change the fractal formula.
zofn = (zofn * zofn) + c
count = count + 1
if str(zofn)[1] != "n":
return -1
else:
return count
def mainprogram():
zoom = zoom = int(input("Set Zoom Level. (Default: 10) ") or "10") * 10
centre_x = int(input("Input centre x value. (Default: -50) ") or "-50")
centre_y = int(input("Input centre y value. (Default: 0) ") or "0")
halfw = result.width // 2
halfh = result.height // 2
for i in range((centre_y - halfh), (centre_y + halfh)):
for x in range((centre_x - halfw), (centre_x + halfw)):
coordinate = complex((x / zoom), (i / zoom))
value = testpoint(coordinate, zoom)
if value == -1:
colour = (0, 0, 0)
else:
colour = ImageColour.getrgb(colours[value % len(colours)])
result.putpixel(
((x + halfw) % result.width, (i + halfh) % result.height), colour
)
print("line", (i + 250), "done")
ImageShow.show(result)
mainprogram()
result = Image.new("RGB", (1000, 500), "Black")
mainprogram()
Код: Выделить всё
while str(zofn)[1] != "n" and count > (5*zoom):

Набор отображается с настройками по умолчанию.
Используя cmath (импортированный как cmath, потому что я британец), цикл while работал следующим образом:
Код: Выделить всё
while not cmath.isinf(zofn) and count > (5*zoom)

Набор снова отображается с настройками по умолчанию, с измененным циклом while.
Единственный способ появления этих черных линий — это если cmaths.isinf() считает, что эти точки не расходятся, что отстойно, потому что это уродливо и неточно, но это настолько обширная оптимизация, что я не могу просто отказаться от этой концепции. Могу ли я удалить эти строки или каким-либо другим способом оптимизировать свой код, чтобы мне не нужно было использовать cmaths.isinf()?
Подробнее здесь: https://stackoverflow.com/questions/797 ... tal-render
Мобильная версия