1import framebuf
2
3# 1. allocate an 80 × 30-pixel, 1-bit-depth buffer
4W, H = 80, 30
5buf = bytearray(W * H // 8)
6fb = framebuf.FrameBuffer(buf, W, H, framebuf.MONO_HLSB)
7
8# 2. clear the screen
9fb.fill(0)
10
11# 3. draw a line from the top-left to the bottom-right corner
12fb.line(0, 0, W - 1, H - 1, 1)
13
14# 4. draw a rectangle
15fb.rect(10, 10, 25, 25, 1)
16fb.fill_rect(15, 15, 20, 20, 1)
17
18fb.text("Hi py", 40, 0, 1)
19fb.hline(0, 10, 1, 1)
20
21print(buf)
22
23# display as ASCII art
24for y in range(H):
25 row = ""
26 for x in range(W):
27 row += "+" if fb.pixel(x, y) else " "
28 print(row)