mandelbrot.py

Created by parisseb

Created on February 04, 2020

458 Bytes

Version de la fractale de Mandelbrot plus rapide en exploitant la symétrie. Fonctionne dans KhiCAS et dans MicroPython (mais avec Delta, version de Epsilon modifiée et qui accepte les codes couleurs en un seul entier).


from math import *
from kandinsky import *
# Mandelbrot fractal
# Nmax: precision, s: scale
def mandelbrot(Nmax=10,s=2,X=160,Y=111):
  w=2.7/X
  h=-1.87/Y
  Y=Y-1
  for y in range(ceil(Y/2)+1):
    c = complex(-2.1,h*y+0.935)
    for x in range(X):
      z = 0
      for j in range(Nmax):
        z=z**2+c
        if abs(z)>2:
          break
      fill_rect(s*x,s*y,s,s,126*j+2079)
      fill_rect(s*x,s*(Y-y),s,s,126*j+2079)
      c = c+w

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

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.