to orientate yourself in more complex programme codes and make certain adjustments. The formulae used in the following examples were invented by well-known mathematicians.
EXAMPLES
Fractals are computer-generated images that are self-similar, i.e. in which partial images are a reduced copy of the overall image. The term fractal was introduced in 1975 by mathematician Benoit Mandelbrot and comes from the Latin fractus (broken), which refers to the so-called fractal dimension. In traditional geometry, a line is one-dimensional, a surface is two-dimensional and a space is three-dimensional. Fractal images usually have a non-integer dimension. Fractals created by a non-linear transformation provide interesting images. Such fractals are usually calculated iteratively and often use complex numbers.
Below you will find the complete programme code for some well-known fractals without further comment. Even without studying the program code in detail, you can enjoy the beautiful images and create fractals with different colours.
Example 1: Fern
Program:
# Farn.pyfrom gpanel import *
import random
def farn():
z = 0
n = 0
while n < nbPoints:
r = random.random()
c = "black"if r < 0.01:
c = "yellow"
z = f(z, 0, 0, 0, 0.16, 0, 0) # Stielelif r < 0.86:
c = "lime"
z = f(z, 0.85, 0.04, -0.04, 0.85, 0, 1.60) # symmetryelif r > 0.86 and r < 0.93:
c = "red"
z = f(z, 0.20, -0.26, 0.23, 0.22, 0, 1.60) # left leaveselif r > 0.93:
c = "blue"
z = f(z, -0.15, 0.28, 0.26, 0.24, 0, 1.44) # right leaves
setColor(c)
point(z)
n += 1
def f(z, a, b, c, d, e, f):
re = a * z.real + b * z.imag + e
im = c * z.real + d * z.imag + f
return complex(re, im)
makeGPanel(-3.5, 3.5, 0, 10)
bgColor("black")
nbPoints = 40000
farn()