Skip to content

Instantly share code, notes, and snippets.

@boochow
Last active August 18, 2018 09:39
Show Gist options
  • Save boochow/fbed1eb574d0d326fdc1e72729bdb5e1 to your computer and use it in GitHub Desktop.
Save boochow/fbed1eb574d0d326fdc1e72729bdb5e1 to your computer and use it in GitHub Desktop.
import gpu, framebuf
gpu.fb_init(240, 135, screen_w=1920, screen_h=1080)
fb = framebuf.FrameBuffer(gpu.fb_data(), 240, 135, framebuf.RGB565)
fb.fill_rect(0,0,240,135,0)
minX = -2.0
maxX = 1.0
width = 240
height = 135
aspectRatio = 1.0
yScale = (maxX - minX) * (float(height) / width) * aspectRatio
for y in range(height):
for x in range(width):
c = complex(minX + x * (maxX - minX) / width, y * yScale / height - yScale / 2)
z = c
for color in range(512):
if abs(z) > 2:
break
z = z * z + c
color = ~color & 0x1ff
r, g, b = (color & 0x1a) << 7, (color & 0x38) << 3, (color & 0x7) << 2
fb.pixel(x, y, r | g | b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment