2016-09-04 02:40:40 -04:00
|
|
|
try:
|
|
|
|
import framebuf
|
|
|
|
except ImportError:
|
|
|
|
print("SKIP")
|
|
|
|
import sys
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
w = 5
|
|
|
|
h = 16
|
|
|
|
buf = bytearray(w * h // 8)
|
2016-08-28 11:44:36 -04:00
|
|
|
fbuf = framebuf.FrameBuffer(buf, w, h, framebuf.MVLSB)
|
2016-09-04 02:40:40 -04:00
|
|
|
|
2016-12-07 23:17:47 -05:00
|
|
|
# access as buffer
|
|
|
|
print(memoryview(fbuf)[0])
|
|
|
|
|
2016-09-04 02:40:40 -04:00
|
|
|
# fill
|
|
|
|
fbuf.fill(1)
|
|
|
|
print(buf)
|
|
|
|
fbuf.fill(0)
|
|
|
|
print(buf)
|
|
|
|
|
|
|
|
# put pixel
|
|
|
|
fbuf.pixel(0, 0, 1)
|
|
|
|
fbuf.pixel(4, 0, 1)
|
|
|
|
fbuf.pixel(0, 15, 1)
|
|
|
|
fbuf.pixel(4, 15, 1)
|
|
|
|
print(buf)
|
|
|
|
|
2016-10-26 06:36:06 -04:00
|
|
|
# clear pixel
|
|
|
|
fbuf.pixel(4, 15, 0)
|
|
|
|
print(buf)
|
|
|
|
|
2016-09-04 02:40:40 -04:00
|
|
|
# get pixel
|
|
|
|
print(fbuf.pixel(0, 0), fbuf.pixel(1, 1))
|
|
|
|
|
2016-12-04 19:55:43 -05:00
|
|
|
# hline
|
|
|
|
fbuf.fill(0)
|
|
|
|
fbuf.hline(0, 1, w, 1)
|
|
|
|
print('hline', buf)
|
|
|
|
|
|
|
|
# vline
|
|
|
|
fbuf.fill(0)
|
|
|
|
fbuf.vline(1, 0, h, 1)
|
|
|
|
print('vline', buf)
|
|
|
|
|
|
|
|
# rect
|
|
|
|
fbuf.fill(0)
|
|
|
|
fbuf.rect(1, 1, 3, 3, 1)
|
|
|
|
print('rect', buf)
|
|
|
|
|
2016-12-12 23:47:58 -05:00
|
|
|
#fill rect
|
|
|
|
fbuf.fill(0)
|
2017-01-19 07:37:44 -05:00
|
|
|
fbuf.fill_rect(0, 0, 0, 3, 1) # zero width, no-operation
|
2016-12-12 23:47:58 -05:00
|
|
|
fbuf.fill_rect(1, 1, 3, 3, 1)
|
|
|
|
print('fill_rect', buf)
|
|
|
|
|
2016-12-04 19:55:43 -05:00
|
|
|
# line
|
|
|
|
fbuf.fill(0)
|
|
|
|
fbuf.line(1, 1, 3, 3, 1)
|
|
|
|
print('line', buf)
|
|
|
|
|
2016-12-12 23:47:58 -05:00
|
|
|
# line steep negative gradient
|
|
|
|
fbuf.fill(0)
|
|
|
|
fbuf.line(3, 3, 2, 1, 1)
|
|
|
|
print('line', buf)
|
|
|
|
|
2016-09-04 02:40:40 -04:00
|
|
|
# scroll
|
|
|
|
fbuf.fill(0)
|
|
|
|
fbuf.pixel(2, 7, 1)
|
|
|
|
fbuf.scroll(0, 1)
|
|
|
|
print(buf)
|
|
|
|
fbuf.scroll(0, -2)
|
|
|
|
print(buf)
|
2016-09-04 22:08:25 -04:00
|
|
|
fbuf.scroll(1, 0)
|
|
|
|
print(buf)
|
|
|
|
fbuf.scroll(-1, 0)
|
|
|
|
print(buf)
|
|
|
|
fbuf.scroll(2, 2)
|
|
|
|
print(buf)
|
2016-10-26 06:36:06 -04:00
|
|
|
|
|
|
|
# print text
|
|
|
|
fbuf.fill(0)
|
|
|
|
fbuf.text("hello", 0, 0, 1)
|
|
|
|
print(buf)
|
|
|
|
fbuf.text("hello", 0, 0, 0) # clear
|
|
|
|
print(buf)
|
|
|
|
|
|
|
|
# char out of font range set to chr(127)
|
|
|
|
fbuf.text(str(chr(31)), 0, 0)
|
|
|
|
print(buf)
|
2016-11-30 23:51:16 -05:00
|
|
|
|
2017-01-25 07:23:50 -05:00
|
|
|
# test invalid constructor, and stride argument
|
2016-12-12 23:47:58 -05:00
|
|
|
try:
|
2017-01-25 07:23:50 -05:00
|
|
|
fbuf = framebuf.FrameBuffer(buf, w, h, -1, w)
|
2016-12-12 23:47:58 -05:00
|
|
|
except ValueError:
|
2017-01-25 07:23:50 -05:00
|
|
|
print("ValueError")
|
2016-12-12 23:47:58 -05:00
|
|
|
|
2016-11-30 23:51:16 -05:00
|
|
|
# test legacy constructor
|
|
|
|
fbuf = framebuf.FrameBuffer1(buf, w, h)
|
|
|
|
fbuf = framebuf.FrameBuffer1(buf, w, h, w)
|