import numpy as np
import matplotlib.pyplot as plt

# 20,000 points start at random places and all jump 400 times
a, b, c, d = -1.7, 1.8, -1.9, -0.4
rng = np.random.default_rng(1)
x, y = rng.uniform(-1, 1, (2, 20_000))
xs, ys = [], []
for step in range(400):
    x, y = (np.sin(a * y) + c * np.cos(a * x),
            np.sin(b * x) + d * np.cos(b * y))
    if step > 20:
        xs.append(x)
        ys.append(y)

# count how many points land in each pixel, then draw the counts
counts, _, _ = np.histogram2d(np.concatenate(xs), np.concatenate(ys), bins=1200)
plt.figure(figsize=(8, 8))
plt.imshow(np.log1p(counts.T), cmap='magma', origin='lower')
plt.axis('off')
plt.savefig('attractor.png', bbox_inches='tight', pad_inches=0, facecolor='black')
