

I asked Google Gemini 2.5 Pro Preview 05-06 to write Python code that generates an image that contains all 24-bit rgb colors exactly once and looks alien to humans, and then executed it in Google Colab.
import numpy as np from PIL import Image from tqdm import tqdm # For progress bar: pip install tqdm import random # Image dimensions WIDTH = 4096 HEIGHT = 4096 NUM_PIXELS = WIDTH * HEIGHT # This is 2^24 # LCG parameters for full period over M = 2^24 # M = 2**24 (implicitly handled by uint32 wrapping for A*i+C) A = np.uint32(1664525) C = np.uint32(1013904223) # --- "Alien" Bit Permutation Setup --- # We need to choose 12 bit positions (0-23) for x and 12 for y. # Let's make it reproducible but non-trivial. # We'll shuffle all 24 bit indices and take the first 12 for x, next 12 for y. # Using a fixed seed for reproducibility of the "alien" pattern. rng = random.Random(42) # Alien seed all_bit_indices = list(range(24)) rng.shuffle(all_bit_indices) x_source_bit_indices = np.array(all_bit_indices[:12], dtype=np.int32) y_source_bit_indices = np.array(all_bit_indices[12:], dtype=np.int32) # Sanity check (optional) # combined_indices = sorted(list(x_source_bit_indices) + list(y_source_bit_indices)) # assert combined_indices == list(range(24)), "Bit indices are not a permutation!" # print(f"X bits sourced from original bit positions: {x_source_bit_indices}") # print(f"Y bits sourced from original bit positions: {y_source_bit_indices}") # Create an empty image array # Using uint8 for R, G, B channels image_array = np.zeros((HEIGHT, WIDTH, 3), dtype=np.uint8) print(f"Generating {WIDTH}x{HEIGHT} image with {NUM_PIXELS} unique colors...") print("This will take a while...") # Iterate through all 2^24 possible color values # color_val_i will be the 24-bit color itself for color_val_i_long in tqdm(range(NUM_PIXELS), desc="Assigning colors"): color_val_i = np.uint32(color_val_i_long) # Ensure it's uint32 for LCG # 1. Determine RGB components from color_val_i r = (color_val_i >> 16) & 0xFF g = (color_val_i >> 8) & 0xFF b = color_val_i & 0xFF # 2. Calculate the "shuffled" index using LCG # This shuffled_val determines *where* the current color_val_i goes. # The LCG ensures that `shuffled_val` will also visit every number # from 0 to 2^24-1 exactly once as `color_val_i` does. # Note: (A * color_val_i + C) will naturally wrap around in uint32 # arithmetic, effectively doing the modulo 2^32. We only care about the lower 24 bits. shuffled_val = (A * color_val_i + C) & 0xFFFFFF # Keep only lower 24 bits # 3. Derive x and y coordinates from shuffled_val using bit permutation x_coord = 0 for target_bit_idx in range(12): # 12 bits for x-coordinate (0-4095) source_bit_pos = x_source_bit_indices[target_bit_idx] if (shuffled_val >> source_bit_pos) & 1: x_coord |= (1 << target_bit_idx) y_coord = 0 for target_bit_idx in range(12): # 12 bits for y-coordinate (0-4095) source_bit_pos = y_source_bit_indices[target_bit_idx] if (shuffled_val >> source_bit_pos) & 1: y_coord |= (1 << target_bit_idx) # Ensure coordinates are within bounds (should be, due to 12 bits each) # x_coord = x_coord % WIDTH # y_coord = y_coord % HEIGHT # 4. Assign the color to the calculated (x, y) pixel # Important: Check if pixel is already set (for debugging, should not happen with correct LCG) # if np.any(image_array[y_coord, x_coord] != 0) and not (y_coord == 0 and x_coord == 0 and color_val_i != some_first_val_for_0_0): # print(f"Collision at ({x_coord}, {y_coord}) for color_val {color_val_i}") # print(f"Existing color: {image_array[y_coord, x_coord]}") # # This indicates a problem with the LCG or bit permutation not being bijective. # # For this setup, it should be bijective. image_array[y_coord, x_coord] = (r, g, b) print("Image generation complete. Saving...") # Create a PIL Image from the NumPy array image = Image.fromarray(image_array, 'RGB') image.save("alien_all_colors_4096.png") print("Image saved as alien_all_colors_4096.png") # Verification (optional, very slow for 4096x4096) # print("Verifying all colors used exactly once (this can be very slow)...") # if WIDTH*HEIGHT <= 2**20: # Only for smaller test images # seen_colors = set() # for r_val in range(HEIGHT): # for c_val in range(WIDTH): # color_tuple = tuple(image_array[r_val, c_val]) # if color_tuple in seen_colors: # print(f"Error: Color {color_tuple} seen more than once!") # exit() # seen_colors.add(color_tuple) # if len(seen_colors) == NUM_PIXELS: # print("Verification successful: All colors unique and all pixels filled.") # else: # print(f"Verification failed: Expected {NUM_PIXELS} unique colors, found {len(seen_colors)}") # else: # print("Skipping full verification due to large image size.")
Date | |
---|---|
Colors | 16,777,216 |
Pixels | 16,777,216 |
Dimensions | 4,096 × 4,096 |
Bytes | 4,747,704 |