def render(arr):
    w = int(arr[0])
    h = int(arr[1])
    lcd.clear()
    for y in range(0, h):
        for x in range(0, w):
            lcd.drawPixel(x, y, arr[3 + x + y * w])
def render(w: int, h: int):
    for y in range(0, h - 1):
        for x in range(0, w):
            clr = int(fire.fire(randint(0, 254), x, y))
            if clr == 0:
                pass
            else:
                lcd.drawPixel(x, y, clr)
def render(fire, w:int, h:int):
    for x in range(0, w):
        fire[h-1][x] = randint(0,255)
    for y in range(0, h-1):
        for x in range(0, w):
            px = int(palette[int(fire[y][x])])
            if px == 0:
                pass
            else:
                lcd.drawPixel(x, y, px)
Beispiel #4
0
 def render(self):
     lcd.setColor(0)
     if self.act == 2 or self.act == 3 or self.act == 4:
         # 跳跃状态才需要清空之前一帧绘制的内容
         # 清空上一帧绘制的内容
         for line in self.head_lines:
             lcd.drawLine(self.old_x + line[0], self.old_y + line[1],
                          self.old_x + line[2], self.old_y + line[3])
         for rect in self.body_rects:
             lcd.fillRect(self.old_x + rect[0], self.old_y + rect[1],
                          rect[2], rect[3])
         for pixel in self.extra_pixels:
             lcd.drawPixel(self.old_x + pixel[0], self.old_y + pixel[1])
         # 清空运动中上一帧眨眼的坐标
         lcd.drawPixel(self.old_x + 12, self.old_y + 1)
         # self.act == 4这是从跳跃状态转移至普通状态的中间状态,
         # 此时仍然需要清空上一帧内容,不然会导致状态错误而留下残影
         if self.act == 4:
             # 清空完上一帧内容,再去转变状态
             self.act = 1
             self.leg_status = 0
     self.clear_leg()
     # 绘制本一帧的内容
     lcd.setColor(0xffffff)
     for line in self.head_lines:
         lcd.drawLine(self.x + line[0], self.y + line[1], self.x + line[2],
                      self.y + line[3])
     for rect in self.body_rects:
         lcd.fillRect(self.x + rect[0], self.y + rect[1], rect[2], rect[3])
     for pixel in self.extra_pixels:
         lcd.drawPixel(self.x + pixel[0], self.y + pixel[1])
     # 由于不断更新的,所以脚单独绘制
     self.draw_leg()
     if self.blink < 40:
         lcd.setColor(0)
         lcd.drawPixel(self.x + 12, self.y + 1)
     elif self.blink < 60:
         # 闭眼效果在此
         lcd.setColor(0xffffff)
         lcd.drawPixel(self.x + 12, self.y + 1)
     else:
         self.blink = 0
     self.blink += 1
Beispiel #5
0
 def draw_leg(self):
     # 脚相关的坐标
     # 大腿
     rects = [[5, 16, 2, 2], [9, 16, 2, 2]]
     # 正常左脚
     left_nor_leg = [[5, 18], [5, 19], [6, 19], [7, 16]]
     # 正常右脚
     right_nor_leg = [[10, 18], [10, 19], [11, 19]]
     # 左脚抬起相关的坐标
     up_left_leg = [[5, 16, 5, 18], [5, 17, 7, 17]]
     # 右脚抬起相关的坐标
     up_right_leg = [[10, 16, 10, 18], [11, 17, 12, 17]]
     # 换脚的时候清空上一帧抬起的脚
     # 绘制静止状态的脚
     if self.act != 1:
         for rect in rects:
             lcd.fillRect(self.x + rect[0], self.y + rect[1], rect[2],
                          rect[3])
         for pixel in left_nor_leg:
             lcd.drawPixel(self.x + pixel[0], self.y + pixel[1])
         for pixel in right_nor_leg:
             lcd.drawPixel(self.x + pixel[0], self.y + pixel[1])
     else:
         # 跑步
         # 抬起左脚
         if self.leg_status < 10:
             lcd.fillRect(self.x + rects[1][0], self.y + rects[1][1],
                          rects[1][2], rects[1][3])
             for pixel in right_nor_leg:
                 lcd.drawPixel(self.x + pixel[0], self.y + pixel[1])
             for left_leg in up_left_leg:
                 lcd.drawLine(self.x + left_leg[0], self.y + left_leg[1],
                              self.x + left_leg[2], self.y + left_leg[3])
         # 抬起右脚
         elif self.leg_status < 20:
             lcd.fillRect(self.x + rects[0][0], self.y + rects[0][1],
                          rects[0][2], rects[0][3])
             for pixel in left_nor_leg:
                 lcd.drawPixel(self.x + pixel[0], self.y + pixel[1])
             for right_leg in up_right_leg:
                 lcd.drawLine(self.x + right_leg[0], self.y + right_leg[1],
                              self.x + right_leg[2], self.y + right_leg[3])
         else:
             self.leg_status = 0