1try:
2    import framebuf
3except ImportError:
4    print("SKIP")
5    raise SystemExit
6
7
8def printbuf():
9    print("--8<--")
10    for y in range(h):
11        print(buf[y * w * 2 : (y + 1) * w * 2])
12    print("-->8--")
13
14
15w = 4
16h = 5
17buf = bytearray(w * h * 2)
18fbuf = framebuf.FrameBuffer(buf, w, h, framebuf.RGB565)
19
20# fill
21fbuf.fill(0xFFFF)
22printbuf()
23fbuf.fill(0x0000)
24printbuf()
25
26# put pixel
27fbuf.pixel(0, 0, 0xEEEE)
28fbuf.pixel(3, 0, 0xEE00)
29fbuf.pixel(0, 4, 0x00EE)
30fbuf.pixel(3, 4, 0x0EE0)
31printbuf()
32
33# get pixel
34print(fbuf.pixel(0, 4), fbuf.pixel(1, 1))
35
36# scroll
37fbuf.fill(0x0000)
38fbuf.pixel(2, 2, 0xFFFF)
39printbuf()
40fbuf.scroll(0, 1)
41printbuf()
42fbuf.scroll(1, 0)
43printbuf()
44fbuf.scroll(-1, -2)
45printbuf()
46
47w2 = 2
48h2 = 3
49buf2 = bytearray(w2 * h2 * 2)
50fbuf2 = framebuf.FrameBuffer(buf2, w2, h2, framebuf.RGB565)
51
52fbuf2.fill(0x0000)
53fbuf2.pixel(0, 0, 0x0EE0)
54fbuf2.pixel(0, 2, 0xEE00)
55fbuf2.pixel(1, 0, 0x00EE)
56fbuf2.pixel(1, 2, 0xE00E)
57fbuf.fill(0xFFFF)
58fbuf.blit(fbuf2, 3, 3, 0x0000)
59fbuf.blit(fbuf2, -1, -1, 0x0000)
60fbuf.blit(fbuf2, 16, 16, 0x0000)
61printbuf()
62