Toggle Navigation
Hatchery
Eggs
Mandelbrot
__init__.py
Users
Badges
Login
Register
MCH2022 badge?
go to mch2022.badge.team
__init__.py
raw
Content
# Based on http://0pointer.de/blog/projects/mandelbrot.html import display display.drawFill(0xFFFFFF) display.drawText(0,0,"Calculating...",0x000000) display.flush(display.FLAG_LUT_NORMAL) dimensions = (display.width(), display.height()) scale = 1.0/(dimensions[0]/3) center = [2.2, 1.5] # Use this for Mandelbrot set #center = (1.5, 1.5) # Use this for Julia set iterate_max = 20 # Calculate the mandelbrot sequence for the point c with start value z def iterate_mandelbrot(c, z = 0): for n in range(iterate_max + 1): z = z*z +c if abs(z) > 2: return n return None # Draw our image display.drawFill(0xFFFFFF) for y in range(dimensions[1]): for x in range(dimensions[0]): c = complex(x * scale - center[0], y * scale - center[1]) n = iterate_mandelbrot(c) # Use this for Mandelbrot set #n = iterate_mandelbrot(complex(0.3, 0.6), c) # Use this for Julia set if n is None: display.drawPixel(x, y, 0x000000) else: display.drawPixel(x, y, 0xFFFFFF) display.flush(display.FLAG_LUT_NORMAL)