Bonjour à tous,

alors voilà, je travaille avec python 2.7 win32 et j'aurais voulu réussir à mettre en couleur la fractale de Mandelbrot sur Tkinter, pour cela il faudrait que je puisse récupérer la valeur d'itération de h à laquelle ma boucle for s'arrête (je m'excuse pour les indentations, le copier coller ne les a pas conservées):

from Tkinter import *
from random import randrange

def mandel2(c):
z=0
for h in range(0,50):
z = z**2 + c
if abs(z) > 2:
break
if abs(z) >= 2:
return False
else:
return True

root = Tk()
w = Canvas(root, width=600, height=600, background='white' )
w.pack()

for hx in range(0,600,50):
w.create_line(0,hx,600,hx,fill="blue")

for hy in range(0,600,50):
w.create_line(hy,0,hy,600,fill="blue")


print ("Initializing...")

for x in range(0,600):
real = x / 200.0 -2
for y in range(0,600):
img = y / 200.0 -1.5
c = complex(real, img)
if mandel2(c):
w.create_line(x,600-y,x+1,601-y,fill="black")
w.pack()

print ("Complete!")

root.mainloop()

J'aurais voulu utiliser ceci pour mettre en couleur en fonction de la valeur de h:

pal = ['purple', 'red', 'yellow', 'blue', 'green', 'maroon', 'pink', 'orange']
d = randrange(8)
couleur = pal[d]

Auriez vous des propositions ?

Merci d'avance,

Onurbi