def test_gradient(self): self._assert_are_colors_equal((10, 20, 40), gradient(0.0, 0.0, 1.0, (10, 20, 40), (0, 128, 240))) self._assert_are_colors_equal((0, 128, 240), gradient(1.0, 0.0, 1.0, (10, 20, 40), (0, 128, 240))) self._assert_are_colors_equal((5, 74, 140), gradient(0.5, 0.0, 1.0, (10, 20, 40), (0, 128, 240)))
def draw_temperature_levels(world, target, black_and_white=False): width = world.width height = world.height if black_and_white: low = world.temperature_thresholds()[0][1] high = world.temperature_thresholds()[5][1] for y in range(height): for x in range(width): t = world.temperature_at((x, y)) if t <= low: target.set_pixel(x, y, (0, 0, 0, 255)) elif t >= high: target.set_pixel(x, y, (255, 255, 255, 255)) else: target.set_pixel(x, y, gradient(t, low, high, (0, 0, 0), (255, 255, 255))) else: for y in range(height): for x in range(width): if world.is_temperature_polar((x, y)): target.set_pixel(x, y, (0, 0, 255, 255)) elif world.is_temperature_alpine((x, y)): target.set_pixel(x, y, (42, 0, 213, 255)) elif world.is_temperature_boreal((x, y)): target.set_pixel(x, y, (85, 0, 170, 255)) elif world.is_temperature_cool((x, y)): target.set_pixel(x, y, (128, 0, 128, 255)) elif world.is_temperature_warm((x, y)): target.set_pixel(x, y, (170, 0, 85, 255)) elif world.is_temperature_subtropical((x, y)): target.set_pixel(x, y, (213, 0, 42, 255)) elif world.is_temperature_tropical((x, y)): target.set_pixel(x, y, (255, 0, 0, 255))
def draw_precipitation(world, target, black_and_white=False): # FIXME we are drawing humidity, not precipitations width = world.width height = world.height if black_and_white: low = None high = None for y in range(height): for x in range(width): p = world.precipitations_at((x, y)) if low is None or p < low: low = p if high is None or p > high: high = p for y in range(height): for x in range(width): p = world.precipitations_at((x, y)) if p <= low: target.set_pixel(x, y, (0, 0, 0, 255)) elif p >= high: target.set_pixel(x, y, (255, 255, 255, 255)) else: target.set_pixel( x, y, gradient(p, low, high, (0, 0, 0), (255, 255, 255))) else: for y in range(height): for x in range(width): if world.is_humidity_superarid((x, y)): target.set_pixel(x, y, (0, 32, 32, 255)) elif world.is_humidity_perarid((x, y)): target.set_pixel(x, y, (0, 64, 64, 255)) elif world.is_humidity_arid((x, y)): target.set_pixel(x, y, (0, 96, 96, 255)) elif world.is_humidity_semiarid((x, y)): target.set_pixel(x, y, (0, 128, 128, 255)) elif world.is_humidity_subhumid((x, y)): target.set_pixel(x, y, (0, 160, 160, 255)) elif world.is_humidity_humid((x, y)): target.set_pixel(x, y, (0, 192, 192, 255)) elif world.is_humidity_perhumid((x, y)): target.set_pixel(x, y, (0, 224, 224, 255)) elif world.is_humidity_superhumid((x, y)): target.set_pixel(x, y, (0, 255, 255, 255))
def draw_precipitation(world, target, black_and_white=False): # FIXME we are drawing humidity, not precipitations width = world.width height = world.height if black_and_white: low = None high = None for y in range(height): for x in range(width): p = world.precipitations_at((x, y)) if low is None or p < low: low = p if high is None or p > high: high = p for y in range(height): for x in range(width): p = world.precipitations_at((x, y)) if p <= low: target.set_pixel(x, y, (0, 0, 0, 255)) elif p >= high: target.set_pixel(x, y, (255, 255, 255, 255)) else: target.set_pixel(x, y, gradient(p, low, high, (0, 0, 0), (255, 255, 255))) else: for y in range(height): for x in range(width): if world.is_humidity_superarid((x, y)): target.set_pixel(x, y, (0, 32, 32, 255)) elif world.is_humidity_perarid((x, y)): target.set_pixel(x, y, (0, 64, 64, 255)) elif world.is_humidity_arid((x, y)): target.set_pixel(x, y, (0, 96, 96, 255)) elif world.is_humidity_semiarid((x, y)): target.set_pixel(x, y, (0, 128, 128, 255)) elif world.is_humidity_subhumid((x, y)): target.set_pixel(x, y, (0, 160, 160, 255)) elif world.is_humidity_humid((x, y)): target.set_pixel(x, y, (0, 192, 192, 255)) elif world.is_humidity_perhumid((x, y)): target.set_pixel(x, y, (0, 224, 224, 255)) elif world.is_humidity_superhumid((x, y)): target.set_pixel(x, y, (0, 255, 255, 255))
def draw_temperature_levels(world, target, black_and_white=False): width = world.width height = world.height if black_and_white: low = world.temperature_thresholds()[0][1] high = world.temperature_thresholds()[5][1] for y in range(height): for x in range(width): t = world.temperature_at((x, y)) if t <= low: target.set_pixel(x, y, (0, 0, 0, 255)) elif t >= high: target.set_pixel(x, y, (255, 255, 255, 255)) else: target.set_pixel( x, y, gradient(t, low, high, (0, 0, 0), (255, 255, 255))) else: for y in range(height): for x in range(width): if world.is_temperature_polar((x, y)): target.set_pixel(x, y, (0, 0, 255, 255)) elif world.is_temperature_alpine((x, y)): target.set_pixel(x, y, (42, 0, 213, 255)) elif world.is_temperature_boreal((x, y)): target.set_pixel(x, y, (85, 0, 170, 255)) elif world.is_temperature_cool((x, y)): target.set_pixel(x, y, (128, 0, 128, 255)) elif world.is_temperature_warm((x, y)): target.set_pixel(x, y, (170, 0, 85, 255)) elif world.is_temperature_subtropical((x, y)): target.set_pixel(x, y, (213, 0, 42, 255)) elif world.is_temperature_tropical((x, y)): target.set_pixel(x, y, (255, 0, 0, 255))