Article 6ZC07 Randomly generated dragon

Randomly generated dragon

by
John
from John D. Cook on (#6ZC07)

Here's a simple way to generate a fractal known as the Twin Dragon. Start with random values of x andy and repeatedly update the according to the rule

xnew = (- xold + yold)/2 - b
ynew = (- xold - yold)/2

where b is randomly chosen to be 0 or 1 with equal probability. The plot of these points fills in the Twin Dragon.

Here's what the plot looks like after 10,000 iterations.

twindragon10k.png

And after 100,000 iterations.

twindragon100k.png

Here's the Python script I used to make the plots.

import matplotlib.pyplot as pltfrom numpy.random import random, choicex, y = random(), random()for _ in range(100000): x, y = (-x + y)/2, (-x - y)/2 x -= choice([0, 1]) plt.plot(x, y, 'bo', markersize=1)plt.show()

The algorithm used here is a particularly special case of a more general algorithm for generating similar fractals found in [1].

Here's a similar post from several years ago:
The chaos game and the Sierpinski triangle

[1] Darst, Palagallo, and Price. Fractal Tilings in the Plane. Mathematics Magazine [71]:1, 1998.

The post Randomly generated dragon first appeared on John D. Cook.
External Content
Source RSS or Atom Feed
Feed Location http://feeds.feedburner.com/TheEndeavour?format=xml
Feed Title John D. Cook
Feed Link https://www.johndcook.com/blog
Reply 0 comments