def draw_scalar_field_circles_color(screen, field, spectrum): for i in range(field.a): for j in range(field.b): if field.valid_hex(i, j): pos = hex_to_screen_space(hexvex.Vex(i, j)) pygame.draw.circle(screen, spectrum.retrieve(field.hexes[i][j]), (int(pos.x), int(pos.y)), int(hex_draw_radius))
def draw_scalar_field_rects(screen, field, spectrum): for i in range(field.a): for j in range(field.b): if field.valid_hex(i, j): pos = hex_to_screen_space(hexvex.Vex(i, j)) pygame.draw.rect( screen, spectrum.retrieve(field.hexes[i][j]), pygame.Rect(int(pos.x - hex_draw_radius), int(pos.y - hex_draw_radius), int(hex_draw_radius * 2), int(hex_draw_radius * 2)))
def draw_vector_field(screen, field, max_size_magnitude): for i in range(field.a): for j in range(field.b): if field.valid_hex(i, j): # (magnitude, argument) polar = field.hexes[i][j].Vector2().as_polar() arrow = get_arrow((255, 255, 255), polar[1], polar[0] / max_size_magnitude) screen.blit( arrow, hex_to_screen_space(hexvex.Vex(i, j)) - (arrow.get_width() / 2, arrow.get_height() / 2))
def draw_scalar_field_circles_radii(screen, field, scale_start, scale_end, max_radius, color=(0, 0, 0)): for i in range(field.a): for j in range(field.b): if field.valid_hex(i, j): radius = max_radius * \ (field.hexes[i][j]-scale_start) / (scale_end-scale_start) radius = clamp(radius, 0, max_radius) pos = hex_to_screen_space(hexvex.Vex(i, j)) pygame.draw.circle(screen, color, (int(pos.x), int(pos.y)), int(radius))
def gen_origin(a, b): global grid_origin grid_origin = game_rect.center - \ hexvex.Vex(a-1, b-1).Vector2() / 2 * cell_parameter
def draw_mask_back_hexes(screen, mask, color): for i in range(mask.a): for j in range(mask.b): if mask.hexes[i][j]: draw_back_hexagon(hex_to_screen_space(hexvex.Vex(i, j)), color)
def draw_scalar_field_back_hexes(screen, field, spectrum): for i in range(field.a): for j in range(field.b): if field.valid_hex(i, j): draw_back_hexagon(hex_to_screen_space(hexvex.Vex(i, j)), spectrum.retrieve(field.hexes[i][j]))
import math from pygame import freetype screen_width = 1000 screen_height = 700 hex_radius = 7 hex_height = 2 * hex_radius hex_width = 2 * hex_radius * hexvex.sin60 cell_parameter = hex_width padding = 0.15 hex_draw_radius = hex_radius - padding half_hex = pygame.Vector2(hex_width / 2, hex_height / 2) half_tile = hexvex.Vex(0.5, 0.5) # The two are different! a hex (bounding box) is slightly larger than a tile, # since hexes (' bounding boxes) cross into each other game_rect = pygame.Rect(80, 0, screen_width - 80, screen_height) sidebar_rect = pygame.Rect(0, 0, 80, screen_height) def gen_origin(a, b): global grid_origin grid_origin = game_rect.center - \ hexvex.Vex(a-1, b-1).Vector2() / 2 * cell_parameter # Translated half a cell to the positive since hexagons are centred