Por qué los saltos al azar dibujan un triángulo perfecto
Salta a mitad de camino hacia un vértice al azar, una y otra vez. Del puro azar surge un fractal perfecto.
Se reproduce desde YouTube tras hacer clic.
Pruébalo: cambia la regla
Puro azar, una regla: el triángulo de Sierpiński, tres copias de sí mismo a la mitad de tamaño.
Por qué funciona
Elige al azar uno de los tres vértices de un triángulo y salta a mitad de camino hacia él. Marca el punto y repite. Los saltos son puro azar, pero tras unos miles aparece el triángulo de Sierpiński: un triángulo con triángulos recortados, a todas las escalas.
xₖ₊₁ = xₖ + r · (vértice − xₖ)triángulo: r = 1/2pentágono: r ≈ 0,618hexágono: r = 2/3
Constrúyelo tú
Python 3 · numpy · matplotlib60 000 saltos al azar a mitad de camino hacia un vértice, coloreados según el vértice.
"""Chaos game: jump a part r of the way to a random corner of a polygon, again and again.
Run: python chaos-game.py (needs: pip install numpy matplotlib)
"""
import numpy as np
import matplotlib.pyplot as plt
plt.style.use("dark_background")
corners, r, no_repeat = 3, 0.5, False # triangle, halfway: the Sierpinski triangle
steps = 60000
rng = np.random.default_rng()
angles = np.pi / 2 + 2 * np.pi * np.arange(corners) / corners
vertex = np.column_stack([np.cos(angles), np.sin(angles)])
points, chosen = np.zeros((steps, 2)), np.zeros(steps, dtype=int)
x, last = np.array([0.0, 0.0]), -1
for i in range(steps):
c = rng.integers(corners)
while no_repeat and c == last: # the restricted game: never the same corner twice
c = rng.integers(corners)
x = x + r * (vertex[c] - x) # the whole rule
points[i], chosen[i], last = x, c, c
plt.figure(figsize=(6, 6))
plt.scatter(points[20:, 0], points[20:, 1], s=0.3, c=chosen[20:], cmap="rainbow")
plt.axis("equal")
plt.axis("off")
plt.show()
# Try: corners, r = 5, 0.618 (a pentagon) or corners, no_repeat = 4, True (a square, restricted)
Prueba: Pon corners = 5 y r = 0.618, o corners = 4 con no_repeat = True.
Aprende este script línea a línea, con ejercicios y un cuestionario → · ejecútalo en Google Colab (en inglés) →
Para docentes: un plan de clase de 45 minutos y una hoja de trabajo en tres niveles →
Las matemáticas, tal como las cuenta el vídeo
Lee las notas del propio vídeo (de YouTube, en inglés)
Start anywhere. Pick one of the triangle's three corners at random and jump exactly halfway toward it. Plot the point.
Repeat. Nothing about the choices is planned — a coin, a die, pure chance — and yet after a few thousand jumps the Sierpiński triangle appears, sharp and complete. The reason is that "jump halfway to a corner" is a contraction: it shrinks every distance by half, so wherever the point starts, after a handful of jumps it is pulled onto the one shape that the three half-size copies of itself map back onto — the fractal is the only set the rule leaves unchanged.
Each point here is coloured by the corner it just jumped toward, which is why order seems to grow out of rainbow noise. From the triangle on, only the rule changes: a pentagon with a golden jump of 0.618, a pentagon where the same corner may never be chosen twice in a row, a square where the opposite corner is forbidden, a hexagon with a two-thirds jump. Every new shape is born from the cloud of the previous one, because the walkers simply keep going under the new rule.
Nothing is drawn; everything is counted.
De la descripción de Pure Randomness Draws a Perfect Fractal (en inglés).