framebuf16.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. print(buf[y * w * 2:(y + 1) * w * 2])
  10. print("-->8--")
  11. w = 4
  12. h = 5
  13. buf = bytearray(w * h * 2)
  14. fbuf = framebuf.FrameBuffer(buf, w, h, framebuf.RGB565)
  15. # fill
  16. fbuf.fill(0xffff)
  17. printbuf()
  18. fbuf.fill(0x0000)
  19. printbuf()
  20. # put pixel
  21. fbuf.pixel(0, 0, 0xeeee)
  22. fbuf.pixel(3, 0, 0xee00)
  23. fbuf.pixel(0, 4, 0x00ee)
  24. fbuf.pixel(3, 4, 0x0ee0)
  25. printbuf()
  26. # get pixel
  27. print(fbuf.pixel(0, 4), fbuf.pixel(1, 1))
  28. # scroll
  29. fbuf.fill(0x0000)
  30. fbuf.pixel(2, 2, 0xffff)
  31. printbuf()
  32. fbuf.scroll(0, 1)
  33. printbuf()
  34. fbuf.scroll(1, 0)
  35. printbuf()
  36. fbuf.scroll(-1, -2)
  37. printbuf()
  38. w2 = 2
  39. h2 = 3
  40. buf2 = bytearray(w2 * h2 * 2)
  41. fbuf2 = framebuf.FrameBuffer(buf2, w2, h2, framebuf.RGB565)
  42. fbuf2.fill(0x0000)
  43. fbuf2.pixel(0, 0, 0x0ee0)
  44. fbuf2.pixel(0, 2, 0xee00)
  45. fbuf2.pixel(1, 0, 0x00ee)
  46. fbuf2.pixel(1, 2, 0xe00e)
  47. fbuf.fill(0xffff)
  48. fbuf.blit(fbuf2, 3, 3, 0x0000)
  49. fbuf.blit(fbuf2, -1, -1, 0x0000)
  50. fbuf.blit(fbuf2, 16, 16, 0x0000)
  51. printbuf()