def drawHead(self): for player in self.model.player_list: if player.is_alive: pos = tuple(map(int, player.pos)) color = player.color if player.is_dash: color = tuple([int(i * 127 / 255 + 128) for i in color]) gfxdraw.filled_circle(self.gameSurface, *pos, int(player.radius), color) # draw triangle triRadius = player.radius * 0.7 theta = math.atan2(player.direction.y, player.direction.x) relativeVertexStart = pg.math.Vector2(triRadius, 0).rotate( theta * 180 / math.pi) relativeVertices = [ relativeVertexStart.rotate(i * 120) for i in range(3) ] vertices = [player.pos + vertex for vertex in relativeVertices] intVertices = [int(x) for vertex in vertices for x in vertex] gfxdraw.filled_trigon(self.gameSurface, *intVertices, viewConst.Color_Snow) if player.is_circling: innerVertices = [ player.pos + 0.6 * vertex for vertex in relativeVertices ] intInnerVertices = [ int(x) for vertex in innerVertices for x in vertex ] gfxdraw.filled_trigon(self.gameSurface, *intInnerVertices, color)
def draw_alien(x, y, w, h): # head for ang in range(-45, 40, 10): ang = ang * pi / 180 # координаты центра головы x0 = x + 0.01 * w y0 = y + h / 5 + (h / 3 - h / 5) / 2 # вращение треугольника вокруг точки (x0, y0) x1 = int(x0 + (x - 0.24 * w - x0) * cos(ang) - (y + h / 5 - y0) * sin(ang)) y1 = int(y0 + (y + h / 5 - y0) * cos(ang) + (x - 0.24 * w - x0) * sin(ang)) x2 = int(x0 + (x + 0.26 * w - x0) * cos(ang) - (y + h / 5 - y0) * sin(ang)) y2 = int(y0 + (y + h / 5 - y0) * cos(ang) + (x + 0.26 * w - x0) * sin(ang)) x3 = int(x0 + (x + 0.01 * w - x0) * cos(ang) - (y + h / 3 - y0) * sin(ang)) y3 = int(y0 + (y + h / 3 - y0) * cos(ang) + (x + 0.01 * w - x0) * sin(ang)) gfxdraw.filled_trigon(screen, x1, y1, x2, y2, x3, y3, GREEN_ALIEN) # body ellipse(screen, GREEN_ALIEN, (x - w / 10, y + h / 3.2, w / 4, h / 3.5)) # hands ellipse(screen, GREEN_ALIEN, (x + w / 10, y + h / 3, w / 7, h / 14)) ellipse(screen, GREEN_ALIEN, (x + w / 6, y + h / 2.7, w / 7, h / 20)) ellipse(screen, GREEN_ALIEN, (x + w / 3.3, y + h / 2.5, w / 6, h / 24)) ellipse(screen, GREEN_ALIEN, (x - w / 6, y + h / 3, w / 7, h / 14)) ellipse(screen, GREEN_ALIEN, (x - w / 4.5, y + h / 2.6, w / 9, h / 20)) ellipse(screen, GREEN_ALIEN, (x - w / 4, y + h / 2.3, w / 14, h / 22)) # legs ellipse(screen, GREEN_ALIEN, (x + w / 20, y + h / 1.9, w / 6.5, h / 9)) ellipse(screen, GREEN_ALIEN, (x + w / 9, y + h / 1.65, w / 9, h / 8)) ellipse(screen, GREEN_ALIEN, (x + w / 5.3, y + h / 1.45, w / 7, h / 14)) ellipse(screen, GREEN_ALIEN, (x - w / 6, y + h / 1.9 - h / 22, w / 6.5, h / 9)) ellipse(screen, GREEN_ALIEN, (x - w / 5, y + h / 1.65 - h / 22, w / 9, h / 8)) ellipse(screen, GREEN_ALIEN, (x - w / 3.25, y + h / 1.45 - h / 22, w / 7, h / 14)) # eyes circle(screen, BLACK, (x + x / 20, y + h / 4.1), h / 32) circle(screen, WHITE, (x + x / 18, y + h / 4), h / 90) circle(screen, BLACK, (x - x / 35, y + h / 4.3), h / 25) circle(screen, WHITE, (x - x / 45, y + h / 4.2), h / 90) # apple circle(screen, RED, (x + w / 2, y + h / 2.7), 0.05 * h) line(screen, BLACK, (x + w / 2.05, y + h / 3), (x + w / 1.9, y + h / 3.5), 2) polygon(screen, GREEN_LEAF, [(x + w / 2, y + h / 3.2), (x + w / 2, y + h / 3.35), (x + w / 2.1, y + h / 3.7), (x + w / 2.1, y + h / 3.5), (x + w / 2, y + h / 3.2)])
def draw_aa(screen, p, color): try: gfx.filled_trigon(screen, p[0][0], p[0][1], p[1][0], p[1][1], p[2][0], p[2][1], color) except: print("points", p[0][0], p[0][1], p[1][0], p[1][1], p[2][0], p[2][1]) print(color) gfx.aatrigon(screen, p[0][0], p[0][1], p[1][0], p[1][1], p[2][0], p[2][1], color)
def trigon(screen, x, y, color, layer, r=20): x1 = x y1 = y - r x2 = x + r * math.cos(pi / 6) y2 = y + r * math.sin(pi / 6) x3 = x - r * math.cos(pi / 6) y3 = y2 draw.filled_trigon(screen, int(x1), int(y1), int(x2), int(y2), int(x3), int(y3), color) if layer == "end": pg.draw.circle(screen, BLACK, (int(x), int(y)), 8)
def func(event): global light_pos objs.sort(key=lambda x:x.from_center.length(), reverse=True) screen.fill((255,255,255)) DS = 0.2 DA = 10 print(pygame.event.event_name(event.type)) if event.key == pygame.K_LEFT: active_obj.move(V3(-DS,0,0)) elif event.key == pygame.K_RIGHT: active_obj.move(V3(DS,0,0)) elif event.key == pygame.K_DOWN: active_obj.move(V3(0,-DS,0)) elif event.key == pygame.K_UP: active_obj.move(V3(0,DS,0)) elif event.key == pygame.K_m: active_obj.move(V3(0,0,DS)) elif event.key == pygame.K_l: active_obj.move(V3(0,0,-DS)) elif event.key == pygame.K_z: active_obj.rotate_around_center_z(DA) elif event.key == pygame.K_u: active_obj.rotate_around_center_z(-DA) elif event.key == pygame.K_x: active_obj.rotate_around_center_x(DA) elif event.key == pygame.K_c: active_obj.rotate_around_center_x(-DA) elif event.key == pygame.K_y: active_obj.rotate_around_center_y(DA) elif event.key == pygame.K_a: active_obj.rotate_around_center_y(-DA) elif event.key == pygame.K_SPACE: ## cam.move(V3(1,0,1), objs) cam.rotate("y",1,objs) for obj in objs: #pas boucler sur objs mais sur tous les triangles de la scen!!! ==> objet scene, le concept de obj est la que pour user transfos ? obj.refresh() i = 0 for t in obj.triangles: if t.c.z > 0: #c denotes the center coordinate p = [] for v in t.vertices(): x,y = cam.project(v) p.append((int(x),int(y))) if USE_LIGHT: color = light.get_color(t) else: color = t.color ## print(color) ## color = t.color ## print(p) gfx.filled_trigon(screen, p[0][0], p[0][1], p[1][0], p[1][1], p[2][0], p[2][1], color) gfx.aatrigon(screen, p[0][0], p[0][1], p[1][0], p[1][1], p[2][0], p[2][1], color) i+=1 pygame.display.flip()
def draw(self): gfxdraw.filled_trigon(screen, self.trigonPointLeftX,self.trigonPointLeftY, self.trigonPointRightX,self.trigonPointRightY, self.x,self.y, (0,0,0)) gfxdraw.aatrigon(screen, self.trigonPointLeftX,self.trigonPointLeftY, self.trigonPointRightX,self.trigonPointRightY, self.x,self.y, (240,240,240))#clean this line
def trigon(x, y, color, extra): r = 20 x1 = x y1 = y - r x2 = x + r * math.cos(pi / 6) y2 = y + r * math.sin(pi / 6) x3 = x - r * math.cos(pi / 6) y3 = y2 draw.filled_trigon(screen, int(x1), int(y1), int(x2), int(y2), int(x3), int(y3), color) if extra: pg.draw.circle(screen, BLACK, (int(x), int(y)), 8)
def __init__(self, screensection, screenname): debugprint(config.dbgscreenbuild, "New ThermostatScreenDesc ", screenname) screen.BaseKeyScreenDesc.__init__(self, screensection, screenname) utilities.LocalizeParams(self, screensection, 'KeyColor', 'KeyOffOutlineColor', 'KeyOnOutlineColor') self.info = {} self.fsize = (30, 50, 80, 160) if screenname in config.ISY.NodesByName: self.RealObj = config.ISY.NodesByName[screenname] else: self.RealObj = None config.Logs.Log("No Thermostat: " + screenname, severity=logsupport.ConsoleWarning) self.TitleRen = config.fonts.Font(self.fsize[1]).render(screen.FlatenScreenLabel(self.label), 0, wc(self.CharColor)) self.TitlePos = ((config.screenwidth - self.TitleRen.get_width())/2, config.topborder) self.TempPos = config.topborder + self.TitleRen.get_height() self.StatePos = self.TempPos + config.fonts.Font(self.fsize[3]).get_linesize() - scaleH(20) self.SPPos = self.StatePos + scaleH(25) self.AdjButSurf = pygame.Surface((config.screenwidth, scaleH(40))) self.AdjButTops = self.SPPos + config.fonts.Font(self.fsize[2]).get_linesize() - scaleH(5) centerspacing = config.screenwidth/5 self.AdjButSurf.fill(wc(self.BackgroundColor)) arrowsize = scaleH(40) # pixel for i in range(4): gfxdraw.filled_trigon(self.AdjButSurf, *trifromtop(centerspacing, arrowsize/2, i + 1, arrowsize, wc(("red", "blue", "red", "blue")[i]), i%2 <> 0)) self.keysbyord.append(toucharea.TouchPoint((centerspacing*(i + 1), self.AdjButTops + arrowsize/2), (arrowsize*1.2, arrowsize*1.2))) self.ModeButPos = self.AdjButTops + scaleH(85) # pixel bsize = (scaleW(100), scaleH(50)) # pixel self.keysbyord.append(toucharea.ManualKeyDesc("Mode", ["Mode"], self.KeyColor, self.CharColor, self.CharColor, center=(config.screenwidth/4, self.ModeButPos), size=bsize, KOn=config.KeyOffOutlineColor)) # todo clean up self.keysbyord.append(toucharea.ManualKeyDesc("Fan", ["Fan"], self.KeyColor, self.CharColor, self.CharColor, center=(3*config.screenwidth/4, self.ModeButPos), size=bsize, KOn=config.KeyOffOutlineColor)) self.keysbyord[4].FinishKey((0,0),(0,0)) self.keysbyord[5].FinishKey((0,0),(0,0)) self.ModesPos = self.ModeButPos + bsize[1]/2 + scaleH(5) utilities.register_example("ThermostatScreenDesc", self)
def __init__(self, screensection, screenname): debugPrint('BuildScreen', "New ThermostatScreenDesc ", screenname) screen.BaseKeyScreenDesc.__init__(self, screensection, screenname) utilities.LocalizeParams(self, screensection, 'KeyColor', 'KeyOffOutlineColor', 'KeyOnOutlineColor') self.info = {} self.fsize = (30, 50, 80, 160) if screenname in config.ISY.NodesByName: self.RealObj = config.ISY.NodesByName[screenname] else: self.RealObj = None config.Logs.Log("No Thermostat: " + screenname, severity=logsupport.ConsoleWarning) self.TitleRen = config.fonts.Font(self.fsize[1]).render(screen.FlatenScreenLabel(self.label), 0, wc(self.CharColor)) self.TitlePos = ((config.screenwidth - self.TitleRen.get_width())/2, config.topborder) self.TempPos = config.topborder + self.TitleRen.get_height() self.StatePos = self.TempPos + config.fonts.Font(self.fsize[3]).get_linesize() - scaleH(20) self.SPPos = self.StatePos + scaleH(25) self.AdjButSurf = pygame.Surface((config.screenwidth, scaleH(40))) self.AdjButTops = self.SPPos + config.fonts.Font(self.fsize[2]).get_linesize() - scaleH(5) centerspacing = config.screenwidth/5 self.AdjButSurf.fill(wc(self.BackgroundColor)) arrowsize = scaleH(40) # pixel for i in range(4): gfxdraw.filled_trigon(self.AdjButSurf, *trifromtop(centerspacing, arrowsize/2, i + 1, arrowsize, wc(("red", "blue", "red", "blue")[i]), i%2 <> 0)) self.keysbyord.append(toucharea.TouchPoint((centerspacing*(i + 1), self.AdjButTops + arrowsize/2), (arrowsize*1.2, arrowsize*1.2))) self.ModeButPos = self.AdjButTops + scaleH(85) # pixel bsize = (scaleW(100), scaleH(50)) # pixel self.keysbyord.append(toucharea.ManualKeyDesc("Mode", ["Mode"], self.KeyColor, self.CharColor, self.CharColor, center=(config.screenwidth/4, self.ModeButPos), size=bsize, KOn=config.KeyOffOutlineColor)) # todo clean up self.keysbyord.append(toucharea.ManualKeyDesc("Fan", ["Fan"], self.KeyColor, self.CharColor, self.CharColor, center=(3*config.screenwidth/4, self.ModeButPos), size=bsize, KOn=config.KeyOffOutlineColor)) self.keysbyord[4].FinishKey((0,0),(0,0)) self.keysbyord[5].FinishKey((0,0),(0,0)) self.ModesPos = self.ModeButPos + bsize[1]/2 + scaleH(5) utilities.register_example("ThermostatScreenDesc", self)
def on_draw(self, screen): # Changes every pixel in the window to black. This is done to wipe the screen and set it up for drawing a new # frame self.director.screen.fill((0, 0, 0)) # Calls the draw_grid function self.draw_grid(screen) # Calls the apple Entity's draw function self.apple.draw(screen) # Calls the head Entity's draw function self.head.draw(screen) # Calls the print_tail function self.print_tail(screen) # This conditional statement is executed if the gameOver boolean has been set to true if self.gameOver: # The text "Game Over" is printed to the middle of the screen screen.blit(self.text, self.text.get_rect(center=self.screen_rect.center)) # draws a round rectangle to the top left corner of the screen rrect( screen, (255, 255, 255), pygame.Rect(0 * self.director.scale, 0 * self.director.scale, 63 * self.director.scale, 30 * self.director.scale), 9 * self.director.scale, 3 * self.director.scale) # Prints the text to the screen at the specified coordinates screen.blit(self.txt, (25 * self.director.scale, 7 * self.director.scale)) #Draws a filled triangle to the screen with the points being at the specified coordinates gfxdraw.filled_trigon(screen, 5 * self.director.scale, 15 * self.director.scale, 20 * self.director.scale, 22 * self.director.scale, 20 * self.director.scale, 8 * self.director.scale, (255, 150, 44)) #Draws an anti-aliased triangle outline with the points being at the specified coordinates gfxdraw.aatrigon(screen, 5 * self.director.scale, 15 * self.director.scale, 20 * self.director.scale, 22 * self.director.scale, 20 * self.director.scale, 8 * self.director.scale, (255, 150, 44))
def filled_trigon(self, x1, y1, x2, y2, x3, y3, color): """内部が塗りつぶされた三角形を描画します. Parameters ---------- x1 : int 三角形の1つめの頂点のx座標. y1 : int 三角形の1つめの頂点のy座標. x2 : int 三角形の2つめの頂点のx座標. y2 : int 三角形の2つめの頂点のy座標. x3 : int 三角形の3つめの頂点のx座標. y3 : int 三角形の3つめの頂点のy座標. color : tuple of int 描画に使用される色を指定します. """ return gfx.filled_trigon(self.pg.screen, x1, y1, x2, y2, x3, y3, color)
def on_draw(self, screen): # Changes every pixel in the window to black. This is done to wipe the screen and set it up for drawing a new # frame screen.fill((0, 0, 0)) # Player One Config # A surface is created with the text "Player One Controls" printed on it self.txt = self.plyr.render("Player One Controls", True, (255, 255, 255)) # Prints the text to the game window at the specified coordinates screen.blit( self.txt, self.txt.get_rect(centerx=self.screen_rect.centerx, centery=19 * self.director.scale)) # A surface is created with the text "Player Two Controls" printed on it self.txt = self.plyr.render("Player Two Controls", True, (255, 255, 255)) # Prints the text to the game window at the specified coordinates screen.blit( self.txt, self.txt.get_rect(centerx=self.screen_rect.centerx, centery=149 * self.director.scale)) # Creates a rounded rectangle with an rgb color of white at the specified coordinates rrect( screen, (255, 255, 255), pygame.Rect(47 * self.director.scale, 34 * self.director.scale, 51 * self.director.scale, 51 * self.director.scale), 12 * self.director.scale, 3 * self.director.scale) # Creates a surface with the letter W printed on it self.txt = self.ctrl.render("W", True, (255, 255, 255)) # Prints the text to the game window a the specified coordinates screen.blit( self.txt, self.txt.get_rect( centerx=47 * self.director.scale + 25 * self.director.scale, centery=34 * self.director.scale + 25 * self.director.scale)) # Creates a surface with the word "up" on it self.txt = self.plyr.render("up", True, (255, 255, 255)) # Prints the text to the game window a the specified coordinates screen.blit( self.txt, self.txt.get_rect( centerx=47 * self.director.scale + 25 * self.director.scale, centery=34 * self.director.scale + 65 * self.director.scale)) # Creates a rounded rectangle with an rgb color of white at the specified coordinates rrect( screen, (255, 255, 255), pygame.Rect(133 * self.director.scale, 34 * self.director.scale, 51 * self.director.scale, 51 * self.director.scale), 12 * self.director.scale, 3 * self.director.scale) # Creates a surface with the letter A printed on it self.txt = self.ctrl.render("A", True, (255, 255, 255)) # Prints the text to the game window a the specified coordinates screen.blit( self.txt, self.txt.get_rect( centerx=133 * self.director.scale + 25 * self.director.scale, centery=34 * self.director.scale + 25 * self.director.scale)) # Creates a surface with the word "left" on it self.txt = self.plyr.render("left", True, (255, 255, 255)) # Prints the text to the game window a the specified coordinates screen.blit( self.txt, self.txt.get_rect( centerx=133 * self.director.scale + 25 * self.director.scale, centery=34 * self.director.scale + 65 * self.director.scale)) # Creates a rounded rectangle with an rgb color of white at the specified coordinates rrect( screen, (255, 255, 255), pygame.Rect(219 * self.director.scale, 34 * self.director.scale, 51 * self.director.scale, 51 * self.director.scale), 12 * self.director.scale, 3 * self.director.scale) # Creates a surface with the letter S printed on it self.txt = self.ctrl.render("S", True, (255, 255, 255)) # Prints the text to the game window a the specified coordinates screen.blit( self.txt, self.txt.get_rect( centerx=219 * self.director.scale + 25 * self.director.scale, centery=34 * self.director.scale + 25 * self.director.scale)) # Creates a surface with the word "down" on it self.txt = self.plyr.render("down", True, (255, 255, 255)) # Prints the text to the game window a the specified coordinates screen.blit( self.txt, self.txt.get_rect( centerx=219 * self.director.scale + 25 * self.director.scale, centery=34 * self.director.scale + 65 * self.director.scale)) # Creates a rounded rectangle with an rgb color of white at the specified coordinates rrect( screen, (255, 255, 255), pygame.Rect(305 * self.director.scale, 34 * self.director.scale, 51 * self.director.scale, 51 * self.director.scale), 12 * self.director.scale, 3 * self.director.scale) # Creates a surface with the letter D printed on it self.txt = self.ctrl.render("D", True, (255, 255, 255)) # Prints the text to the game window a the specified coordinates screen.blit( self.txt, self.txt.get_rect( centerx=305 * self.director.scale + 25 * self.director.scale, centery=34 * self.director.scale + 25 * self.director.scale)) # Creates a surface with the word "right" on it self.txt = self.plyr.render("right", True, (255, 255, 255)) # Prints the text to the game window a the specified coordinates screen.blit( self.txt, self.txt.get_rect( centerx=305 * self.director.scale + 25 * self.director.scale, centery=34 * self.director.scale + 65 * self.director.scale)) # Player Two Config # Creates a rounded rectangle with an rgb color of white at the specified coordinates rrect( screen, (255, 255, 255), pygame.Rect(47 * self.director.scale, 164 * self.director.scale, 51 * self.director.scale, 51 * self.director.scale), 12 * self.director.scale, 3 * self.director.scale) # Draws a filled triangle to the screen using the specified points gfxdraw.filled_trigon(screen, 72 * self.director.scale, 176 * self.director.scale, 86 * self.director.scale, 204 * self.director.scale, 58 * self.director.scale, 204 * self.director.scale, (255, 255, 255)) # Draws an outline of an anti-aliased triangle using the specified points gfxdraw.aatrigon(screen, 72 * self.director.scale, 176 * self.director.scale, 86 * self.director.scale, 204 * self.director.scale, 58 * self.director.scale, 204 * self.director.scale, (255, 255, 255)) # Creates a surface with the word "up" printed on it self.txt = self.plyr.render("up", True, (255, 255, 255)) # Prints the text to the game window a the specified coordinates screen.blit( self.txt, self.txt.get_rect( centerx=47 * self.director.scale + 25 * self.director.scale, centery=164 * self.director.scale + 65 * self.director.scale)) # Creates a rounded rectangle with an rgb color of white at the specified coordinates rrect( screen, (255, 255, 255), pygame.Rect(133 * self.director.scale, 164 * self.director.scale, 51 * self.director.scale, 51 * self.director.scale), 12 * self.director.scale, 3 * self.director.scale) # Draws a filled triangle to the screen using the specified points gfxdraw.filled_trigon(screen, 144 * self.director.scale, 189 * self.director.scale, 172 * self.director.scale, 175 * self.director.scale, 172 * self.director.scale, 203 * self.director.scale, (255, 255, 255)) # Draws an outline of an anti-aliased triangle using the specified points gfxdraw.aatrigon(screen, 144 * self.director.scale, 189 * self.director.scale, 172 * self.director.scale, 175 * self.director.scale, 172 * self.director.scale, 203 * self.director.scale, (255, 255, 255)) # Creates a surface with the word "left" printed on it self.txt = self.plyr.render("left", True, (255, 255, 255)) # Prints the text to the game window a the specified coordinates screen.blit( self.txt, self.txt.get_rect( centerx=133 * self.director.scale + 25 * self.director.scale, centery=164 * self.director.scale + 65 * self.director.scale)) # Creates a rounded rectangle with an rgb color of white at the specified coordinates rrect( screen, (255, 255, 255), pygame.Rect(219 * self.director.scale, 164 * self.director.scale, 51 * self.director.scale, 51 * self.director.scale), 12 * self.director.scale, 3 * self.director.scale) # Draws a filled triangle to the screen using the specified points gfxdraw.filled_trigon(screen, 244 * self.director.scale, 204 * self.director.scale, 258 * self.director.scale, 176 * self.director.scale, 230 * self.director.scale, 176 * self.director.scale, (255, 255, 255)) # Draws an outline of an anti-aliased triangle using the specified points gfxdraw.aatrigon(screen, 244 * self.director.scale, 204 * self.director.scale, 258 * self.director.scale, 176 * self.director.scale, 230 * self.director.scale, 176 * self.director.scale, (255, 255, 255)) # Creates a surface with the word "left" printed on it self.txt = self.plyr.render("down", True, (255, 255, 255)) # Prints the text to the game window a the specified coordinates screen.blit( self.txt, self.txt.get_rect( centerx=219 * self.director.scale + 25 * self.director.scale, centery=164 * self.director.scale + 65 * self.director.scale)) # Creates a rounded rectangle with an rgb color of white at the specified coordinates rrect( screen, (255, 255, 255), pygame.Rect(305 * self.director.scale, 164 * self.director.scale, 51 * self.director.scale, 51 * self.director.scale), 12 * self.director.scale, 3 * self.director.scale) # Draws a filled triangle to the screen using the specified points gfxdraw.filled_trigon(screen, 344 * self.director.scale, 189 * self.director.scale, 316 * self.director.scale, 175 * self.director.scale, 316 * self.director.scale, 203 * self.director.scale, (255, 255, 255)) # Draws an outline of an anti-aliased triangle using the specified points gfxdraw.aatrigon(screen, 344 * self.director.scale, 189 * self.director.scale, 316 * self.director.scale, 175 * self.director.scale, 316 * self.director.scale, 203 * self.director.scale, (255, 255, 255)) # Creates a surface with the word "right" printed on it self.txt = self.plyr.render("right", True, (255, 255, 255)) # Prints the text to the game window a the specified coordinates screen.blit( self.txt, self.txt.get_rect( centerx=305 * self.director.scale + 25 * self.director.scale, centery=164 * self.director.scale + 65 * self.director.scale)) # Creates a surface with the word "p1" printed on it self.txt = self.p.render("p1", True, (255, 255, 255)) # Prints the text to the game window a the specified coordinates screen.blit( self.txt, self.txt.get_rect(centerx=self.screen_rect.right / 3, centery=self.screen_rect.bottom - 116 * self.director.scale)) # Creates a surface with the word "p2" printed on it self.txt = self.p.render("p2", True, (255, 255, 255)) # Prints the text to the game window a the specified coordinates screen.blit( self.txt, self.txt.get_rect(centerx=self.screen_rect.right * (2 / 3), centery=self.screen_rect.bottom - 116 * self.director.scale)) # Draws anti-aliased lines to the screen using the coordinates given by drawpnts_one pygame.draw.aalines(screen, (255, 255, 255), False, self.drawpnts_one) # Draws anti-aliased lines to the screen using the coordinates given by drawpnts_two pygame.draw.aalines(screen, (255, 255, 255), False, self.drawpnts_two) # Draws the particle system self.particle_system.draw(screen) # Creates a surface with the name of the color printed on it using the color associated with that name self.txt = self.colortxt.render( self.color_name[self.director.index_one], True, self.color_rgb[self.director.index_one]) # Prints the text to the game window a the specified coordinates screen.blit( self.txt, self.txt.get_rect(centerx=133 * self.director.scale, centery=373 * self.director.scale)) # Creates a surface with the name of the color printed on it using the color associated with that name self.txt = self.colortxt.render( self.color_name[self.director.index_two], True, self.color_rgb[self.director.index_two]) # Prints the text to the game window a the specified coordinates screen.blit( self.txt, self.txt.get_rect(centerx=267 * self.director.scale, centery=373 * self.director.scale)) # This conditional statement says that if p1_hili_l_arrow is set to true then draw the enlarged version of the # triangle. Otherwise, draw the regular version if self.p1_hili_l_arrow: gfxdraw.filled_trigon(screen, 94 * self.director.scale, 363 * self.director.scale, 94 * self.director.scale, 383 * self.director.scale, 74 * self.director.scale, 373 * self.director.scale, (255, 255, 255)) gfxdraw.aatrigon(screen, 94 * self.director.scale, 363 * self.director.scale, 94 * self.director.scale, 383 * self.director.scale, 74 * self.director.scale, 373 * self.director.scale, (255, 255, 255)) else: gfxdraw.filled_trigon(screen, 91 * self.director.scale, 366 * self.director.scale, 91 * self.director.scale, 380 * self.director.scale, 77 * self.director.scale, 373 * self.director.scale, (255, 255, 255)) gfxdraw.aatrigon(screen, 91 * self.director.scale, 366 * self.director.scale, 91 * self.director.scale, 380 * self.director.scale, 77 * self.director.scale, 373 * self.director.scale, (255, 255, 255)) # This conditional statement says that if p1_hili_l_arrow is set to true then draw the enlarged version of the # triangle. Otherwise, draw the regular version if self.p1_hili_r_arrow: gfxdraw.filled_trigon(screen, 172 * self.director.scale, 363 * self.director.scale, 172 * self.director.scale, 383 * self.director.scale, 192 * self.director.scale, 373 * self.director.scale, (255, 255, 255)) gfxdraw.aatrigon(screen, 172 * self.director.scale, 363 * self.director.scale, 172 * self.director.scale, 383 * self.director.scale, 192 * self.director.scale, 373 * self.director.scale, (255, 255, 255)) else: gfxdraw.filled_trigon(screen, 175 * self.director.scale, 366 * self.director.scale, 175 * self.director.scale, 380 * self.director.scale, 189 * self.director.scale, 373 * self.director.scale, (255, 255, 255)) gfxdraw.aatrigon(screen, 175 * self.director.scale, 366 * self.director.scale, 175 * self.director.scale, 380 * self.director.scale, 189 * self.director.scale, 373 * self.director.scale, (255, 255, 255)) # This conditional statement says that if p2_hili_l_arrow is set to true then draw the enlarged version of the # triangle. Otherwise, draw the regular version if self.p2_hili_l_arrow: gfxdraw.filled_trigon(screen, 228 * self.director.scale, 363 * self.director.scale, 228 * self.director.scale, 383 * self.director.scale, 209 * self.director.scale, 373 * self.director.scale, (255, 255, 255)) gfxdraw.aatrigon(screen, 228 * self.director.scale, 363 * self.director.scale, 228 * self.director.scale, 383 * self.director.scale, 209 * self.director.scale, 373 * self.director.scale, (255, 255, 255)) else: gfxdraw.filled_trigon(screen, 225 * self.director.scale, 366 * self.director.scale, 225 * self.director.scale, 380 * self.director.scale, 211 * self.director.scale, 373 * self.director.scale, (255, 255, 255)) gfxdraw.aatrigon(screen, 225 * self.director.scale, 366 * self.director.scale, 225 * self.director.scale, 380 * self.director.scale, 211 * self.director.scale, 373 * self.director.scale, (255, 255, 255)) # This conditional statement says that if p2_hili_r_arrow is set to true then draw the enlarged version of the # triangle. Otherwise, draw the regular version if self.p2_hili_r_arrow: gfxdraw.filled_trigon(screen, 306 * self.director.scale, 363 * self.director.scale, 306 * self.director.scale, 383 * self.director.scale, 326 * self.director.scale, 373 * self.director.scale, (255, 255, 255)) gfxdraw.aatrigon(screen, 306 * self.director.scale, 363 * self.director.scale, 306 * self.director.scale, 383 * self.director.scale, 326 * self.director.scale, 373 * self.director.scale, (255, 255, 255)) else: gfxdraw.filled_trigon(screen, 309 * self.director.scale, 366 * self.director.scale, 309 * self.director.scale, 380 * self.director.scale, 323 * self.director.scale, 373 * self.director.scale, (255, 255, 255)) gfxdraw.aatrigon(screen, 309 * self.director.scale, 366 * self.director.scale, 309 * self.director.scale, 380 * self.director.scale, 323 * self.director.scale, 373 * self.director.scale, (255, 255, 255)) # Creates a rounded rectangle with an rgb color of white at the specified coordinates rrect( screen, (255, 255, 255), pygame.Rect(0 * self.director.scale, 0 * self.director.scale, 63 * self.director.scale, 30 * self.director.scale), 9 * self.director.scale, 3 * self.director.scale) # Creates a surface with the word "ctrl" printed on it self.txt = self.plyr.render("ctrl", True, (255, 255, 255)) # Prints the text to the game window a the specified coordinates screen.blit(self.txt, (25 * self.director.scale, 7 * self.director.scale)) # Draws a filled triangle to the screen using the specified points gfxdraw.filled_trigon(screen, 5 * self.director.scale, 15 * self.director.scale, 20 * self.director.scale, 22 * self.director.scale, 20 * self.director.scale, 8 * self.director.scale, (255, 150, 44)) # Draws an outline of an anti-aliased triangle using the specified points gfxdraw.aatrigon(screen, 5 * self.director.scale, 15 * self.director.scale, 20 * self.director.scale, 22 * self.director.scale, 20 * self.director.scale, 8 * self.director.scale, (255, 150, 44))
def create_body(color): original_image = Surface((16, 16), pygame.SRCALPHA) gfxdraw.aatrigon(original_image, 8, 0, 2, 16, 14, 16, color) gfxdraw.filled_trigon(original_image, 8, 0, 2, 16, 14, 16, color) return original_image
def drawCat(topx, topy, width, position, surf, cat_color): BLACK = (0, 0, 0) if position == 'middle': ## front gfxdraw.aatrigon(surf, int(topx + 3 * width / 32), int(topy + width / 2), int(topx + 5 * width / 32), int(topy + width / 2), int(topx + 4 * width / 32), int(topy + 7 * width / 8), cat_color) gfxdraw.filled_trigon(surf, int(topx + 3 * width / 32), int(topy + width / 2), int(topx + 5 * width / 32), int(topy + width / 2), int(topx + 4 * width / 32), int(topy + 7 * width / 8), cat_color) gfxdraw.aatrigon(surf, int(topx + 5 * width / 32), int(topy + width / 2), int(topx + 7 * width / 32), int(topy + width / 2), int(topx + 6 * width / 32), int(topy + 7 * width / 8), cat_color) gfxdraw.filled_trigon(surf, int(topx + 5 * width / 32), int(topy + width / 2), int(topx + 7 * width / 32), int(topy + width / 2), int(topx + 6 * width / 32), int(topy + 7 * width / 8), cat_color) ## back gfxdraw.aatrigon(surf, int(topx + 25 * width / 32), int(topy + width / 2), int(topx + 23 * width / 32), int(topy + width / 2), int(topx + 24 * width / 32), int(topy + 7 * width / 8), cat_color) gfxdraw.filled_trigon(surf, int(topx + 25 * width / 32), int(topy + width / 2), int(topx + 23 * width / 32), int(topy + width / 2), int(topx + 24 * width / 32), int(topy + 7 * width / 8), cat_color) gfxdraw.aatrigon(surf, int(topx + 23 * width / 32), int(topy + width / 2), int(topx + 21 * width / 32), int(topy + width / 2), int(topx + 22 * width / 32), int(topy + 7 * width / 8), cat_color) gfxdraw.filled_trigon(surf, int(topx + 23 * width / 32), int(topy + width / 2), int(topx + 21 * width / 32), int(topy + width / 2), int(topx + 22 * width / 32), int(topy + 7 * width / 8), cat_color) elif position == 'out': ## front gfxdraw.aatrigon(surf, int(topx + 3 * width / 32), int(topy + width / 2), int(topx + 5 * width / 32), int(topy + 7 * width / 16), int(topx + 1 * width / 32), int(topy + 7 * width / 8), cat_color) gfxdraw.filled_trigon(surf, int(topx + 3 * width / 32), int(topy + width / 2), int(topx + 5 * width / 32), int(topy + 7 * width / 16), int(topx + 1 * width / 32), int(topy + 7 * width / 8), cat_color) gfxdraw.aatrigon(surf, int(topx + 5 * width / 32), int(topy + width / 2), int(topx + 7 * width / 32), int(topy + 7 * width / 16), int(topx + 3 * width / 32), int(topy + 7 * width / 8), cat_color) gfxdraw.filled_trigon(surf, int(topx + 5 * width / 32), int(topy + width / 2), int(topx + 7 * width / 32), int(topy + 7 * width / 16), int(topx + 3 * width / 32), int(topy + 7 * width / 8), cat_color) ## back gfxdraw.aatrigon(surf, int(topx + 25 * width / 32), int(topy + width / 2), int(topx + 23 * width / 32), int(topy + 7 * width / 16), int(topx + 27 * width / 32), int(topy + 7 * width / 8), cat_color) gfxdraw.filled_trigon(surf, int(topx + 25 * width / 32), int(topy + width / 2), int(topx + 23 * width / 32), int(topy + 7 * width / 16), int(topx + 27 * width / 32), int(topy + 7 * width / 8), cat_color) gfxdraw.aatrigon(surf, int(topx + 23 * width / 32), int(topy + width / 2), int(topx + 21 * width / 32), int(topy + 7 * width / 16), int(topx + 25 * width / 32), int(topy + 7 * width / 8), cat_color) gfxdraw.filled_trigon(surf, int(topx + 23 * width / 32), int(topy + width / 2), int(topx + 21 * width / 32), int(topy + 7 * width / 16), int(topx + 25 * width / 32), int(topy + 7 * width / 8), cat_color) elif position == "in": ## front gfxdraw.aatrigon(surf, int(topx + 3 * width / 32), int(topy + width / 2), int(topx + 5 * width / 32), int(topy + 7 * width / 16), int(topx + 7 * width / 32), int(topy + 7 * width / 8), cat_color) gfxdraw.filled_trigon(surf, int(topx + 3 * width / 32), int(topy + width / 2), int(topx + 5 * width / 32), int(topy + 7 * width / 16), int(topx + 7 * width / 32), int(topy + 7 * width / 8), cat_color) gfxdraw.aatrigon(surf, int(topx + 5 * width / 32), int(topy + width / 2), int(topx + 7 * width / 32), int(topy + 7 * width / 16), int(topx + 9 * width / 32), int(topy + 7 * width / 8), cat_color) gfxdraw.filled_trigon(surf, int(topx + 5 * width / 32), int(topy + width / 2), int(topx + 7 * width / 32), int(topy + 7 * width / 16), int(topx + 9 * width / 32), int(topy + 7 * width / 8), cat_color) ## back gfxdraw.aatrigon(surf, int(topx + 25 * width / 32), int(topy + 7 * width / 16), int(topx + 23 * width / 32), int(topy + width / 2), int(topx + 21 * width / 32), int(topy + 7 * width / 8), cat_color) gfxdraw.filled_trigon(surf, int(topx + 25 * width / 32), int(topy + 7 * width / 16), int(topx + 23 * width / 32), int(topy + width / 2), int(topx + 21 * width / 32), int(topy + 7 * width / 8), cat_color) gfxdraw.aatrigon(surf, int(topx + 23 * width / 32), int(topy + 7 * width / 16), int(topx + 21 * width / 32), int(topy + width / 2), int(topx + 19 * width / 32), int(topy + 7 * width / 8), cat_color) gfxdraw.filled_trigon(surf, int(topx + 23 * width / 32), int(topy + 7 * width / 16), int(topx + 21 * width / 32), int(topy + width / 2), int(topx + 19 * width / 32), int(topy + 7 * width / 8), cat_color) # draw the body of the cat pygame.draw.ellipse(surf, cat_color, (int(topx + width / 16), int(topy + width / 4), int(3 * width / 4), int(width / 2))) # pygame.draw.ellipse(surf, BLACK, # (int(topx + width/16), int(topy + width/4), # int(3*width/4), int(width/2)), 5) # draw the ears of the cat pygame.draw.aalines(surf, cat_color, False, ((int(topx + 7 * width / 12), int(topy + width / 4)), (int(topx + 8 * width / 12), int(topy)), (int(topx + 9 * width / 12), int(topy + width / 4)))) pygame.draw.aalines(surf, cat_color, False, ((int(topx + 9 * width / 12), int(topy + width / 4)), (int(topx + 10 * width / 12), int(topy)), (int(topx + 11 * width / 12), int(topy + width / 4)))) # draw the head of the cat gfxdraw.filled_circle(surf, int(topx + 3 * width / 4), int(topy + width / 4), int(width / 6), cat_color) gfxdraw.aacircle(surf, int(topx + 3 * width / 4), int(topy + width / 4), int(width / 6), cat_color) # draw the eyes of the cat pygame.draw.ellipse(surf, BLACK, (int(topx + 5.2 * width / 8), int(topy + width / 8), int(width / 10), int(width / 12))) pygame.draw.ellipse(surf, BLACK, (int(topx + 6.2 * width / 8), int(topy + width / 8), int(width / 10), int(width / 12)))
def draw_normal(screen, p, color): gfx.filled_trigon(screen, p[0][0], p[0][1], p[1][0], p[1][1], p[2][0], p[2][1], color)
def __init__(self, screensection, screenname): debug.debugPrint('Screen', "New ThermostatScreenDesc ", screenname) screen.BaseKeyScreenDesc.__init__(self, screensection, screenname) screen.IncorporateParams( self, 'ThermostatScreen', {'KeyColor', 'KeyOffOutlineColor', 'KeyOnOutlineColor'}, screensection) self.info = {} self.oldinfo = {} nominalfontsz = (30, 50, 80, 160) nominalspacers = (5, 20, 25, 40, 50, 85) self.fsize = [] self.spacer = [] if isinstance(self.DefaultHubObj, isy.ISY): self.isy = self.DefaultHubObj self.ISYObj = self.isy.GetNode(screenname)[0] # use ControlObj (0) if self.ISYObj is None: logsupport.Logs.Log("No Thermostat: " + screenname, severity=ConsoleWarning) else: logsupport.Logs.Log("Thermostat screen only works with ISY hub", severity=ConsoleError) self.ISYObj = None self.SetScreenTitle(screen.FlatenScreenLabel(self.label), nominalfontsz[1], self.CharColor) self.TempPos = self.startvertspace ''' Size and positions based on vertical screen space less top/bottom borders less default title size of 50 Compute other fonts sizes based on what is left after that given user ability to set actual title size ''' tempsurf = fonts.fonts.Font(50).render('Temp', 0, wc( self.CharColor)) # todo should the 50 be scaled now? sizingratio = self.useablevertspace / (self.useablevertspace - tempsurf.get_height()) for fs in nominalfontsz: self.fsize.append(int(fs * sizingratio)) for fs in nominalspacers: self.spacer.append(int(fs * sizingratio)) self.StatePos = self.TempPos + fonts.fonts.Font( self.fsize[3]).get_linesize() - scaleH(self.spacer[1]) self.SPPos = self.StatePos + scaleH(self.spacer[2]) self.AdjButSurf = pygame.Surface( (hw.screenwidth, scaleH(self.spacer[3]))) self.AdjButTops = self.SPPos + fonts.fonts.Font( self.fsize[2]).get_linesize() - scaleH(self.spacer[0]) centerspacing = hw.screenwidth // 5 self.SPHPosL = int(1.5 * centerspacing) self.SPHPosR = int(3.5 * centerspacing) self.AdjButSurf.fill(wc(self.BackgroundColor)) arrowsize = scaleH(self.spacer[3]) # pixel for i in range(4): gfxdraw.filled_trigon( self.AdjButSurf, *trifromtop(centerspacing, arrowsize // 2, i + 1, arrowsize, wc(("red", "blue", "red", "blue")[i]), i % 2 != 0)) self.Keys['temp' + str(i)] = toucharea.TouchPoint( 'temp' + str(i), (centerspacing * (i + 1), self.AdjButTops + arrowsize // 2), (arrowsize * 1.2, arrowsize * 1.2), proc=functools.partial(self.BumpTemp, ('CLISPH', 'CLISPH', 'CLISPC', 'CLISPC')[i], (2, -2, 2, -2)[i])) self.ModeButPos = self.AdjButTops + scaleH(self.spacer[5]) # pixel bsize = (scaleW(100), scaleH(self.spacer[4])) # pixel self.Keys['Mode'] = toucharea.ManualKeyDesc( self, "Mode", ["Mode"], self.KeyColor, self.CharColor, self.CharColor, center=(self.SPHPosL, self.ModeButPos), size=bsize, KOn=self.KeyOffOutlineColor, proc=functools.partial(self.BumpMode, 'CLIMD', range(8))) self.Keys['Fan'] = toucharea.ManualKeyDesc( self, "Fan", ["Fan"], self.KeyColor, self.CharColor, self.CharColor, center=(self.SPHPosR, self.ModeButPos), size=bsize, KOn=self.KeyOffOutlineColor, proc=functools.partial(self.BumpMode, 'CLIFS', (7, 8))) self.ModesPos = self.ModeButPos + bsize[1] // 2 + scaleH( self.spacer[0]) if self.ISYObj is not None: self.HubInterestList[self.isy.name] = { self.ISYObj.address: self.Keys['Mode'] } # placeholder for thermostat node utilities.register_example("ThermostatScreenDesc", self)
def on_draw(self, screen): # Changes every pixel in the window to black. This is done to wipe the screen and set it up for drawing a new # frame self.director.screen.fill((0, 0, 0)) # Calls the draw_grid function self.draw_grid(screen) # Calls the apple Entity's draw function self.apple.draw(screen) # Calls the head Entity's draw function self.head_1.draw(screen) # Calls the head Entity's draw function self.head_2.draw(screen) # Calls the print_tail function self.print_tails(screen) # This conditional statement executes if player one has won if self.plyronewins: # The text "Player One Wins" is printed to the middle of the screen screen.blit( self.plyronewins_txt, self.plyronewins_txt.get_rect(center=self.screen_rect.center)) # Creates a surface with the text "ctrl" print on it using the plyr font self.txt = self.plyr.render("ctrl", True, (255, 255, 255)) # draws a round rectangle to the top left corner of the screen rrect( screen, (255, 255, 255), pygame.Rect(0 * self.director.scale, 0 * self.director.scale, 63 * self.director.scale, 30 * self.director.scale), 9 * self.director.scale, 3 * self.director.scale) # The text ctrl is printed in the top left corner of the screen screen.blit(self.txt, (25 * self.director.scale, 7 * self.director.scale)) #Draws a filled triangle to the screen with the points being at the specified coordinates gfxdraw.filled_trigon(screen, 5 * self.director.scale, 15 * self.director.scale, 20 * self.director.scale, 22 * self.director.scale, 20 * self.director.scale, 8 * self.director.scale, (255, 150, 44)) #Draws an anti-aliased triangle outline with the points being at the specified coordinates gfxdraw.aatrigon(screen, 5 * self.director.scale, 15 * self.director.scale, 20 * self.director.scale, 22 * self.director.scale, 20 * self.director.scale, 8 * self.director.scale, (255, 150, 44)) #pygame.mixer.music.stop() # This conditional statement executes if player two has won if self.plyrtwowins: # The text "Player Two Wins" is printed to the middle of the screen screen.blit( self.plyrtwowins_txt, self.plyronewins_txt.get_rect(center=self.screen_rect.center)) # Creates a surface with the text "ctrl" print on it using the plyr font self.txt = self.plyr.render("ctrl", True, (255, 255, 255)) # draws a round rectangle to the top left corner of the screen rrect( screen, (255, 255, 255), pygame.Rect(0 * self.director.scale, 0 * self.director.scale, 63 * self.director.scale, 30 * self.director.scale), 9 * self.director.scale, 3 * self.director.scale) # The text ctrl is printed in the top left corner of the screen screen.blit(self.txt, (25 * self.director.scale, 7 * self.director.scale)) #Draws a filled triangle to the screen with the points being at the specified coordinates gfxdraw.filled_trigon(screen, 5 * self.director.scale, 15 * self.director.scale, 20 * self.director.scale, 22 * self.director.scale, 20 * self.director.scale, 8 * self.director.scale, (255, 150, 44)) #Draws an anti-aliased triangle outline with the points being at the specified coordinates gfxdraw.aatrigon(screen, 5 * self.director.scale, 15 * self.director.scale, 20 * self.director.scale, 22 * self.director.scale, 20 * self.director.scale, 8 * self.director.scale, (255, 150, 44)) #pygame.mixer.music.stop() # This conditional statement executes if there has been a draw if self.plyrdraw: # Creates a surface with the text "ctrl" print on it using the plyr font self.txt = self.plyr.render("ctrl", True, (255, 255, 255)) # The text "draw" is printed to the middle of the screen screen.blit( self.plyrdraw_txt, self.plyrdraw_txt.get_rect(center=self.screen_rect.center)) # draws a round rectangle to the top left corner of the screen rrect( screen, (255, 255, 255), pygame.Rect(0 * self.director.scale, 0 * self.director.scale, 63 * self.director.scale, 30 * self.director.scale), 9 * self.director.scale, 3 * self.director.scale) # The text ctrl is printed in the top left corner of the screen screen.blit(self.txt, (25 * self.director.scale, 7 * self.director.scale)) #Draws a filled triangle to the screen with the points being at the specified coordinates gfxdraw.filled_trigon(screen, 5 * self.director.scale, 15 * self.director.scale, 20 * self.director.scale, 22 * self.director.scale, 20 * self.director.scale, 8 * self.director.scale, (255, 150, 44)) #Draws an anti-aliased triangle outline with the points being at the specified coordinates gfxdraw.aatrigon(screen, 5 * self.director.scale, 15 * self.director.scale, 20 * self.director.scale, 22 * self.director.scale, 20 * self.director.scale, 8 * self.director.scale, (255, 150, 44))
def draw_triangle(t, surface, marked=False): ((x1, y1), (x2, y2), (x3, y3)) = map(lambda c: tuple(c.vertex().loc()), t) (x1, y1, x2, y2, x3, y3) = map(int, (x1, y1, x2, y2, x3, y3)) color = (0, 80, 240) if not marked else (160, 100, 200) filled_trigon(surface, x1, y1, x2, y2, x3, y3, color)
def __init__(self, screensection, screenname): debug.debugPrint('Screen', "New Nest ThermostatScreenDesc ", screenname) screen.BaseKeyScreenDesc.__init__(self, screensection, screenname) screen.IncorporateParams( self, 'NestThermostatScreen', {'KeyColor', 'KeyOffOutlineColor', 'KeyOnOutlineColor'}, screensection) nominalfontsz = (30, 50, 80, 160) nominalspacers = (5, 20, 25, 40, 50, 85) self.fsize = [] self.spacer = [] self.HA = self.DefaultHubObj self.ThermNode = self.HA.GetNode(screenname)[0] # use ControlObj (0) if self.ThermNode is None: logsupport.Logs.Log("No Thermostat: " + screenname, severity=ConsoleWarning) raise ValueError # if isinstance(self.DefaultHub,hasshub.HA): # self.HA = self.DefaultHub # self.ThermNode = self.HA.GetNode(screenname)[0] # use ControlObj (0) # if self.ThermNode is None: # logsupport.Logs.Log("No Thermostat: " + screenname, severity=ConsoleWarning) # raise ValueError # else: # logsupport.Logs.Log("Nest Thermostat screen only works with HA hub", severity=ConsoleError) # self.self.ThermNode = None # raise ValueError self.SetScreenTitle(screen.FlatenScreenLabel(self.label), nominalfontsz[1], self.CharColor) self.TempPos = self.startvertspace ''' Size and positions based on nominal 480 vertical screen less top/bottom borders less default title size of 50 Compute other fonts sizes based on what is left after that given user ability to set actual title size ''' tempsurf = fonts.fonts.Font(50).render('Temp', 0, wc(self.CharColor)) useable = self.useablevertspace / (self.useablevertspace - tempsurf.get_height()) for fs in nominalfontsz: self.fsize.append(int(fs * useable)) for fs in nominalspacers: self.spacer.append(int(fs * useable)) self.StatePos = self.TempPos + fonts.fonts.Font( self.fsize[3]).get_linesize() - scaleH(self.spacer[1]) self.SPVPos = self.StatePos + scaleH(self.spacer[2]) sp = fonts.fonts.Font(self.fsize[2]).render("{:2d}".format(99), 0, wc(self.CharColor)) self.SPHgt = sp.get_height() self.SPWdt = sp.get_width() self.SetPointSurf = pygame.Surface((self.SPWdt, self.SPHgt)) self.SetPointSurf.fill(wc(self.BackgroundColor)) self.AdjButSurf = pygame.Surface( (hw.screenwidth, scaleH(self.spacer[3]))) self.AdjButTops = self.SPVPos + fonts.fonts.Font( self.fsize[2]).get_linesize() - scaleH(self.spacer[0]) centerspacing = hw.screenwidth // 5 self.SPHPosL = int(1.5 * centerspacing) self.SPHPosR = int(3.5 * centerspacing) self.AdjButSurf.fill(wc(self.BackgroundColor)) self.LocalOnly = [0.0, 0.0 ] # Heat setpoint, Cool setpoint: 0 is normal color self.ModeLocal = 0.0 self.FanLocal = 0.0 arrowsize = scaleH( 40) # pixel todo should this be other than a constant? self.t_low = 0 self.t_high = 99 self.t_cur = 0 self.t_state = "Unknown" self.mode = 'auto' self.fan = 'auto' self.modes, self.fanstates = self.ThermNode.GetModeInfo() self.TimeBumpSP = None self.TimeBumpModes = None self.TimeBumpFan = None self.TimerName = 0 for i in range(4): gfxdraw.filled_trigon( self.AdjButSurf, *trifromtop(centerspacing, arrowsize // 2, i + 1, arrowsize, wc(("red", "blue", "red", "blue")[i]), i % 2 != 0)) self.Keys['temp' + str(i)] = toucharea.TouchPoint( 'temp' + str(i), (centerspacing * (i + 1), self.AdjButTops + arrowsize // 2), (arrowsize * 1.2, arrowsize * 1.2), proc=functools.partial(self.BumpTemp, (True, True, False, False)[i], (1, -1, 1, -1)[i])) self.ModeButPos = self.AdjButTops + scaleH(self.spacer[5]) # pixel bsize = (scaleW(100), scaleH(self.spacer[4])) # pixel self.Keys['Mode'] = toucharea.ManualKeyDesc( self, "Mode", ["Mode"], self.KeyColor, self.CharColor, self.CharColor, center=(self.SPHPosL, self.ModeButPos), size=bsize, KOn=self.KeyOffOutlineColor, proc=self.BumpMode) self.Keys['Fan'] = toucharea.ManualKeyDesc(self, "Fan", ["Fan"], self.KeyColor, self.CharColor, self.CharColor, center=(self.SPHPosR, self.ModeButPos), size=bsize, KOn=self.KeyOffOutlineColor, proc=self.BumpFan) self.ModesPos = self.ModeButPos + bsize[1] // 2 + scaleH( self.spacer[0]) if self.ThermNode is not None: self.HubInterestList[self.HA.name] = { self.ThermNode.address: self.Keys['Mode'] } # placeholder for thermostat node utilities.register_example("NestThermostatScreenDesc", self)