Note
Go to the end to download the full example code or to run this example in your browser via Binder.
Generative art: CPPNs, harmonographs, superformula and cellular automata#
Compositional pattern-producing networks (Stanley, 2007) paint by evaluating a small network at every pixel and gave rise to Picbreeder (Secretan et al., 2011). Harmonographs draw the trace of damped pendulums; the superformula of Gielis (2003) generalizes the superellipse to natural shapes; elementary and totalistic cellular automata (Wolfram, 1983) grow textures from local rules.
The four families#
import matplotlib.pyplot as plt
import numpy as np
import easyiec as ei
from easyiec.problems import CellularAutomaton, CPPNArt, Harmonograph, SuperShape
from easyiec.strategies import InteractiveMAPElites
rng = np.random.default_rng(2)
families = [CPPNArt(), Harmonograph(), SuperShape(), CellularAutomaton()]
fig, axes = plt.subplots(4, 6, figsize=(10, 7))
for row, p in zip(axes, families):
for ax in row:
ax.imshow(p.to_image(p.random(rng), 140))
ax.axis("off")
row[0].set_title(p.title, fontsize=8, loc="left")
fig.tight_layout()

A repertoire of CPPN images#
MAP-Elites over symmetry and colourfulness: one elite per niche, decided in duels by a simulated viewer.
problem = CPPNArt()
strategy = InteractiveMAPElites(bins=4, batch=12, n_init=24)
user = ei.SimulatedUser(problem, target="random", noise=0.05, seed=3)
res = ei.run(problem, strategy, user, generations=20, seed=3)
elites = [strategy.archive[c] for c in sorted(strategy.archive)]
ei.viz.plot_gallery(problem, elites, ncols=8, size=1.0)
plt.show()

Total running time of the script: (0 minutes 2.467 seconds)