Das ist das ganze Programm:
Code: Select all
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()
Code: Select all
while str(zofn)[1] != "n" and count > (5*zoom):

Der Satz wurde mit den Standardeinstellungen gerendert.
Mit cmath (importiert als cmaths, weil ich Brite bin) funktionierte die while-Schleife folgendermaßen:
Code: Select all
while not cmath.isinf(zofn) and count > (5*zoom)

Der Satz wird erneut mit den Standardeinstellungen gerendert, mit der geänderten while-Schleife.
Diese schwarzen Linien könnten nur dann angezeigt werden, wenn cmaths.isinf() davon ausgeht, dass diese Punkte nicht divergieren, was scheiße ist, weil es hässlich und ungenau ist, aber es ist eine so umfangreiche Optimierung, dass ich sie nicht einfach aufgeben kann Konzept. Gibt es eine Möglichkeit, diese Zeilen zu entfernen oder meinen Code auf andere Weise so zu optimieren, dass ich cmaths.isinf() nicht verwenden muss?
Mobile version