def draw_top_bar(self): pyxel.rect(0, 0, pyxel.width, CONST.TOPBAR.HEIGHT, CONST.COLOR.CREAM) pyxel.line(0, CONST.TOPBAR.HEIGHT, pyxel.width, CONST.TOPBAR.HEIGHT, CONST.COLOR.BLACK) pyxel.blt(CONST.TOPBAR.TEXT_X - 8, CONST.TOPBAR.TEXT_Y - 2, 0, 136, 0, CONST.TOPBAR.ICON_SIZE, CONST.TOPBAR.ICON_SIZE ) pyxel.blt(CONST.TOPBAR.TEXT_X + 35, CONST.TOPBAR.TEXT_Y - 2, 0, 144, 0, CONST.TOPBAR.ICON_SIZE, CONST.TOPBAR.ICON_SIZE ) pyxel.text( CONST.TOPBAR.TEXT_X, CONST.TOPBAR.TEXT_Y, f"GAMEPAD {self.current_gamepad+1}", CONST.COLOR.BLACK )
def draw_results(self): self.quantum_results() pyxel.rectb(110, 110, 30, 10, 7) pyxel.text(115, 112, "Next", 7) state_1 = ''.join(self.state_1) state_2 = ''.join(self.state_2) state_3 = ''.join(self.state_3) state_4 = ''.join(self.state_4) game_result = [] for i in self.RawGameResults: game_result.append(str(i)) P1_Result = game_result[0] P2_Result = game_result[1] P3_Result = game_result[2] P4_Result = game_result[3] victor = [] for i in range(len(self.RawGameResults)): if self.RawGameResults[i] == 0: victor.append('You Lose') elif self.RawGameResults[i] == 1: victor.append('You Win') P1_v = victor[0] P2_v = victor[1] P3_v = victor[2] P4_v = victor[3] the_variable = ''.join(self.state_1) pyxel.text(67, 15, "Results", pyxel.frame_count % 16) pyxel.line(40, 30, 40, 110, 7) pyxel.line(80, 30, 80, 110, 7) pyxel.line(115, 37, 115, 110, 7) pyxel.text(45, 25, "Strategy", 7) pyxel.text(95, 25, "Game Results", 7) pyxel.text(5, 40, "Player 1", 7) pyxel.text(45, 40, state_1, 7) pyxel.text(90, 40, P1_Result, 7) pyxel.text(120, 40, P1_v, 7) pyxel.text(5, 60, "Player 2", 7) pyxel.text(45, 60, state_2, 7) pyxel.text(90, 60, P2_Result, 7) pyxel.text(120, 60, P2_v, 7) pyxel.text(5, 80, "Player 3", 7) pyxel.text(45, 80, state_3, 7) pyxel.text(90, 80, P3_Result, 7) pyxel.text(120, 80, P3_v, 7) pyxel.text(5, 100, "Player 4", 7) pyxel.text(45, 100, state_4, 7) pyxel.text(90, 100, P4_Result, 7) pyxel.text(120, 100, P4_v, 7)
def draw(self): # METODO QUE DIBUJA EL TRIANGULO if self.stateUP: pyxel.line(self.Ax, self.Ay, self.Bx, self.By, 15) # Dibuja hipotenusa if self.stateLEFT: pyxel.line(self.Ax, self.Ay, self.Bx, self.Ay, 14) # Dibuja adyacente if self.stateDOWN: pyxel.line(self.Bx, self.Ay, self.Bx, self.By, 13) # Dibuja opuesto
def __on_draw(self): x = self.x y = self.y w = self.width h = self.height self.draw_panel(x, y, w, h, with_shadow=self._with_shadow) inc_color = (BUTTON_PRESSED_COLOR if self.inc_button.is_pressed else WIDGET_BACKGROUND_COLOR) dec_color = (BUTTON_PRESSED_COLOR if self.dec_button.is_pressed else WIDGET_BACKGROUND_COLOR) if self._direction == ScrollBar.HORIZONTAL: pyxel.rect(x + 1, y + 1, 4, h - 2, dec_color) pyxel.rect(x + 6, y + 1, w - 12, h - 2, WIDGET_BACKGROUND_COLOR) pyxel.rect(x + w - 5, y + 1, 4, h - 2, inc_color) pyxel.pix(x + 2, y + 3, WIDGET_PANEL_COLOR) pyxel.line(x + 3, y + 2, x + 3, y + h - 3, WIDGET_PANEL_COLOR) pyxel.pix(x + w - 3, y + h - 4, WIDGET_PANEL_COLOR) pyxel.line(x + w - 4, y + 2, x + w - 4, y + h - 3, WIDGET_PANEL_COLOR) x = self.x + self.slider_pos y = self.y + 2 pyxel.rect(x, y, self.slider_size, 3, WIDGET_PANEL_COLOR) else: pyxel.rect(x + 1, y + 1, w - 2, 4, dec_color) pyxel.rect(x + 1, y + 6, w - 2, h - 12, WIDGET_BACKGROUND_COLOR) pyxel.rect(x + 1, y + h - 5, w - 2, 4, inc_color) pyxel.pix(x + 3, y + 2, WIDGET_PANEL_COLOR) pyxel.line(x + 2, y + 3, x + w - 3, y + 3, WIDGET_PANEL_COLOR) pyxel.pix(x + 3, y + h - 3, WIDGET_PANEL_COLOR) pyxel.line(x + 2, y + h - 4, x + w - 3, y + h - 4, WIDGET_PANEL_COLOR) x = self.x + 2 y = self.y + self.slider_pos pyxel.rect(x, y, 3, self.slider_size, WIDGET_PANEL_COLOR)
def hbox(cls): # TAKE X1 Y1 WHEN LMB HELD if pyxel.btnp(pyxel.MOUSE_LEFT_BUTTON, 0): Highlight.line_x1 = pyxel.mouse_x Highlight.line_y1 = pyxel.mouse_y # TAKE X2 Y2 WHEN LMB PRESSED - DRAWS THE HIGHLIGHT BOX BY CONNECTING CO-ORDINATES if pyxel.btn(pyxel.MOUSE_LEFT_BUTTON): Highlight.line_x2 = pyxel.mouse_x Highlight.line_y2 = pyxel.mouse_y pyxel.line(Highlight.line_x1, Highlight.line_y1, Highlight.line_x2, Highlight.line_y1, 3) pyxel.line(Highlight.line_x1, Highlight.line_y1, Highlight.line_x1, Highlight.line_y2, 3) pyxel.line(Highlight.line_x1, Highlight.line_y2, Highlight.line_x2, Highlight.line_y2, 3) pyxel.line(Highlight.line_x2, Highlight.line_y1, Highlight.line_x2, Highlight.line_y2, 3) # CLEARS THE HIGHLIGHT_BOX LIST, ADDS THE X1 Y1 X2 Y2 VALUES TO THE LIST if pyxel.btnr(pyxel.MOUSE_LEFT_BUTTON): Highlight.highlight_box.clear() Highlight.highlight_box.extend([Highlight.line_x1, Highlight.line_x2, Highlight.line_y1, Highlight.line_y2])
def __on_draw(self): x1 = self.x y1 = self.y x2 = x1 + self.width - 1 y2 = y1 + self.height - 1 pyxel.rect(x1 + 1, y1, x2 - 1, y2, WIDGET_BASE_COLOR) pyxel.rect(x1, y1 + 1, x2, y2 - 1, WIDGET_BASE_COLOR) inc_color = (BUTTON_PRESSED_COLOR if self.inc_button.is_pressed else WIDGET_BACKGROUND_COLOR) dec_color = (BUTTON_PRESSED_COLOR if self.dec_button.is_pressed else WIDGET_BACKGROUND_COLOR) if self.is_horizontal: pyxel.rect(x1 + 1, y1 + 1, x1 + 4, y2 - 1, dec_color) pyxel.rect(x1 + 6, y1 + 1, x2 - 6, y2 - 1, WIDGET_BACKGROUND_COLOR) pyxel.rect(x2 - 1, y1 + 1, x2 - 4, y2 - 1, inc_color) pyxel.pix(x1 + 2, y1 + 3, WIDGET_BASE_COLOR) pyxel.line(x1 + 3, y1 + 2, x1 + 3, y2 - 2, WIDGET_BASE_COLOR) pyxel.pix(x2 - 2, y2 - 3, WIDGET_BASE_COLOR) pyxel.line(x2 - 3, y1 + 2, x2 - 3, y2 - 2, WIDGET_BASE_COLOR) else: pyxel.rect(x1 + 1, y1 + 1, x2 - 1, y1 + 4, dec_color) pyxel.rect(x1 + 1, y1 + 6, x2 - 1, y2 - 6, WIDGET_BACKGROUND_COLOR) pyxel.rect(x1 + 1, y2 - 1, x2 - 1, y2 - 4, inc_color) pyxel.pix(x1 + 3, y1 + 2, WIDGET_BASE_COLOR) pyxel.line(x1 + 2, y1 + 3, x2 - 2, y1 + 3, WIDGET_BASE_COLOR) pyxel.pix(x1 + 3, y2 - 2, WIDGET_BASE_COLOR) pyxel.line(x1 + 2, y2 - 3, x2 - 2, y2 - 3, WIDGET_BASE_COLOR) if self.is_horizontal: x = self.x + self.slider_pos y = self.y + 2 pyxel.rect(x, y, x + self.slider_size - 1, y + 2, 1) else: x = self.x + 2 y = self.y + self.slider_pos pyxel.rect(x, y, x + 2, y + self.slider_size - 1, 1)
def draw(self): fc=pyxel.frame_count if self.pallet_test==1:pal(2,3)# pallet swap - test_pal1 if self.pallet_test==2:pal(4,7) if self.pallet_test==3:pal(7,10) _,__=cls(2),text(6,6, "cls(col)",7) #self.test_cls(6, 6) text(6, 20, "pix(x,y,col)", 7) for i in range(16):pix(10 + i*2, 30, i) text(106, 6, "line(x1,y1,x2,y2,col)", 7) for i in range(3):line(110, 15 + i * 8, 158, 15 + i * 8, 5+i) for i in range(4):line(110 + i*16, 15,110 + i * 16,31, 8+i) for i in range(4):line(110 + i*16, 15,110+ (3 - i) * 16,31, 12+i) text(6, 38, "rect(x,y,w,h,col)", 7) for i in range(8):rect(10 + i * 8, 54 - i, i + 1, i + 1, i + 8) text(106, 38, "rectb(x,y,w,h,col)", 7) for i in range(8):rectb(110+i*8,54- i, i + 1, i + 1, i + 8) text(6,61, "circ(x,y,r,col)", 7) for i in range(8):circ(10+ i * 8,76, i, i + 8) text(106, 61, "circb(x,y,r,col)", 7) for i in range(8):circb(110+i*8,76,i,i+8) text(6,88, "blt(x,y,img,u,v,\n w,h,[colkey])", 7) x,y=6,103 blt(x, y, 0, 0, 0, 16, 16) blt(x + math.sin(fc * 0.1) * 2 + 19, y, 0, 0, 0, 16, 16, 5) blt(x + 38, y, 0, 0, 0, -16, 16, 5) blt(x + 57, y, 0, 0, 0, 16, -16, 5) blt(x + 76, y, 0, 0, 0, -16, -16, 5) text(106, 88, "bltm(x,y,tm,u,v,\n w,h,[colkey])", 7) bltm(106, 103, 0, 0, 0, 11, 2, 2) text(6, 124, "text(x,y,s,col)",7) s = "Elapsed frame count is {}\n" "Current mouse position is ({},{})".format(fc,pyxel.mouse_x,pyxel.mouse_y) text(11,133,s,1)# shadow text(10,132,s,9) _,__=text(106, 124, "pal(col1,col2)", 4),pal()# test_pal2 if not self.clip_test:return clip() x,y,w,h=math.sin(fc*0.02)*39+40,math.sin(fc*0.03)*29+30,120,90 text(x,y-8,"clip(x,y,w,h)",14) rectb(x-1,y-1,w+2,h+2,14) clip(x,y,w,h)
def draw_background(self): """Draw background and grid.""" pyxel.cls(const.C_OCEAN) game_box = self.game_box - 1 # Draw lines for i in range(const.SIZE): position1 = i * const.BOX_SIZE position2 = position1 + const.BOX_SIZE - 1 col = const.C_OCEAN_LINE pyxel.line(x1=position1, y1=0, x2=position1, y2=game_box, col=col) pyxel.line(x1=position2, y1=0, x2=position2, y2=game_box, col=col) pyxel.line(x1=0, y1=position1, x2=game_box, y2=position1, col=col) pyxel.line(x1=0, y1=position2, x2=game_box, y2=position2, col=col) # Draw scorebox col = const.C_SCOREBOX height = game_box + const.SCORE_HEIGHT pyxel.rectb(x1=0, y1=game_box + 1, x2=game_box, y2=height, col=col)
def test_line(self, x, y): pyxel.text(x, y, "line(x1,y1,x2,y2,col)", 7) x += 4 y += 9 col = 5 for i in range(3): pyxel.line(x, y + i * 8, x + 48, y + i * 8, col) col += 1 for i in range(4): pyxel.line(x + i * 16, y, x + i * 16, y + 16, col) col += 1 for i in range(4): pyxel.line(x + i * 16, y, x + (3 - i) * 16, y + 16, col) col += 1
def draw(self): """ Draw the ship as a triangle pointing to the center """ # Get quadrant's limit line i_angle = quadrant(self.angle, False) l_angle = angle(math.floor(i_angle)) u_angle = angle(math.ceil(i_angle)) linea = [ [ self.app.center_x + math.cos(l_angle) * (self.app.radius - 6), self.app.center_y + math.sin(l_angle) * (self.app.radius - 6) ], [ self.app.center_x + math.cos(u_angle) * (self.app.radius - 6), self.app.center_y + math.sin(u_angle) * (self.app.radius - 6) ] ] # Get ship direction line (from the center to radius * 2) lineb = [[ self.app.center_x, self.app.center_y, ], [ self.app.center_x + (math.cos(self.angle) * (self.app.radius * 2)), self.app.center_y + (math.sin(self.angle) * (self.app.radius * 2)), ]] # The ship nose point is the intersection of the quadrant's limit line # and the ship direction line front_x, front_y = intersect(linea, lineb) # Ship's nose angle a = math.radians(15) # Ship's back points backr_x = front_x + (math.cos(self.angle - a) * 10) backr_y = front_y + (math.sin(self.angle - a) * 10) backl_x = front_x + (math.cos(self.angle + a) * 10) backl_y = front_y + (math.sin(self.angle + a) * 10) # Finally draw the ship pyxel.line(front_x, front_y, backr_x, backr_y, self.color) pyxel.line(backr_x, backr_y, backl_x, backl_y, self.color) pyxel.line(backl_x, backl_y, front_x, front_y, self.color)
def draw(self): """ Draw the obstacle as an hexagon portion from the current quadrant to the next """ tunnel_length = self.app.radius - self.app.inner_radius # Inner border rpos = pow(self.pos, 4) if rpos > 1: rpos = 1 radiusa = rpos * tunnel_length + self.app.inner_radius # Outter border posb = self.pos + self.height rposb = pow(posb, 4) if rposb > 1: rposb = 1 self._at_border = True radiusb = rposb * tunnel_length + self.app.inner_radius # 4 corners position calculation i = angle(self.quadrant) xaa = self.app.center_x + (math.cos(i) * radiusa) yaa = self.app.center_y + (math.sin(i) * radiusa) xba = self.app.center_x + (math.cos(i) * radiusb) yba = self.app.center_y + (math.sin(i) * radiusb) i = angle(self.quadrant + 1) xab = self.app.center_x + (math.cos(i) * radiusa) yab = self.app.center_y + (math.sin(i) * radiusa) xbb = self.app.center_x + (math.cos(i) * radiusb) ybb = self.app.center_y + (math.sin(i) * radiusb) # Finally draw the obstacle pyxel.line(xaa, yaa, xba, yba, self.color) pyxel.line(xba, yba, xbb, ybb, self.color) pyxel.line(xbb, ybb, xab, yab, self.color) pyxel.line(xab, yab, xaa, yaa, self.color)
def draw(self, ox, oy): walkState = self.state['nc']['walking'] if walkState and self.state['nc']['onSurface']: walkFrame = (self.walkingCounter // 6) % 12 self.px.blt( self.player.position[0] - 7 + ox, np.round(self.px.height - self.player.position[1] - 8, 2) + oy, 0, 1 + (15 + 2 + 1) * (1 + (walkState * self.flip * walkFrame % 12)), 1, self.flip * 15, 19) else: # Player is still self.px.blt(self.player.position[0] - 7 + ox, self.px.height - self.player.position[1] - 8 + oy, 0, 1, 1, self.flip * 15, 19) if self.state['nc']['emitter']: top = self.state['lookAt'] drawX = self.state['headCenter'][0] + ox drawY = px.height - self.state['headCenter'][1] + oy px.line(drawX + top[0] * 5, drawY + top[1] * 5, drawX + top[0] * self.state['emitterLength'], drawY + top[1] * self.state['emitterLength'], 12) if self.state['persistent']['holding']: drawX = self.state['headCenter'][0] + ox drawY = px.height - self.state['headCenter'][1] + oy px.line(drawX + self.state['lookAt'][0] * 5, drawY + self.state['lookAt'][1] * 5, drawX + self.state['lookAt'][0] * 15, drawY + self.state['lookAt'][1] * 15, 13) # draw charge line px.line( drawX + self.state['lookAt'][0] * 5, drawY + self.state['lookAt'][1] * 5, drawX + self.state['lookAt'][0] * (10 * self.state['emitterCharge'] / 100 + 5), drawY + self.state['lookAt'][1] * (10 * self.state['emitterCharge'] / 100 + 5), 2)
def draw_beam(self, angle: float, starttime: int): """Draw a beam at the angle for both eyes.""" eye1 = (self.player.x + 5, self.player.y + 4) eye2 = (self.player.x + 10, self.player.y + 4) self.raycast_has_collided = self.detect_raycast_colision(eye1, eye2) elapsed_frames = pyxel.frame_count - starttime color = 10 if 3 <= elapsed_frames < 6: color = 11 elif 6 <= elapsed_frames < 9: color = 3 elif 9 <= elapsed_frames < 12: color = 1 elif elapsed_frames >= 12: self.beam_angle = None self.locked = False return if self.raycast_has_collided: pyxel.line(eye1[0], eye1[1], eye1[0] + self.raycast_distance * cos(self.beam_angle), eye1[1] + self.raycast_distance * sin(self.beam_angle), color) pyxel.line(eye2[0], eye2[1], eye2[0] + self.raycast_distance * cos(self.beam_angle), eye2[1] + self.raycast_distance * sin(self.beam_angle), color) self.raycast_has_collided = False else: pyxel.line(eye1[0], eye1[1], eye1[0] + 1000 * cos(self.beam_angle), eye1[1] + 1000 * sin(self.beam_angle), color) pyxel.line(eye2[0], eye2[1], eye2[0] + 1000 * cos(self.beam_angle), eye2[1] + 1000 * sin(self.beam_angle), color)
def draw_box(self, coords, mask): # 4 lsb for walls walls = mask & 15 # north wall (1) if walls & self.north == self.north: pyxel.line(coords[0], coords[1], coords[0] + self.box_size, coords[1], 12) # east wall (2) if walls & self.east == self.east: pyxel.line(coords[0] + self.box_size, coords[1] + self.box_size, coords[0] + self.box_size, coords[1], 12) # west wall (8) if walls & self.west == self.west: pyxel.line(coords[0], coords[1] + self.box_size, coords[0], coords[1], 12) # south wall (4) if walls & self.south: pyxel.line(coords[0], coords[1] + self.box_size, coords[0] + self.box_size, coords[1] + self.box_size, 12) flags = mask >> 4 if flags == 2: pyxel.text(coords[0] + 2, coords[1] + 2, "@", 14)
def draw(self): if self.hit_frame: col = self.hit_anim[self.hit_frame] else: col = self.hp_color[self.hp] pyxel.circ(128,452,256,col[0]) pyxel.circ(128,464,256,col[1]) pyxel.circ(128,472,256,col[2]) pyxel.circ(128,475,256,col[3]) pyxel.circ(128,478,256,col[4]) for star in self.stars1: pyxel.line(star[0],star[1],star[0],star[1],5) for star in self.stars2: pyxel.line(star[0],star[1],star[0],star[1]+1,12) for star in self.stars3: pyxel.line(star[0],star[1],star[0],star[1]+1,7) self.earth.draw(11,220)
def draw(self, car): VEL_POS = (40, 200) GAS_POS = (90, 200) pyxel.circ(GAS_POS[0], GAS_POS[1], 15, 0) pyxel.circb(GAS_POS[0], GAS_POS[1], 16, 7) angle_gas = -math.pi * 7 / 8 + (6 / 320 * math.pi * car.fuel) pyxel.line(GAS_POS[0], GAS_POS[1], GAS_POS[0] + 8 * math.cos(angle_gas), GAS_POS[1] + 8 * math.sin(angle_gas), 9) pyxel.text(GAS_POS[0] + 10, GAS_POS[1] - 7, "F", 7) pyxel.text(GAS_POS[0] - 12, GAS_POS[1] - 7, "E", 7) if car.fuel <= 5 and car.fuel > 0: if int(pyxel.frame_count / 10) % 8 < 4: Sprite(1, (0, 0), (15, 15), 0).draw(GAS_POS[0] - 8, GAS_POS[1] - 17) elif car.fuel == 0: Sprite(1, (0, 0), (15, 15), 0).draw(GAS_POS[0] - 8, GAS_POS[1] - 17) pyxel.circ(VEL_POS[0], VEL_POS[1], 30, 0) pyxel.circb(VEL_POS[0], VEL_POS[1], 31, 7) pyxel.text(VEL_POS[0] - 28, VEL_POS[1] - 6, "0", 7) pyxel.text(VEL_POS[0] - 25, VEL_POS[1] - 15, "30", 7) pyxel.text(VEL_POS[0] - 15, VEL_POS[1] - 25, "70", 7) pyxel.text(VEL_POS[0] - 2, VEL_POS[1] - 28, "130", 7) pyxel.text(VEL_POS[0] + 10, VEL_POS[1] - 22, "150", 7) pyxel.text(VEL_POS[0] + 10, VEL_POS[1] - 22, "180", 7) pyxel.text(VEL_POS[0] + 15, VEL_POS[1] - 10, "210", 7) if (car.vel >= 0) or (abs(car.vel) < 1): pyxel.line( VEL_POS[0], VEL_POS[1], VEL_POS[0] + 20 * math.cos(math.pi + 0.1 + (math.pi / 250 * car.vel)), VEL_POS[1] + 25 * math.sin(math.pi + 0.1 + (math.pi / 250 * car.vel)), 8) else: pyxel.line( VEL_POS[0], VEL_POS[1], VEL_POS[0] + 20 * math.cos(math.pi + 0.1 + abs(math.pi / 200 * car.vel)), VEL_POS[1] + 25 * math.sin(math.pi + 0.1 + abs(math.pi / 200 * car.vel)), 8) pyxel.text(VEL_POS[0] + 5, VEL_POS[1] - 10, "R", 8)
def draw(self): # pyxel.cls(7) pyxel.cls(0) # print(self.player.moving) if not self.run: pyxel.text(map_size / 2, map_size / 2, "MiniGame", 7) pyxel.text(map_size / 2, map_size / 2 + 5, "space key to start", 7) if self.run: pyxel.circ(self.player.x, self.player.y, 5, 6) pyxel.circ(self.player.x, self.player.y, 4, 7) if self.player.moving == False: self.player.draw_shield() for enemy in self.enemies: # pyxel.blt(16,16,) pyxel.circ(enemy.x, enemy.y, 5, 8) pyxel.circ(enemy.x, enemy.y, 3, 0) pyxel.circ(enemy.x, enemy.y, 1, 8) for projectile in self.projectiles: pyxel.circ(projectile.x, projectile.y, 2, 9) pyxel.circ(projectile.x, projectile.y, 1, 7) pyxel.circ(pyxel.mouse_x, pyxel.mouse_y, 1, 6) pyxel.pset(pyxel.mouse_x, pyxel.mouse_y, 7) if self.debug: pyxel.line(self.player.x, self.player.y, pyxel.mouse_x, pyxel.mouse_y, 1) pyxel.line(pyxel.mouse_x, self.player.y, pyxel.mouse_x, pyxel.mouse_y, 3) pyxel.line(self.player.x, self.player.y, pyxel.mouse_x, self.player.y, 2) pyxel.text(5, 5, f'xlen: {pyxel.mouse_x - self.player.x}', 0) pyxel.text(5, 15, f'ylen: {self.player.y -pyxel.mouse_y}', 0) pyxel.text(5, 25, f'degrees: {self.player.shield_center}', 0) pyxel.text(5, 35, f'start: {self.player.shield_center - 45}', 0) pyxel.text(5, 45, f'end: {self.player.shield_center + 45}', 0) pyxel.text(5, 55, f'rad: {math.radians(self.player.shield_center)}', 0)
def draw(): pyxel.cls(pyxel.COLOR_BLACK) pyxel.line(0, 90, 240, 90, pyxel.COLOR_PEACH) pyxel.line(120, 0, 120, 180, pyxel.COLOR_PEACH) for body in space.bodies: for shape in body.shapes: if isinstance(shape, Circle): x, y = body.position + shape.offset color = getattr(shape, 'color', pyxel.COLOR_WHITE) pyxel.circ(x, y, shape.radius, color) elif isinstance(shape, Segment): ax, ay = body.position + shape.a bx, by = body.position + shape.b pyxel.line(ax, ay, bx, by, pyxel.COLOR_RED) elif isinstance(shape, Poly): color = getattr(shape, 'color', pyxel.COLOR_WHITE) for tri in group_tri(shape.get_vertices()): coords = [] for v in tri: x, y = v.rotated(body.angle) + body.position coords.extend((x, y)) pyxel.tri(*coords, color) pyxel.text(5, 6, "U(x, y) =", pyxel.COLOR_WHITE) inpt.draw_widgets() # Energia obj = space.player K = obj.kinetic_energy x, y = obj.position - (120, 90) y *= -1 K = obj.mass * obj.velocity.length**2 / 2 pyxel.text(5, 150, f"K: {K:5.1f}", pyxel.COLOR_WHITE) pyxel.text(5, 160, f"U: {U(x, y):5.1f}", pyxel.COLOR_WHITE) pyxel.text(5, 170, f"E: {K + U(x, y):5.1f}", pyxel.COLOR_WHITE)
import pyxel import math pyxel.init(200, 200) pyxel.cls(14) lineCounter = 0 distance = 20 for i in range(distance, 210 + distance, distance * 2): for j in range(distance, 210, int(distance * math.sqrt(3))): for k in range(0, 360, 60): kRadian = math.radians(k) shortLineLength = int(distance * 2 / 3 * math.sqrt(3)) if (lineCounter % 2 == 0): pyxel.line(i, j, i + shortLineLength * math.sin(kRadian), j + shortLineLength * math.cos(kRadian), 0) pyxel.line(i, j, i + distance * math.cos(kRadian), j + distance * math.sin(kRadian), 0) else: pyxel.line(i - distance, j, i - distance + shortLineLength * math.sin(kRadian), j + shortLineLength * math.cos(kRadian), 0) pyxel.line(i - distance, j, i - distance + distance * math.cos(kRadian), j + distance * math.sin(kRadian), 0) lineCounter += 1 pyxel.show()
def draw(self): pyxel.line(self.x1, self.y1, self.x2, self.y2, self.color)
def pintar(self): pyxel.line(self.linha.p1.x, self.linha.p1.y, self.linha.p2.x, self.linha.p2.y, 8)
def draw(): visited = [] queue = [] pyxel.cls(0) pyxel.text(0, 5, "Press 1, 2 or 3", 15) pyxel.text(0, 15, "to switch Node", 15) node = nodeSelector #Option of User if not default #Default settings node.xCount = len(node.nodes) node.x = 125 node.y = 10 node.xLeft = 0 visited.append(node) queue.append(node) while queue: curNode = queue.pop(0) xCount = 0 #Internal counter of Nodes of a given Node #Calulate length of a Node lenNode = len(curNode.nodes) if curNode.data != node.data: lenNode -= 1 #Length of Node - 1 as the parent node wont be in the same horizontal x axis as the other child connected nodes. #Refer to appendix 1 for xLeft and appendix 2 for newXSpacing #Calculating the childs spacing of a given curNode if lenNode != 0: temp = ( curNode.x - curNode.xLeft ) * 2 #Calculates parents spacing dynamically. get the curNode.x e.g. 1's is 125. Minus that with horizontal spacing, which gives half spacing of parent element as Nodes are located on the center of spacing, hence multiple by 2. newXSpacing = ( temp / lenNode ) #Calulate child spacing. ParentSpacing/numOfChild=ChildSpacing for n in curNode.nodes: if n not in visited: n.parent = curNode n.x = (xCount * newXSpacing) + ( newXSpacing / 2 ) #Calculating x axis location. (InternalCounter * SpacingsOfChild) calculates the margin left of the node block. (newXSpacing/2) centers the node within its block rather than floating left. #Add xLeft of Parent to x and also to xLeft. We have to loop through the visited as we need to get the stored data that was produced dynamically. n.xLeft = xCount * newXSpacing for element in visited: if element.data == curNode.data: n.x += element.xLeft n.xLeft += element.xLeft n.y = curNode.y + 25 #Add vertical spacing to each node visited.append(n) queue.append(n) xCount += 1 #DRAWINGS #DRAW LINES FIRST for element in visited: if element.parent is not None: x1 = element.parent.x y1 = element.parent.y x2 = element.x y2 = element.y pyxel.line(x1, y1, x2, y2, 14) #DRAW CIRCLES for element in visited: pyxel.circ(element.x, element.y, 6, 12) pyxel.text(element.x - (len(element.data) * 1.5), element.y - 1, element.data, 2) pyxel.text(0, 125, 'Visited Nodes', 15) pyxel.text(0, 135, str(visited), 15)
def draw(): pyxel.cls(pyxel.COLOR_BLACK) colors = islice(cycle(range(1, 16)), pyxel.frame_count % 15, None) for cmd, col in zip(cmds, colors): pyxel.line(*cmd, col)
def drawLine(body, segment): x1, y1 = segment.a.rotated(body.angle) + body.position x2, y2 = segment.b.rotated(body.angle) + body.position px.line(x1, 256-y1, x2, 256-y2, 9)
pyxel.init(200, 150) # Céu: pinta a tela de azul # cls(cor) pyxel.cls(12) # Sol: desenha um círculo de raio 15px em (50px, 25px) # circ(x, y, raio, cor) pyxel.circ(50, 25, 15, 10) # Chão: retângulo na parte de baixo do sistema de coordenadas # rect(x, y, largura, altura, cor) pyxel.rect(0, 120, 200, 30, 3) for x in range(0, 230, 4): pyxel.line(x - 30, 150, x, 120, 11) # Cerca pyxel.rect(0, 135, 200, 3, 2) pyxel.rect(0, 145, 200, 3, 2) for x in range(0, 200, 15): pyxel.rect(x, 130, 3, 20, 2) # Casa pyxel.rect(90, 90, 70, 35, 15) # Porta pyxel.rect(97, 100, 15, 25, 2) pyxel.circ(99, 112, 1, 1) # Janelas
def draw_grid(self): for y in range(Box.HEIGHT): pyxel.line(0, Block.Size*y, Block.Size*Box.WIDTH, Block.Size*y, 12) for x in range(Box.WIDTH): pyxel.line(Block.Size*x, 0, Block.Size*x, Block.Size*Box.HEIGHT, 12)
def draw(self): pyxel.cls(1) self.draw_points() offset = 0 offy = 30 offx = 10 pyxel.line(95, 50, 95, 220, 8) #left pyxel.line(155, 50, 155, 220, 8) #right pyxel.line(95, 220, 155, 220, 8) # button pyxel.line(95, 221, 155, 221, 8) pyxel.line(95, 50, 105, 50, 8) pyxel.line(145, 50, 155, 50, 8) pyxel.line(105, 50, 105, 40, 8) pyxel.line(145, 50, 145, 40, 8) if self.stack.size() == 0: pyxel.text( 5, 10, 'This is an empty candy jar, Can put up to five candies', 10) pyxel.text( 5, 17, 'Try your click your mouse left button to put a new candy', 11) if self.stack.size() == 1: pyxel.text(75, 195, 'TOP:', 6) pyxel.text(5, 15, 'Now you have a candy.', 13) if self.stack.size() == 2: pyxel.text(75, 165, 'TOP:', 6) pyxel.text(5, 15, 'Now you have 2 candies.', 13) if self.stack.size() == 3: pyxel.text(75, 135, 'TOP:', 6) pyxel.text(5, 15, 'Now you have 3 candies.', 14) if self.stack.size() == 4: pyxel.text(75, 105, 'TOP:', 6) pyxel.text(5, 15, 'Now you have 4 candies.', 13) if self.stack.size() == 5: pyxel.line(105, 40, 145, 40, 7) pyxel.text(75, 75, 'TOP:', 6) pyxel.text(5, 5, 'Now you have 5 candies. This candy jar is full', 11) pyxel.text(5, 15, 'Wanna eat candies? Try to press P', 10) for value in self.stack.stack: myItem = Item(125 + offx, 230 - offy, value) #1 myItem.draw() # pyxel.text(145, 230-offy, 'Use push()', self.color) offset = offset + 1 offy = offy + 30 if offx == 10: offx = offx - 10 else: offx = offx + 10 if offset > 7: break
def __on_draw(self): pyxel.cls(WIDGET_BACKGROUND_COLOR) pyxel.rect(0, 0, 240, 9, WIDGET_PANEL_COLOR) pyxel.line(0, 9, 239, 9, WIDGET_SHADOW_COLOR) pyxel.text(93, 2, self.help_message_var, HELP_MESSAGE_COLOR) self.help_message_var = ""
def draw_beams(self): ''' Draws laser beams as pyxel lines. ''' for laser_beam in self.beams: pyxel.line(laser_beam[0], laser_beam[1], laser_beam[0], laser_beam[1] + 2, 8)
def draw(self): px.line(self.pos.x, self.pos.y, self.center.x, self.center.y, 9) px.pix(self.pos.x, self.pos.y, 8)