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 = 16 16h = 8 17buf = bytearray(w * h // 2) 18fbuf = framebuf.FrameBuffer(buf, w, h, framebuf.GS4_HMSB) 19 20# fill 21fbuf.fill(0x0F) 22printbuf() 23fbuf.fill(0xA0) 24printbuf() 25 26# put pixel 27fbuf.pixel(0, 0, 0x01) 28printbuf() 29fbuf.pixel(w - 1, 0, 0x02) 30printbuf() 31fbuf.pixel(w - 1, h - 1, 0x03) 32printbuf() 33fbuf.pixel(0, h - 1, 0x04) 34printbuf() 35 36# get pixel 37print(fbuf.pixel(0, 0), fbuf.pixel(w - 1, 0), fbuf.pixel(w - 1, h - 1), fbuf.pixel(0, h - 1)) 38print(fbuf.pixel(1, 0), fbuf.pixel(w - 2, 0), fbuf.pixel(w - 2, h - 1), fbuf.pixel(1, h - 1)) 39 40# fill rect 41fbuf.fill_rect(0, 0, w, h, 0x0F) 42printbuf() 43fbuf.fill_rect(0, 0, w, h, 0xF0) 44fbuf.fill_rect(1, 0, w // 2 + 1, 1, 0xF1) 45printbuf() 46fbuf.fill_rect(1, 0, w // 2 + 1, 1, 0x10) 47fbuf.fill_rect(1, 0, w // 2, 1, 0xF1) 48printbuf() 49fbuf.fill_rect(1, 0, w // 2, 1, 0x10) 50fbuf.fill_rect(0, h - 4, w // 2 + 1, 4, 0xAF) 51printbuf() 52fbuf.fill_rect(0, h - 4, w // 2 + 1, 4, 0xB0) 53fbuf.fill_rect(0, h - 4, w // 2, 4, 0xAF) 54printbuf() 55fbuf.fill_rect(0, h - 4, w // 2, 4, 0xB0) 56