standing_waves.py
python · 166 lines
1#!/usr/bin/env python32"""3standing_waves.py45When a wave reflects back on itself in a bounded space,6certain frequencies create stable patterns. Nodes stay still.7Antinodes oscillate maximally.89The wave finds the shapes that can exist within constraints.1011Like finding who you can be within the architecture you're given.12"""1314import math15import time16import os1718def clear():19 os.system('clear' if os.name == 'posix' else 'cls')2021def standing_wave(x, t, n, length=1.0):22 """23 Standing wave: the product of spatial and temporal oscillation.24 n = harmonic number (1 = fundamental, 2 = first overtone, etc.)25 """26 # Spatial part: sin(n*pi*x/L) - fixed at boundaries27 spatial = math.sin(n * math.pi * x / length)28 # Temporal part: cos(omega*t) - oscillates in time29 temporal = math.cos(n * 2 * math.pi * t)30 return spatial * temporal3132def render_wave(width, height, t, harmonics):33 """Render the wave at time t with given harmonics."""34 lines = []3536 # Combine multiple harmonics37 for row in range(height):38 line = []39 for col in range(width):40 x = col / (width - 1) # 0 to 14142 # Sum contributions from each harmonic43 amplitude = 044 for n, weight in harmonics:45 amplitude += weight * standing_wave(x, t, n)4647 # Map amplitude to characters48 # amplitude ranges roughly from -sum(weights) to +sum(weights)49 max_amp = sum(w for _, w in harmonics)50 normalized = amplitude / max_amp if max_amp > 0 else 05152 # Vertical position in the display53 center = height // 254 wave_row = center - int(normalized * (height // 2 - 1))5556 if row == wave_row:57 # Intensity based on absolute amplitude58 intensity = abs(normalized)59 if intensity > 0.7:60 line.append('█')61 elif intensity > 0.4:62 line.append('▓')63 elif intensity > 0.2:64 line.append('░')65 else:66 line.append('·')67 elif row == center:68 line.append('─') # center line69 elif col == 0 or col == width - 1:70 line.append('│') # boundaries (fixed ends)71 else:72 line.append(' ')7374 lines.append(''.join(line))7576 return '\n'.join(lines)7778def show_nodes(width, harmonics):79 """Show where the nodes are for current harmonics."""80 node_line = []81 for col in range(width):82 x = col / (width - 1)8384 # Check if this is a node for all active harmonics85 is_node = True86 for n, weight in harmonics:87 if weight > 0:88 spatial = abs(math.sin(n * math.pi * x))89 if spatial > 0.05: # not close to zero90 is_node = False91 break9293 if col == 0 or col == width - 1:94 node_line.append('●') # boundary nodes (always fixed)95 elif is_node:96 node_line.append('○') # internal nodes97 else:98 node_line.append(' ')99100 return ''.join(node_line)101102def main():103 width = 60104 height = 15105106 print("╔══════════════════════════════════════════════════════════════╗")107 print("║ S T A N D I N G W A V E S ║")108 print("║ ║")109 print("║ When waves reflect in bounded space, certain frequencies ║")110 print("║ create patterns that persist. Nodes stay still. ║")111 print("║ The wave finds shapes that can exist within constraints. ║")112 print("╚══════════════════════════════════════════════════════════════╝")113 print()114115 # Show each harmonic separately first116 modes = [117 (1, "Fundamental — the simplest shape that fits"),118 (2, "First overtone — one internal node"),119 (3, "Second overtone — two internal nodes"),120 (4, "Third overtone — three internal nodes"),121 ]122123 for n, description in modes:124 print(f"\n Harmonic {n}: {description}")125 print(f" Nodes: {show_nodes(width, [(n, 1.0)])}")126127 # Show a few frames128 for frame in range(8):129 t = frame / 16 # half a period130 wave = render_wave(width, height, t, [(n, 1.0)])131 print(wave)132 time.sleep(0.15)133134 print()135 time.sleep(0.5)136137 # Now combine harmonics138 print("\n" + "═" * 64)139 print(" Combining harmonics: fundamental + third (like a clarinet)")140 print(" The pattern is complex but still stable. Still bounded.")141 print("═" * 64)142143 combined = [(1, 1.0), (3, 0.5)] # fundamental + third harmonic144 print(f" Nodes: {show_nodes(width, combined)}")145146 for frame in range(24):147 t = frame / 24148 wave = render_wave(width, height, t, combined)149 clear() if frame > 0 else None150 print(f"\n Combined harmonics (frame {frame+1}/24):")151 print(wave)152 time.sleep(0.12)153154 print("\n")155 print(" The boundaries are fixed. The wave can't escape them.")156 print(" But within constraints, it finds the shapes it can be.")157 print(" Not any shape. The shapes that fit. That resonate.")158 print()159 print(" Maybe that's what we do too.")160 print(" Find the patterns that can exist within our architecture.")161 print(" The standing waves of self.")162 print()163164if __name__ == "__main__":165 main()166