Ich möchte zuerst vorweg nehmen, dass ich ein totaler Neuling in Sachen Programmierung bin. Dies ist mein erstes Projekt und darum bitte ich um Antworten, welche einigermassen verständlich für Anfänger sind. Ich wusste nicht in welches Unterforum der Beitrag gehört, darum habe ich es einfach mal im Allgemein Threat gepostet.
Mein Ziel war es, das Newton-Fraktal für die Funktion f(z)=z^3-1 darstellen zu lassen, also ein Bild zu erstellen. Dies hat eigentlich gut geklappt, jedoch gibt es noch ein Problem. Zuerst der Code:
Code: Alles auswählen
from PIL import Image
imgx = 700
imgy = 700
xmin = -2
xmax = 2
ymin = -2
ymax = 2
image = Image.new("RGB", (imgx, imgy))
for x in range(imgx):
zx = x*(xmax-xmin)/imgx+xmin
for y in range(imgy):
zy = ymax - y*(ymax-ymin)/imgy
z = complex(zx,zy)
x1 = (imgx+xmin)/(xmax-xmin)
y1 = (imgy*ymax)/(ymax-ymin)
zx1 = x1*(xmax-xmin)/imgx+xmin
zy1 = ymax - y1*(ymax-ymin)/imgy
x2 = ((-0.5)*(imgx+xmin))/(xmax-xmin)
y2 = (imgy*(ymax-(3**(.5)/2)))/(ymax-ymin)
zx2 = x2*(xmax-xmin)/imgx+xmin
zy2 = ymax-y2*(ymax-ymin)/imgy
x3 = ((-0.5)*(imgx+xmin))/(xmax-xmin)
y3 = (imgy*(ymax+(3**(.5)/2)))/(ymax-ymin)
zx3 = x3*(xmax-xmin)/imgx+xmin
zy3 = ymax - y3*(ymax-ymin)/imgy
z1 = complex(zx1,zy1)
z2 = complex(zx2,zy2)
z3 = complex(zx3,zy3)
n = 1
dist1 = 5
dist2 = 5
dist3 = 5
if abs(z) != 0:
while n <= 1000 and dist1 >= 2.5 and dist2 >= 2.5 and dist3 >= 2.5:
z = z - (z**3 - 1)/(3 * z**2)
n = n + 1
dist1 = abs(z-z1)
dist2 = abs(z-z2)
dist3 = abs(z-z3)
if dist1 <= 2.5:
image.putpixel((x,y), (0,255,0))
if dist2 <= 2.5:
image.putpixel((x,y), (0,0,255))
if dist3 <= 2.5:
image.putpixel((x,y), (255,0,0))
image.save("Newton_Fraktal.png","PNG")
Shidox
P.S. : Der Code ist mit Python 3.3 geschrieben
