Last active
March 29, 2022 17:36
-
-
Save zoeleu/438d42ad45bc772d576c8231f68730e5 to your computer and use it in GitHub Desktop.
mandelbrot-fb.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import * | |
from kadinsky import set_pixel, color | |
def mandelbrot(N_iteration): | |
for x in range(320): | |
framebuffer = [] | |
for y in range(222): | |
# Compute the mandelbrot sequence for the point c = (c_r, c_i) with start value z = (z_r, z_i) | |
z = complex(0,0) | |
# Rescale to fit the drawing screen 320x222 | |
c = complex(3.5*x/319-2.5, -2.5*y/221+1.25) | |
i = 0 | |
while (i < N_iteration) and abs(z) < 2: | |
i = i + 1 | |
z = z*z+c | |
# Choose the color of the dot from the Mandelbrot sequence | |
rgb = int(255*i/N_iteration) | |
col = kandinsky.color(int(rgb),int(rgb*0.75),int(rgb*0.25)) | |
# Draw a pixel colored in 'col' at position (x,y) | |
framebuffer.append((x,y,col)) | |
# set_pixel(x,y,col) | |
for i in framebuffer: | |
set_pixel(i[0],i[1],i[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment