importkandinskyWIDTH,HEIGHT=320,222C=complex(-0.8,0.156)# paramètre de Julia (change pour d'autres formes)
MAX_ITER=50# nombre max d'itérations
ESCAPE_RADIUS=4.0# seuil de divergence
defjulia(z):"""Retourne le nombre d'itérations avant divergence."""i=0whilei<MAX_ITERand(z.real*z.real+z.imag*z.imag)<=ESCAPE_RADIUS:z=z*z+Ci+=1returnidefiter_to_color(i):"""Convertit une itération en couleur RGB."""ifi>=MAX_ITER:return (0,0,0)# noir dans l'ensemble
t=i/MAX_ITERr=int(255*t)g=int(128*(1-t))b=int(255*(1-t))return (r,g,b)defpixel_to_complex(px,py):"""Convertit un pixel écran en coordonnée complexe (ajustée au ratio)."""zx=3.0*(px/WIDTH)-1.5# intervalle [-1.5, +1.5]
zy=2.0*(py/HEIGHT)-1.0# intervalle [-1.0, +1.0]
returncomplex(zx,-zy)# inversion verticale
defmain():foryinrange(HEIGHT):forxinrange(WIDTH):z=pixel_to_complex(x,y)i=julia(z)kandinsky.set_pixel(x,y,iter_to_color(i))main()
During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:
Ensure the proper functioning of the site (essential cookies); and
Track your browsing to send you personalized communications if you have created a professional account on the site and can be contacted (audience measurement cookies).
With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.