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        for x in range(w):
12            print("%u" % ((buf[(x + y * w) // 4] >> ((x & 3) << 1)) & 3), end="")
13        print()
14    print("-->8--")
15
16
17w = 8
18h = 5
19buf = bytearray(w * h // 4)
20fbuf = framebuf.FrameBuffer(buf, w, h, framebuf.GS2_HMSB)
21
22# fill
23fbuf.fill(3)
24printbuf()
25fbuf.fill(0)
26printbuf()
27
28# put pixel
29fbuf.pixel(0, 0, 1)
30fbuf.pixel(3, 0, 2)
31fbuf.pixel(0, 4, 3)
32fbuf.pixel(3, 4, 2)
33printbuf()
34
35# get pixel
36print(fbuf.pixel(0, 4), fbuf.pixel(1, 1))
37
38# scroll
39fbuf.fill(0)
40fbuf.pixel(2, 2, 3)
41printbuf()
42fbuf.scroll(0, 1)
43printbuf()
44fbuf.scroll(1, 0)
45printbuf()
46fbuf.scroll(-1, -2)
47printbuf()
48
49w2 = 2
50h2 = 3
51buf2 = bytearray(w2 * h2 // 4)
52fbuf2 = framebuf.FrameBuffer(buf2, w2, h2, framebuf.GS2_HMSB)
53
54# blit
55fbuf2.fill(0)
56fbuf2.pixel(0, 0, 1)
57fbuf2.pixel(0, 2, 2)
58fbuf2.pixel(1, 0, 1)
59fbuf2.pixel(1, 2, 2)
60fbuf.fill(3)
61fbuf.blit(fbuf2, 3, 3, 0)
62fbuf.blit(fbuf2, -1, -1, 0)
63fbuf.blit(fbuf2, 16, 16, 0)
64printbuf()
65