def test_color__name_str_arg_from_colordict(self): """Ensures Color objects can be created using str names from the THECOLORS dict.""" for name, values in THECOLORS.items(): color = pygame.Color(name) self.assertEqual(color.r, values[0]) self.assertEqual(color.g, values[1]) self.assertEqual(color.b, values[2]) self.assertEqual(color.a, values[3])
def simplified_color_table(): """De-dupe the colour table.""" by_hex = {} for name, color in THECOLORS.items(): if name[-1].isdigit(): continue html = html_color(color) by_hex.setdefault(html, []).append(name) return { ' / '.join(sorted(names)): THECOLORS[names[0]] for names in by_hex.values() }
from core.sim_engine import gui_get from core.world_patch_block import Block, Patch, World def is_acceptable_color(rgb): """ Require reasonably bright colors (sum_rgb >= 150) for which r, g, and b are not too close to each other, i.e., not too close to gray. The numbers 150 and 100 are arbitrary. """ sum_rgb = sum(rgb) avg_rgb = sum_rgb / 3 return avg_rgb >= 160 and sum(abs(avg_rgb - x) for x in rgb) > 100 # These are colors defined by pygame that satisfy is_acceptable_color() above. PYGAME_COLORS = [(name, rgba[:3]) for (name, rgba) in THECOLORS.items() if is_acceptable_color(rgba[:3])] # These are NetLogo primary colors -- more or less. NETLOGO_PRIMARY_COLORS = [(color_name, Color(color_name)) for color_name in [ 'gray', 'red', 'orange', 'brown', 'yellow', 'green', 'limegreen', 'turquoise', 'cyan', 'skyblue3', 'blue', 'violet', 'magenta', 'pink' ]] SQRT_2 = sqrt(2) class Agent(Block): color_palette = choice([NETLOGO_PRIMARY_COLORS, PYGAME_COLORS])
from core.pairs import Pixel_xy, RowCol, Velocity, XY, heading_and_speed_to_velocity from core.world_patch_block import Block, Patch, World def is_acceptable_color(rgb): """ Require reasonably bright colors (sum_rgb >= 150) for which r, g, and b are not too close to each other, i.e., not too close to gray. The numbers 150 and 100 are arbitrary. """ sum_rgb = sum(rgb) avg_rgb = sum_rgb/3 return avg_rgb >= 160 and sum(abs(avg_rgb-x) for x in rgb) > 100 # These are colors defined by pygame that satisfy is_acceptable_color() above. PYGAME_COLORS = [(name, rgba[:3]) for (name, rgba) in THECOLORS.items() if is_acceptable_color(rgba[:3])] # These are NetLogo primary colors -- more or less. NETLOGO_PRIMARY_COLORS = [(color_name, Color(color_name)) for color_name in ['gray', 'red', 'orange', 'brown', 'yellow', 'green', 'limegreen', 'turquoise', 'cyan', 'skyblue3', 'blue', 'violet', 'magenta', 'pink']] SQRT_2 = sqrt(2) class Agent(Block): color_palette = choice([NETLOGO_PRIMARY_COLORS, PYGAME_COLORS]) half_patch_pixel = pairs.Pixel_xy((HALF_PATCH_SIZE(), HALF_PATCH_SIZE()))