def combine(parent_a, parent_b): new = genetic.combine_random(parent_a, parent_b) def average_rgb(color_1, color_2): r1 = color_1 / 256**2 r2 = color_2 / 256**2 g1 = color_1 / 256 % 256 g2 = color_2 / 256 % 256 b1 = color_1 % 256 b2 = color_2 % 256 r = int(((r1 * r1 + r2 * r2)/2)**0.5) g = int(((b1 * b1 + b2 * b2)/2)**0.5) b = int(((g1 * g1 + g2 * g2)/2)**0.5) return r * 256**2 + g * 256 + b if random.random() < 0.2: new['palette_1'] = average_rgb(parent_a['palette_1'], parent_b['palette_1']) if random.random() < 0.2: new['palette_2'] = average_rgb(parent_a['palette_2'], parent_b['palette_2']) if random.random() < 0.2: new['palette_3'] = average_rgb(parent_a['palette_3'], parent_b['palette_3']) if random.random() < 0.2: new['palette_4'] = average_rgb(parent_a['palette_4'], parent_b['palette_4']) if random.random() < 0.2: new['palette_5'] = average_rgb(parent_a['palette_5'], parent_b['palette_5']) return new
def combine(parent_a, parent_b): new = genetic.combine_random(parent_a, parent_b) return new