framebuf4.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 = 16
  12. h = 8
  13. buf = bytearray(w * h // 2)
  14. fbuf = framebuf.FrameBuffer(buf, w, h, framebuf.GS4_HMSB)
  15. # fill
  16. fbuf.fill(0x0f)
  17. printbuf()
  18. fbuf.fill(0xa0)
  19. printbuf()
  20. # put pixel
  21. fbuf.pixel(0, 0, 0x01)
  22. printbuf()
  23. fbuf.pixel(w-1, 0, 0x02)
  24. printbuf()
  25. fbuf.pixel(w-1, h-1, 0x03)
  26. printbuf()
  27. fbuf.pixel(0, h-1, 0x04)
  28. printbuf()
  29. # get pixel
  30. print(fbuf.pixel(0, 0), fbuf.pixel(w-1, 0), fbuf.pixel(w-1, h-1), fbuf.pixel(0, h-1))
  31. print(fbuf.pixel(1, 0), fbuf.pixel(w-2, 0), fbuf.pixel(w-2, h-1), fbuf.pixel(1, h-1))
  32. # fill rect
  33. fbuf.fill_rect(0, 0, w, h, 0x0f)
  34. printbuf()
  35. fbuf.fill_rect(0, 0, w, h, 0xf0)
  36. fbuf.fill_rect(1, 0, w//2+1, 1, 0xf1)
  37. printbuf()
  38. fbuf.fill_rect(1, 0, w//2+1, 1, 0x10)
  39. fbuf.fill_rect(1, 0, w//2, 1, 0xf1)
  40. printbuf()
  41. fbuf.fill_rect(1, 0, w//2, 1, 0x10)
  42. fbuf.fill_rect(0, h-4, w//2+1, 4, 0xaf)
  43. printbuf()
  44. fbuf.fill_rect(0, h-4, w//2+1, 4, 0xb0)
  45. fbuf.fill_rect(0, h-4, w//2, 4, 0xaf)
  46. printbuf()
  47. fbuf.fill_rect(0, h-4, w//2, 4, 0xb0)