framebuf1.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. try:
  2. import framebuf
  3. except ImportError:
  4. print("SKIP")
  5. raise SystemExit
  6. w = 5
  7. h = 16
  8. size = w * h // 8
  9. buf = bytearray(size)
  10. maps = {framebuf.MONO_VLSB : 'MONO_VLSB',
  11. framebuf.MONO_HLSB : 'MONO_HLSB',
  12. framebuf.MONO_HMSB : 'MONO_HMSB'}
  13. for mapping in maps.keys():
  14. for x in range(size):
  15. buf[x] = 0
  16. fbuf = framebuf.FrameBuffer(buf, w, h, mapping)
  17. print(maps[mapping])
  18. # access as buffer
  19. print(memoryview(fbuf)[0])
  20. # fill
  21. fbuf.fill(1)
  22. print(buf)
  23. fbuf.fill(0)
  24. print(buf)
  25. # put pixel
  26. fbuf.pixel(0, 0, 1)
  27. fbuf.pixel(4, 0, 1)
  28. fbuf.pixel(0, 15, 1)
  29. fbuf.pixel(4, 15, 1)
  30. print(buf)
  31. # clear pixel
  32. fbuf.pixel(4, 15, 0)
  33. print(buf)
  34. # get pixel
  35. print(fbuf.pixel(0, 0), fbuf.pixel(1, 1))
  36. # hline
  37. fbuf.fill(0)
  38. fbuf.hline(0, 1, w, 1)
  39. print('hline', buf)
  40. # vline
  41. fbuf.fill(0)
  42. fbuf.vline(1, 0, h, 1)
  43. print('vline', buf)
  44. # rect
  45. fbuf.fill(0)
  46. fbuf.rect(1, 1, 3, 3, 1)
  47. print('rect', buf)
  48. #fill rect
  49. fbuf.fill(0)
  50. fbuf.fill_rect(0, 0, 0, 3, 1) # zero width, no-operation
  51. fbuf.fill_rect(1, 1, 3, 3, 1)
  52. print('fill_rect', buf)
  53. # line
  54. fbuf.fill(0)
  55. fbuf.line(1, 1, 3, 3, 1)
  56. print('line', buf)
  57. # line steep negative gradient
  58. fbuf.fill(0)
  59. fbuf.line(3, 3, 2, 1, 1)
  60. print('line', buf)
  61. # scroll
  62. fbuf.fill(0)
  63. fbuf.pixel(2, 7, 1)
  64. fbuf.scroll(0, 1)
  65. print(buf)
  66. fbuf.scroll(0, -2)
  67. print(buf)
  68. fbuf.scroll(1, 0)
  69. print(buf)
  70. fbuf.scroll(-1, 0)
  71. print(buf)
  72. fbuf.scroll(2, 2)
  73. print(buf)
  74. # print text
  75. fbuf.fill(0)
  76. fbuf.text("hello", 0, 0, 1)
  77. print(buf)
  78. fbuf.text("hello", 0, 0, 0) # clear
  79. print(buf)
  80. # char out of font range set to chr(127)
  81. fbuf.text(str(chr(31)), 0, 0)
  82. print(buf)
  83. print()
  84. # test invalid constructor, and stride argument
  85. try:
  86. fbuf = framebuf.FrameBuffer(buf, w, h, -1, w)
  87. except ValueError:
  88. print("ValueError")
  89. # test legacy constructor
  90. fbuf = framebuf.FrameBuffer1(buf, w, h)
  91. fbuf = framebuf.FrameBuffer1(buf, w, h, w)
  92. print(framebuf.MVLSB == framebuf.MONO_VLSB)