#!/usr/bin/python -O

# Erzeugt ein Farn-aehnliches Bild aus einem iterierten Funktionensystem
#
# GZ 2011, TU Clausthal, http://zach.in.tu-clausthal.de/cg_in_schule/
#


import Image
import random
import sys

im = Image.new("RGB", (512, 512), (256, 256, 256) )

# get command line args
if len( sys.argv ) >= 2:
    N = int( sys.argv[1] )
else:
    N = 20000

x, y = 0.5, 0 

# create image by iterating the function system
for i in range( 0, N ):
    r = random.random()
    if r <= 0.02:
        tempx = 0.5
        tempy = 0.27 * y
    elif r <= 0.17:
        tempx = -0.139 * x + 0.263 * y + 0.5700
        tempy =  0.246 * x + 0.224 * y - 0.0360
    elif r <= 0.30:
        tempx =  0.170 * x - 0.215 * y + 0.4080
        tempy =  0.222 * x + 0.176 * y + 0.0893
    else:
        tempx =  0.781 * x + 0.034 * y + 0.1075
        tempy = -0.032 * x + 0.739 * y + 0.2700

    x, y = tempx, tempy
    im.putpixel ( (int(x*512), int(y*512)), ( 0, 1, 0) )


im.rotate(180).show()

#vim:expandtab:
