framebuf8.py 585 B

1234567891011121314151617181920212223242526272829303132
  1. try:
  2. import framebuf
  3. except ImportError:
  4. print("SKIP")
  5. raise SystemExit
  6. def printbuf():
  7. print("--8<--")
  8. for y in range(h):
  9. for x in range(w):
  10. print('%02x' % buf[(x + y * w)], end='')
  11. print()
  12. print("-->8--")
  13. w = 8
  14. h = 5
  15. buf = bytearray(w * h)
  16. fbuf = framebuf.FrameBuffer(buf, w, h, framebuf.GS8)
  17. # fill
  18. fbuf.fill(0x55)
  19. printbuf()
  20. # put pixel
  21. fbuf.pixel(0, 0, 0x11)
  22. fbuf.pixel(w - 1, 0, 0x22)
  23. fbuf.pixel(0, h - 1, 0x33)
  24. fbuf.pixel(w - 1, h - 1, 0xff)
  25. printbuf()
  26. # get pixel
  27. print(hex(fbuf.pixel(0, h - 1)), hex(fbuf.pixel(1, 1)))