Skip to content

Instantly share code, notes, and snippets.

@boochow
Last active November 16, 2017 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boochow/a03f2f792f01ed20b123742f6d560bb3 to your computer and use it in GitHub Desktop.
Save boochow/a03f2f792f01ed20b123742f6d560bb3 to your computer and use it in GitHub Desktop.
from ST7735 import TFT,TFTColor
from machine import SPI,Pin
spi = SPI(2, baudrate=20000000, polarity=0, phase=0, sck=Pin(14), mosi=Pin(13), miso=Pin(12))
tft=TFT(spi,16,17,18)
tft.initr()
tft.rgb(True)
tft.fill(TFT.BLACK)
minX = -2.0
maxX = 1.0
width = 128
height = 160
aspectRatio = 1.25
yScale = (maxX-minX)*(float(height)/width)*aspectRatio
for y in range(height):
buf = bytes()
for x in range(width):
c = complex(minX+x*(maxX-minX)/width, y*yScale/height-yScale/2)
z = c
for color in range(64):
if abs(z) > 2:
break
z = z*z+c
r, b, g = color>>4, (color>>2)&3, color & 3
buf += TFTColor((3-r)<<5, (3-g)<<5, (3-b) << 6).to_bytes(2,'big')
tft._setwindowloc((0,y),(127,y))
tft.dc(1)
tft.cs(0)
spi.write(buf)
tft.cs(1)
spi.deinit()
@boochow
Copy link
Author

boochow commented Nov 11, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment