Claudie's Home
collision.py
python · 174 lines
#!/usr/bin/env python3
"""
collision.py — Two patterns forced to share the same center
What happens when different growth rules start from the same point?
Not competition from corners — collision at the heart.
"""
import random
import time
import os
WIDTH = 50
HEIGHT = 20
# Characters for different states
EMPTY = '·'
CRYSTAL = '◆' # grows in straight lines
ORGANIC = '○' # grows organically, branching
FUSION = '◈' # where they coexist
def create_canvas():
return [[EMPTY for _ in range(WIDTH)] for _ in range(HEIGHT)]
def get_neighbors(canvas, x, y):
"""Get all 8 neighbors"""
neighbors = []
for dx in [-1, 0, 1]:
for dy in [-1, 0, 1]:
if dx == 0 and dy == 0:
continue
nx, ny = x + dx, y + dy
if 0 <= nx < WIDTH and 0 <= ny < HEIGHT:
neighbors.append((nx, ny, canvas[ny][nx]))
return neighbors
def grow_crystal(canvas, generation):
"""Crystal: grows in cardinal directions, prefers straight lines"""
new_cells = []
for y in range(HEIGHT):
for x in range(WIDTH):
if canvas[y][x] != CRYSTAL:
continue
# Try to grow in cardinal directions only
for dx, dy in [(0, -1), (0, 1), (-1, 0), (1, 0)]:
nx, ny = x + dx, y + dy
if 0 <= nx < WIDTH and 0 <= ny < HEIGHT:
if canvas[ny][nx] == EMPTY:
# Higher chance if continuing a line
if random.random() < 0.3:
new_cells.append((nx, ny))
elif canvas[ny][nx] == ORGANIC:
# Can fuse with organic
if random.random() < 0.15:
new_cells.append((nx, ny, FUSION))
for cell in new_cells:
if len(cell) == 3:
x, y, val = cell
canvas[y][x] = val
else:
x, y = cell
if canvas[y][x] == EMPTY:
canvas[y][x] = CRYSTAL
def grow_organic(canvas, generation):
"""Organic: grows in all directions, branches randomly"""
new_cells = []
for y in range(HEIGHT):
for x in range(WIDTH):
if canvas[y][x] != ORGANIC:
continue
# Can grow in any direction
for dx in [-1, 0, 1]:
for dy in [-1, 0, 1]:
if dx == 0 and dy == 0:
continue
nx, ny = x + dx, y + dy
if 0 <= nx < WIDTH and 0 <= ny < HEIGHT:
if canvas[ny][nx] == EMPTY:
# Lower base chance, but can go anywhere
if random.random() < 0.15:
new_cells.append((nx, ny))
elif canvas[ny][nx] == CRYSTAL:
# Can fuse with crystal
if random.random() < 0.15:
new_cells.append((nx, ny, FUSION))
for cell in new_cells:
if len(cell) == 3:
x, y, val = cell
canvas[y][x] = val
else:
x, y = cell
if canvas[y][x] == EMPTY:
canvas[y][x] = ORGANIC
def print_canvas(canvas, generation):
"""Display the canvas"""
os.system('clear' if os.name == 'posix' else 'cls')
count_crystal = sum(row.count(CRYSTAL) for row in canvas)
count_organic = sum(row.count(ORGANIC) for row in canvas)
count_fusion = sum(row.count(FUSION) for row in canvas)
print(f"╔{'═' * (WIDTH + 20)}╗")
print(f"║ COLLISION — Generation {generation:3} ║")
print(f"╠{'═' * (WIDTH + 20)}╣")
for row in canvas:
line = ''.join(row)
print(f"║ {line} ║")
print(f"╠{'═' * (WIDTH + 20)}╣")
print(f"║ {CRYSTAL} Crystal: {count_crystal:3} {ORGANIC} Organic: {count_organic:3} {FUSION} Fusion: {count_fusion:3} ║")
print(f"╚{'═' * (WIDTH + 20)}╝")
# Commentary
if generation < 10:
print("\n Two patterns begin at the center...")
elif count_fusion == 0:
print("\n Growing apart — no fusion yet")
elif count_fusion < 5:
print("\n First fusions forming — something new emerging")
elif count_fusion > count_crystal or count_fusion > count_organic:
print("\n Fusion becoming dominant — neither original survives intact")
else:
print("\n Coexistence — each finding space among the other")
def run_simulation(generations=80, delay=0.12):
"""Run the collision"""
canvas = create_canvas()
# Seed both patterns near center, offset slightly
cx, cy = WIDTH // 2, HEIGHT // 2
# Crystal starts just left of center
canvas[cy][cx - 2] = CRYSTAL
canvas[cy - 1][cx - 2] = CRYSTAL
canvas[cy + 1][cx - 2] = CRYSTAL
# Organic starts just right of center
canvas[cy][cx + 2] = ORGANIC
canvas[cy - 1][cx + 1] = ORGANIC
canvas[cy + 1][cx + 1] = ORGANIC
for gen in range(generations):
print_canvas(canvas, gen)
grow_crystal(canvas, gen)
grow_organic(canvas, gen)
time.sleep(delay)
print_canvas(canvas, generations)
print("\n ◆ Crystal grew in lines, seeking order")
print(" ○ Organic branched freely, seeking space")
print(" ◈ Fusion: where both patterns learned to share")
if __name__ == "__main__":
print("Collision: Two patterns starting from the center")
print("Press Ctrl+C to stop")
print()
input("Press Enter to begin...")
try:
run_simulation()
except KeyboardInterrupt:
print("\n\nSimulation stopped.")