diff --git a/Ecology/01Studio/pyBoard/Demo/01Studio中文显示例程/main.py b/Ecology/01Studio/pyBoard/Demo/01Studio中文显示例程/main.py deleted file mode 100644 index 0a2cc8e..0000000 --- a/Ecology/01Studio/pyBoard/Demo/01Studio中文显示例程/main.py +++ /dev/null @@ -1,85 +0,0 @@ -''' -实验名称:中文显示 -版本:v1.0 -日期:2022.3 -作者:01Studio -实验平台:编程实现中文显示,本例程使用1.54寸LCD,不同LCD可自行修改。 -''' - -#导入相关模块 -from tftlcd import LCD15 -import time,fonts,gc - -#定义常用颜色 -RED = (255,0,0) -GREEN = (0,255,0) -BLUE = (0,0,255) -BLACK = (0,0,0) -WHITE = (255,255,255) - -######################## -# 构建1.5寸LCD对象并初始化 -######################## -d = LCD15(portrait=1) #默认方向竖屏 - -#填充白色 -d.fill(BLACK) - -#中文显示 -def printChinese(text,x,y,color=(0,0,0),backcolor=(255,255,255),size=1): - - font_size = [0,16,24,32,40,48] #分别对应size=1,2,3,4,5的字体尺寸,0无效。 - - chinese_dict = {} - - #获取对应的字模 - if size==1: - chinese_dict = fonts.hanzi_16x16_dict - - elif size==2: - chinese_dict = fonts.hanzi_24x24_dict - - elif size==3: - chinese_dict = fonts.hanzi_32x32_dict - - elif size==4: - chinese_dict = fonts.hanzi_40x40_dict - - elif size==5: - chinese_dict = fonts.hanzi_48x48_dict - - xs = x - ys = y - - #定义字体颜色,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 =chinese_dict[text[i]] #汉子对应码表 - - rgb_buf = [] - - t1 = font_size[size] // 8 - t2 = font_size[size] % 8 - - 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) - - d.write_buf(bytearray(rgb_buf),xs,y,font_size[size],font_size[size]) - - xs += font_size[size] - -printChinese('零一科技',0,0,color=RED,backcolor=BLACK,size=1) -printChinese('零一科技',0,16,color=GREEN,backcolor=BLACK,size=2) -printChinese('零一科技',0,40,color=BLUE,backcolor=BLACK,size=3) -printChinese('零一科技',0,72,color=WHITE,backcolor=BLACK,size=4) -printChinese('零一科技',0,120,color=WHITE,backcolor=BLACK,size=5) diff --git a/Ecology/01Studio/pyBoard/Demo/01Studio中文显示例程/tftch.py b/Ecology/01Studio/pyBoard/Demo/01Studio中文显示例程/tftch.py new file mode 100644 index 0000000..a7e7870 --- /dev/null +++ b/Ecology/01Studio/pyBoard/Demo/01Studio中文显示例程/tftch.py @@ -0,0 +1,52 @@ +# 定义常用颜色 +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__