def rect(self, z): screen.drawline(self.x, 100, self.x, 130, 1, 0x000000) self.x += 1 if self.x == 180: self.timer.deinit() text.draw("加载完成", 88, 160, 0xff0000) self.quit_flag = True
def drawLine(self, pos1, pos2, color=0x000000, weight=1): assert self.width >= pos1[0] >= 1 and self.width >= pos2[ 0] >= 1, "X out of border" assert self.height >= pos1[1] >= 1 and self.height >= pos2[ 1] >= 1, "Y out of border" x1, y1 = pos1[0] - 1, pos1[1] - 1 x2, y2 = pos2[0] - 1, pos2[1] - 1 _screen.drawline(x1, y1, x2, y2, weight, color)
def drawInterface(self): #界面初始化 bmp1 = ubitmap.BitmapFromFile("pic/boy") bmp2 = ubitmap.BitmapFromFile("pic/girl") bmp1.draw(20, 200) #显示boy图片 bmp2.draw(140, 200) #显示girl图片 screen.drawline(0, 160, 240, 160, 2, 0xff0000)
def grid(self): x = 20 y = 20 for i in range(11): screen.drawline(x, 20, x, 220, 3, 0x000000) x += 20 for j in range(11): screen.drawline(20, y, 220, y, 3, 0x000000) y += 20
def drawClock(self): screen.clear() # 画表盘 for i in range(60): if i % 5 == 0: # 画时刻度 长线 screen.drawline(self.cirStart[i][0], self.cirStart[i][1], self.cirEnd2[i][0], self.cirEnd2[i][1], 3, 0x000000) else: # 画秒刻度 短线 screen.drawline(self.cirStart[i][0], self.cirStart[i][1], self.cirEnd1[i][0], self.cirEnd1[i][1], 2, 0x000000)
def filledRect(self, pos1, pos2, borderColor=0x000000, contentColor=0xFFFFFF): x1, y1 = pos1[0] - 1, pos1[1] - 1 x2, y2 = pos2[0] - 1, pos2[1] - 1 _screen.drawline(x1, y1, x2, y1, 1, borderColor) _screen.drawline(x1, y2, x2, y2, 1, borderColor) _screen.drawline(x1, y1, x1, y2, 1, borderColor) _screen.drawline(x2, y1, x2, y2, 1, borderColor) for i in range(y1 + 1, y2): _screen.drawline(x1 + 1, i, x2 - 1, i, 1, contentColor)
def draw(self,x,y):#清除一个相邻的方块并在新的地方画出一个方块,以达到运动的效果 screen.drawline(self.x, self.y, self.x-10, self.y, 3, 0xffffff) screen.drawline(self.x-10, self.y, self.x-10, self.y-10, 3, 0xffffff) screen.drawline(self.x-10, self.y-10, self.x, self.y-10, 3, 0xffffff) screen.drawline(self.x, self.y-10, self.x, self.y, 3, 0xffffff) self.x=self.x+x*10 self.y=self.y+y*10 self.rect1(self.x,self.y,self.x-10,self.y-10)
def rect1(self,x, y,x2, y2):#画出一个方块 width = abs(x2 - x) height = abs(y2 - y) screen.drawline(x, y, x2, y, 3, 0x000000) screen.drawline(x2, y, x2, y2, 3, 0x000000) screen.drawline(x2, y2, x, y2, 3, 0x000000) screen.drawline(x, y2, x, y, 3, 0x000000) utime.sleep_ms(20)
def __init__(self, master=None, x=10, y=10, w=222, h=222): self.x = x self.y = y self.w = w self.h = h self.width = w // 35 - 1 self.height = h // 55 - 1 self.bg = 0x000000 print(self.width, self.height) #画背景 for i in range(320): screen.drawline(0, i, 239, i, 1, self.bg) self.initial()
def __init__(self): screen.clear() self.x = 61 self.quit_flag = False self.timer = Timer(-1) screen.drawline(60, 100, 180, 100, 1, 0x000000) screen.drawline(60, 130, 180, 130, 1, 0x000000) screen.drawline(60, 100, 60, 130, 1, 0x000000) screen.drawline(180, 100, 180, 130, 1, 0x000000)
def drawRect(self, x1, y1, x2, y2, lineWidth, lineColor): x = int(x1) y = int(y1) w = int(x2 - x1) h = int(y2 - y1) screen.drawline(x, y, x + w, y, lineWidth, lineColor) screen.drawline(x + w, y, x + w, y + h, lineWidth, lineColor) screen.drawline(x + w, y + h, x, y + h, lineWidth, lineColor) screen.drawline(x, y + h, x, y, lineWidth, lineColor)
def initial(self): for i in range(0, 4): for j in range(0, 4): x = i * 55 + self.x + 1 y = j * 55 + self.y + 1 #画边界 screen.drawline(x, y, x + 55 - 1, y, 1, 0xFFFFFF) screen.drawline(x + 55 - 1, y, x + 55 - 1, y + 55, 1, 0xFFFFFF) screen.drawline(x, y + 55, x + 55 - 1, y + 55, 1, 0xFFFFFF) screen.drawline(x, y, x, y + 55, 1, 0xFFFFFF)
def __init__(self, master=None, x=10, y=10, w=222, h=303): self.x = x self.y = y self.w = w self.h = h self.width = w // 10 - 1 self.height = h // 10 - 1 self.bg = 0x000000 print(self.width, self.height) #画背景 for i in range(320): screen.drawline(0, i, 239, i, 1, self.bg) #画边界 screen.drawline(x, y, x + w - 1, y, 1, 0xFFFFFF) screen.drawline(x + w - 1, y, x + w - 1, y + h, 1, 0xFFFFFF) screen.drawline(x, y + h, x + w - 1, y + h, 1, 0xFFFFFF) screen.drawline(x, y, x, y + h, 1, 0xFFFFFF)
def drawRect(self, pos1, pos2, color=0x000000, weight=1): assert self.width >= pos1[0] >= 1 and self.width >= pos2[ 0] >= 1, "X out of border" assert self.height >= pos1[1] >= 1 and self.height >= pos2[ 1] >= 1, "Y out of border" half_weight = weight // 2 x1, y1 = pos1[0] - 1, pos1[1] - 1 x2, y2 = pos2[0] - 1, pos2[1] - 1 _screen.drawline(x1 - half_weight, y1, x2 + half_weight, y1, weight, color) _screen.drawline(x1 - half_weight, y2, x2 + half_weight, y2, weight, color) _screen.drawline(x1, y1, x1, y2, weight, color) _screen.drawline(x2, y1, x2, y2, weight, color)
def __init__(self, master=None, x=10, y=10, w=222, h=303, s=10): self.x = x # 格栅系统左上角横坐标:px self.y = y # 格栅系统左上角纵坐标:px self.w = w # 格栅系统宽度:px self.h = h # 格栅系统高度:px self.s = s # 格子的边长:px self.width = w // self.s - 1 # 宽度:格子 self.height = h // self.s - 1 # 高度:格子 self.bg = 0x000000 # 背景色:16进制RGB # print(self.width, self.height) # 输出控制台提示信息 #画背景 for i in range(SCREEN_HEIGHT): # 用贯穿上下的竖线铺满屏幕 screen.drawline(0, i, SCREEN_WIDTH, i, 1, self.bg) #画边界 screen.drawline(x, y, x + w - 1, y, 1, 0xFFFFFF) # 上边框 screen.drawline(x + w - 1, y, x + w - 1, y + h, 1, 0xFFFFFF) # 右边框 screen.drawline(x, y + h, x + w - 1, y + h, 1, 0xFFFFFF) # 下边框 screen.drawline(x, y, x, y + h, 1, 0xFFFFFF)
def displayColon(self): # 时分间 x1 = self.startX + self.edgeL * 2 + self.margin + self.colon y1 = self.startY + self.margin x2 = x1 y2 = y1 + self.margin screen.drawline(x1, y1, x2, y2, self.edgeW, 0x000000) y1 = self.startY + self.margin * 4 y2 = y1 + self.margin screen.drawline(x1, y1, x2, y2, self.edgeW, 0x000000) # 分秒间 x1 = self.startX + self.edgeL * 4 + self.margin * 2 + self.colon * 3 y1 = self.startY + self.margin x2 = x1 y2 = y1 + self.margin screen.drawline(x1, y1, x2, y2, self.edgeW, 0x000000) y1 = self.startY + self.margin * 4 y2 = y1 + self.margin screen.drawline(x1, y1, x2, y2, self.edgeW, 0x000000)
def draw(self, pos, color): x = pos[0] * 10 + self.x + 1 y = pos[1] * 10 + self.y + 1 for i in range(10): screen.drawline(x, y + i, x + 10 - 1, y + i, 1, color)
def start(self): while True: start = time.ticks_ms() # 记录开始时间 # 获取列表下标 hi = int(self.totalSec / 720) mi = int(self.totalSec / 60) % 60 si = self.totalSec % 60 # 画时分秒针并保留一段时间 screen.drawline(self.hurTail[hi][0], self.hurTail[hi][1], self.hurHand[hi][0], self.hurHand[hi][1], 2, 0x000000) screen.drawline(self.minTail[mi][0], self.minTail[mi][1], self.minHand[mi][0], self.minHand[mi][1], 2, 0x000000) screen.drawline(self.secTail[si][0], self.secTail[si][1], self.secHand[si][0], self.secHand[si][1], 2, 0x000000) time.sleep_ms(980) # 程序执行延时大约20ms # 擦除时分秒针 screen.drawline(self.secTail[si][0], self.secTail[si][1], self.secHand[si][0], self.secHand[si][1], 2, 0xffffff) if self.totalSec % 60 == 59: screen.drawline(self.minTail[mi][0], self.minTail[mi][1], self.minHand[mi][0], self.minHand[mi][1], 2, 0xffffff) if self.totalSec % 720 == 719: screen.drawline(self.hurTail[hi][0], self.hurTail[hi][1], self.hurHand[hi][0], self.hurHand[hi][1], 2, 0xffffff) self.totalSec = self.totalSec + 1 if self.totalSec >= 43200: self.totalSec = 0 print(time.ticks_diff(time.ticks_ms(), start)) # 每一次循环运行时间
def drawgrid(self, pos, color): x = pos[1] * 10 + self.x + 2 y = pos[0] * 10 + self.y + 2 for i in range(9): screen.drawline(x, y + i, x + 9 - 1, y + i, 1, color)
def __init__(self, master=None, x=10, y=10, w=193, h=303): self.x = x self.y = y self.w = w self.h = h self.rows = h // 10 self.cols = w // 10 self.bg = 0x000000 print(self.rows, self.cols) #画背景 for i in range(320): screen.drawline(0, i, 239, i, 1, self.bg) #画边界 screen.drawline(x, y, x + w - 1, y, 1, 0xFFFFFF) screen.drawline(x + w - 1, y, x + w - 1, y + h, 1, 0xFFFFFF) screen.drawline(x, y + h, x + w - 1, y + h, 1, 0xFFFFFF) screen.drawline(x, y, x, y + h, 1, 0xFFFFFF) #画提示框边界 screen.drawline(204, 10, 204 + 32 - 1, 10, 1, 0xFFFFFF) screen.drawline(204 + 32 - 1, 10, 204 + 32 - 1, 10 + 32, 1, 0xFFFFFF) screen.drawline(204, 10 + 32, 204 + 32 - 1, 10 + 32, 1, 0xFFFFFF) screen.drawline(204, 10, 204, 10 + 32, 1, 0xFFFFFF)
def put_circle_back(self, x, y, r, color): #画圆形棋子 a = 0 #选定原点距离圆心距离 b = r #在原点所画交叉线长度 di = 3 - (r << 1) #辅助判断画圆是否结束 while (a <= b): #选定原点画交叉线 screen.drawline(x - b, y - a, x + b, y - a, 3, color) screen.drawline(x - a, y, x - a, y + b, 3, color) screen.drawline(x - b, y - a, x, y - a, 3, color) screen.drawline(x - a, y - b, x - a, y, 3, color) screen.drawline(x, y + a, x + b, y + a, 3, color) screen.drawline(x + a, y - b, x + a, y, 3, color) screen.drawline(x + a, y, x + a, y + b, 3, color) screen.drawline(x - b, y + a, x, y + a, 3, color) a += 1 #改变原点位置 if (di < 0): #辅助判断画圆是否结束,计算下一步所画交叉线长度 di += 4 * a + 6 else: di += 10 + 4 * (a - b) b -= 1 screen.drawline(x + a, y, x + a, y + b, 3, color)
def drawpre(self, pos, color): x = pos[1] * 10 + 204 + 2 y = pos[0] * 10 + 10 + 2 for i in range(9): screen.drawline(x, y + i, x + 9 - 1, y + i, 1, color)
def drawcross(self, x, y, lineColor): # 画选择位置的框 screen.drawline(x - 10, y - 10, x - 5, y - 10, 3, lineColor) screen.drawline(x - 10, y - 10, x - 10, y - 5, 3, lineColor) screen.drawline(x + 10, y - 10, x + 5, y - 10, 3, lineColor) screen.drawline(x + 10, y - 10, x + 10, y - 5, 3, lineColor) screen.drawline(x - 10, y + 10, x - 5, y + 10, 3, lineColor) screen.drawline(x - 10, y + 10, x - 10, y + 5, 3, lineColor) screen.drawline(x + 10, y + 10, x + 5, y + 10, 3, lineColor) screen.drawline(x + 10, y + 10, x + 10, y + 5, 3, lineColor)
def selectInit(self): #选择表情初始化 screen.drawline(20, 200, 92, 200, 2, 0xff0000) screen.drawline(92, 200, 92, 272, 2, 0xff0000) screen.drawline(92, 272, 20, 272, 2, 0xff0000) screen.drawline(20, 272, 20, 200, 2, 0xff0000)
def clear(self): w, h = len(self.text) * 16, 16 for i in range(h): _screen.drawline(self.x, self.y + i, self.x + w, self.y + i, 1, self.bg)
def displayNum(self, num, x, y): # 1号边 x1 = x y1 = y x2 = x + self.edgeL y2 = y screen.drawline(x1, y1, x2, y2, self.edgeW, self.colorDict[num[0]]) # 2号边 x1 = x y1 = y + self.edgeL x2 = x + self.edgeL y2 = y + self.edgeL screen.drawline(x1, y1, x2, y2, self.edgeW, self.colorDict[num[1]]) # 3号边 x1 = x y1 = y + self.edgeL * 2 x2 = x + self.edgeL y2 = y + self.edgeL * 2 screen.drawline(x1, y1, x2, y2, self.edgeW, self.colorDict[num[2]]) # 4号边 x1 = x y1 = y x2 = x y2 = y + self.edgeL screen.drawline(x1, y1, x2, y2, self.edgeW, self.colorDict[num[3]]) # 5号边 x1 = x y1 = y + self.edgeL x2 = x y2 = y + self.edgeL * 2 screen.drawline(x1, y1, x2, y2, self.edgeW, self.colorDict[num[4]]) # 6号边 x1 = x + self.edgeL y1 = y x2 = x + self.edgeL y2 = y + self.edgeL screen.drawline(x1, y1, x2, y2, self.edgeW, self.colorDict[num[5]]) # 7号边 x1 = x + self.edgeL y1 = y + self.edgeL x2 = x + self.edgeL y2 = y + self.edgeL * 2 screen.drawline(x1, y1, x2, y2, self.edgeW, self.colorDict[num[6]])
def draw(self, pos, color): # pos 是一个元组(横坐标:格子,纵坐标:格子) x = pos[0] * self.s + self.x + 1 # 格子坐标转绝对坐标:px y = pos[1] * self.s + self.y + 1 # 格子坐标转绝对坐标:px for i in range(self.s): # 用贯穿上下的竖线铺满一格 screen.drawline(x, y + i, x + self.s - 1, y + i, 1, color)
def keyboardEvent(self, key): if self.keymatch[key] == "Key1": #右移键,选择要发送的表情 if self.select % 2 == 1: #用红色框选中boy表情 screen.drawline(20, 200, 92, 200, 2, 0xffffff) screen.drawline(92, 200, 92, 272, 2, 0xffffff) screen.drawline(92, 272, 20, 272, 2, 0xffffff) screen.drawline(20, 272, 20, 200, 2, 0xffffff) screen.drawline(140, 200, 212, 200, 2, 0xff0000) screen.drawline(212, 200, 212, 272, 2, 0xff0000) screen.drawline(212, 272, 140, 272, 2, 0xff0000) screen.drawline(140, 272, 140, 200, 2, 0xff0000) self.select += 1 else: #用红色框选中girl表情 screen.drawline(140, 200, 212, 200, 2, 0xffffff) screen.drawline(212, 200, 212, 272, 2, 0xffffff) screen.drawline(212, 272, 140, 272, 2, 0xffffff) screen.drawline(140, 272, 140, 200, 2, 0xffffff) screen.drawline(20, 200, 92, 200, 2, 0xff0000) screen.drawline(92, 200, 92, 272, 2, 0xff0000) screen.drawline(92, 272, 20, 272, 2, 0xff0000) screen.drawline(20, 272, 20, 200, 2, 0xff0000) self.select += 1 if self.keymatch[key] == "Key3": #发送表情按键 if self.select % 2 == 1: #显示已发送boy表情 bmp1 = ubitmap.BitmapFromFile("pic/boy") bmp1.draw(140, 40) self.content = "001" self.client.publish(self.TOPIC2, self.content) #给服务器发送boy表情的号码 else: #显示已发送girl表情 bmp2 = ubitmap.BitmapFromFile("pic/girl") bmp2.draw(140, 40) self.content = "002" self.client.publish(self.TOPIC2, self.content) #给服务器发送girl表情的号码
week0 = " 一 二 三 四 五 六 日" week1 = " 01020304050607 " week2 = " 08091011121314" week3 = " 15161718192021" week4 = " 22232425262728" week5 = " 293031" #显示日期 text.draw(week0, 8, 0, BLACK, 0xffffff) text.draw(week1, 0, 30, BLACK, 0xffffff) text.draw(week2, 0, 60, BLACK, 0xffffff) text.draw(week3, 0, 90, BLACK, 0xffffff) text.draw(week4, 0, 120, BLACK, 0xffffff) text.draw(week5, 0, 150, BLACK, 0xffffff) #划线分隔日期 #竖线 screen.drawline(50, 30, 50, 170, 1, 0x000000) screen.drawline(82, 30, 82, 170, 1, 0x000000) screen.drawline(114, 30, 114, 170, 1, 0x000000) screen.drawline(146, 30, 146, 170, 1, 0x000000) screen.drawline(178, 30, 178, 170, 1, 0x000000) screen.drawline(210, 30, 210, 170, 1, 0x000000) #横线 screen.drawline(10, 50, 240, 50, 1, 0x000000) screen.drawline(10, 80, 240, 80, 1, 0x000000) screen.drawline(10, 110, 240, 110, 1, 0x000000) screen.drawline(10, 140, 240, 140, 1, 0x000000) #改变当前日期颜色 x = (t3 - 1) % 7 * 32 + 16 y = (t3 // 7) * 30 + 30 if t3 > 9: text.draw(str(t3), x, y, RED, 0xffffff)