” in Python
p from one of the verticesp halfway between p and the random vertexp inGOTO 3
import random
import imageio
import numpy as np
max_x = 1000
max_y = int((max_x**2 - (max_x / 2)**2)**0.5)
a = np.zeros((max_y, max_x), dtype=np.uint8)
vertices = ( # [y, x] coordinates
np.array([0, max_x // 2]),
np.array([max_y - 1, 0]),
np.array([max_y - 1, max_x - 1]),
)
p = random.choice(vertices)
for _ in range(A_LOT):
p = (p + random.choice(vertices)) // 2
a[tuple(p)] = 255
imageio.imwrite('sierpinski.png', a)