""" Triangle Angle i*Z CONJUGATE I.F.S. Angle iteration: w=angle(x-a,y-b): z = i*exp(-i*w)/r+a+i*b By R. L. BAGULA, Sep 7 2002. rlbagula@sbcglobal.net From Paul Bourke site, http://local.wasp.uwa.edu.au/~pbourke/ Translated to Python by leonardo maffi, Sept 11 2006. Requires: - Python - Pygame, http://www.pygame.org/download.shtml - Psyco optional. """ from __future__ import division import pygame def lace(screen, nx, ny, npoints=100000): from random import randint from math import sqrt, sin, cos, hypot, atan2 pset = screen.set_at mx, my = nx/3.5, ny/3.5 nx2, ny2 = nx/2, ny/2 s32 = sqrt(3)/2 colors = (255,0,0), (0,255,0), (0,0,255), (255,255,255) x, y = 0.5, 0.75 for i in xrange(npoints): a = randint(0, 3) r0 = -hypot(x, y) / 2 if a == 0: w = atan2(x-1, y) x = r0*cos(w) + 1 y = r0*sin(w) elif a == 1: w = atan2(x+0.5, y - s32) x = r0*cos(w) - 0.5 y = r0*sin(w) + s32 elif a == 2: w = atan2(x+0.5, y+s32) x = r0*cos(w) - 0.5 y = r0*sin(w) - s32 else: w = atan2(x, y) x = r0*cos(w) y = r0*sin(w) if i > 10: pset( ( int(nx2 + x*mx), int(ny2 + y*my) ), colors[a]) if not (i % 6000): pygame.display.flip() try: # Use psyco if possible import psyco psyco.bind(lace) except: pass def pygame_plot(do_plot, nx=640, ny=480, **args): pygame.init() screen = pygame.display.set_mode((nx, ny)) pygame.display.set_caption(do_plot.__name__) do_plot(screen, nx, ny, **args) pygame.display.flip() while True: e = pygame.event.wait() if e.type == pygame.QUIT: break pygame_plot(lace, nx=800, ny=500, npoints=200000)