NotePublic/Ecology/01Studio/pyBoard/Demo/01Studio中文显示例程/tftch.py

53 lines
1.8 KiB
Python
Raw Normal View History

# 定义常用颜色
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
def printChinese(text, x, y, display, dict, size, color=(0,0,0), backcolor=(255,255,255)):
xs = x
# 定义字体颜色,RGB888转RGB565
fc = ((color[0]>>3)<<11) + ((color[1]>>2)<<5) + (color[2]>>3) # 字体
bc = ((backcolor[0]>>3)<<11) + ((backcolor[1]>>2)<<5) + (backcolor[2]>>3) # 字体背景颜色
#
for i in range(0, len(text)):
#
ch_buf =dict[text[i]] # 汉子对应码表
rgb_buf = []
#
for i in range(0, len(ch_buf)):
for j in range(0, 8):
if (ch_buf[i] << j) & 0x80 == 0x00:
rgb_buf.append(bc & 0xff)
rgb_buf.append(bc >> 8)
else:
rgb_buf.append(fc & 0xff)
rgb_buf.append(fc >> 8)
# if
# for
# for
display.write_buf(bytearray(rgb_buf),xs,y,size,size)
#
xs += size
# for
# printChinese
if __name__ == '__main__':
import fonts
from tftlcd import LCD24
########################
# 构建1.5寸LCD对象并初始化
########################
d = LCD24(portrait=1) #默认方向竖屏
#
#填充白色
d.fill(BLACK)
#
printChinese('零一科技', 0, 0, d, fonts.hanzi_16x16_dict, 24, color=RED, backcolor=BLACK)
printChinese('零一科技', 0, 16, d, fonts.hanzi_24x24_dict, 24, color=GREEN, backcolor=BLACK)
printChinese('零一科技', 0, 40, d, fonts.hanzi_32x32_dict, 32, color=BLUE, backcolor=BLACK)
printChinese('零一科技', 0, 72, d, fonts.hanzi_40x40_dict, 40, color=WHITE, backcolor=BLACK)
printChinese('零一科技', 0, 120, d, fonts.hanzi_48x48_dict, 48, color=WHITE, backcolor=BLACK)
# __main__