#!/usr/bin/env python
# an implementation of http://en.wikipedia.org/wiki/Barnsley_fern

from pylab import zeros, rand, scatter, xlim, ylim, xticks, yticks, show

num_points = 100000;
x, y = (zeros(num_points), zeros(num_points))

for ind in range(1,num_points):
	r = rand()
	if r < 0.01:
		a, b, c, d, e ,f = (0, 0, 0, 0.16, 0, 0)
	elif r < 0.01 + 0.85:
		a, b, c, d, e ,f = (0.85, 0.04, -0.04, 0.85, 0, 1.6)
	elif r < 0.01 + 0.85 + 0.07:
		a, b, c, d, e ,f = (0.2, -0.26, 0.23, 0.22, 0, 1.6)
	else:
		a, b, c, d, e ,f = (-0.15, 0.28, 0.26, 0.24, 0, 0.44)
	x[ind] = a*x[ind-1] + b*y[ind-1] + e
	y[ind] = c*x[ind-1] + d*y[ind-1] + f

scatter(x, y, s=1, c='g', edgecolors='none')
# xlim(-2.1818, 2.6556 )
# ylim(0, 9.95851)
xticks([])
yticks([])
show()

