Hi there,
the PyX gallery shows how to create the Sierpinski triangle and a
fractal tree. These examples are fine as is, but also somehow
"barebones" in their approach. So I'm wondering whether there's interest
in a more systematic/pythonic example on interated function systems.
The attached code shows how to generate the iterated transformations
(Hutchinson operator) using itertools, and also demonstrates that any
compact set converges to the Sierpinski triangle. For other IFS fractals
you simply specify a different set of elementary transformations.
The tree could be redone in a similar way, either looping over orders or
substituting a recursive call for the itertools.product.
Cheers
Michael
from pyx import *
from math import sqrt
import itertools
def ifs(trafos, n):
"""Hutchinson operator
This generator yields all n-th order transformations generated
from the specified 1st order trabnsformations"""
for trafotuple in itertools.product(trafos, repeat = n):
yield reduce(trafo.trafo_pt.__mul__, trafotuple)
sierpinski = [ trafo.scale(0.5),
trafo.translate(1, 0) * trafo.scale(0.5),
trafo.translate(0.5, 0.5*sqrt(3)) * trafo.scale(0.5) ]
c = canvas.canvas()
d = canvas.canvas()
d.stroke(path.circle(0, 0, 0.75))
d.text(0, 0, r"\PyX")
for n in [2, 4, 6]:
for t in ifs(sierpinski, n):
c.insert(d, [trafo.translate(n, 0) * t]) # transform canvas
#c.fill(path.circle(0, 0, 0.75), [t]) # or tranform path
#c.text(0, 0, "PyX", [t]) # or transform text
c.writePDFfile()
------------------------------------------------------------------------------
Monitor 25 network devices or servers for free with OpManager!
OpManager is web-based network management software that monitors
network devices and physical & virtual servers, alerts via email & sms
for fault. Monitor 25 devices for free with no restriction. Download now
http://ad.doubleclick.net/ddm/clk/292181274;119417398;o
_______________________________________________
PyX-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyx-user