Excuse me if my DarkBASIC is a little rusty, but I whipped this up yesterday from the formulas on the wikipedia page:
http://en.wikipedia.org/wiki/L-system
Sync On
Set Window On
Rem Set Window Size 640,480
Rem Set Display Mode 1280,1024,16
Sync Rate 0
For I=0 To 100
Cls 0
Sync
Next I
Remstart
Define some global variables
Remend
Dim x_position#(0)
Dim y_position#(0)
Dim z_angle(0)
Dim line_size#(0)
Dim angle_size(0)
x_position#(0)=Screen Width()/2.0
y_position#(0)=Screen Height()/2.0
line_size#(0)=2.0
level=10
dragon_start(level)
Sync
Rem Our drawing Functions
Function draw_line()
old_x#=x_position#(0)
old_y#=y_position#(0)
sw#=Screen Width()
sh#=Screen Height()
jump_line()
Line old_x#,old_y#,x_position#(0),y_position#(0)
While x_position#(0)<0 : x_position#(0)=x_position#(0)+sw# : old_x#=old_x#+sw# : Endwhile
Line old_x#,old_y#,x_position#(0),y_position#(0)
While y_position#(0)<0 : y_position#(0)=y_position#(0)+sh# : old_y#=old_y#+sh# : Endwhile
Line old_x#,old_y#,x_position#(0),y_position#(0)
While x_position#(0)>=sw# : x_position#(0)=x_position#(0)-sw# : old_x#=old_x#-sw# : Endwhile
Line old_x#,old_y#,x_position#(0),y_position#(0)
While y_position#(0)>=sh# : y_position#(0)=y_position#(0)-sh# : old_y#=old_y#-sh# : Endwhile
Line old_x#,old_y#,x_position#(0),y_position#(0)
Sync
Endfunction
Function jump_line()
while z_angle(0)<0
z_angle(0)=z_angle(0)+360
endwhile
while z_angle(0)>=360
z_angle(0)=z_angle(0)-360
endwhile
x_position#(0)=x_position#(0)+cos(z_angle(0))*line_size#(0)
y_position#(0)=y_position#(0)+sin(z_angle(0))*line_size#(0)
Endfunction
Remstart
Lindenmayer's original L-system for modelling the growth of algae.
start:A
rules:(A=AB),(B=A)
Remend
Function algae_a(level)
level=level-1
if level<=0
draw_line()
else
algae_a(level)
algae_b(level)
endif
Endfunction
Function algae_b(level)
level=level-1
if level<=0
jump_line()
else
algae_a(level)
endif
Endfunction
Function algae_start(level)
algae_a(level)
Endfunction
Remstart
Cantor set
variables: A B
constants: none
start:A
rules:(A=ABA),(B=BBB)
Remend
Function cantor_a(level)
level=level-1
if level<=0
draw_line()
else
cantor_a(level)
cantor_b(level)
cantor_a(level)
endif
Endfunction
Function cantor_b(level)
level=level-1
if level<=0
jump_line()
else
cantor_b(level)
cantor_b(level)
cantor_b(level)
endif
Endfunction
Function cantor_start(level)
cantor_a(level)
Endfunction
Remstart
A variant of the Koch curve which uses only right-angles.
start:F
rules:(F=F+F-F-F+F)
angle:90 degrees
Remend
Function koch_minus()
z_angle(0)=z_angle(0)-90
Endfunction
Function koch_plus()
z_angle(0)=z_angle(0)+90
Endfunction
Function koch_f(level)
level=level-1
if level<=0
draw_line()
else
koch_f(level)
koch_plus()
koch_f(level)
koch_minus()
koch_f(level)
koch_minus()
koch_f(level)
koch_plus()
koch_f(level)
endif
Endfunction
Function koch_start(level)
koch_f(level)
Endfunction
Remstart
The Sierpinski triangle drawn using an L-system.
start:A
rules:(A=B-A-B),(B=A+B+A)
angle:60 degrees
Remend
Function sierpinski_minus()
z_angle(0)=z_angle(0)-60
Endfunction
Function sierpinski_plus()
z_angle(0)=z_angle(0)+60
Endfunction
Function sierpinski_a(level)
level=level-1
if level<=0
draw_line()
else
sierpinski_b(level)
sierpinski_minus()
sierpinski_a(level)
sierpinski_minus()
sierpinski_b(level)
endif
Endfunction
Function sierpinski_b(level)
level=level-1
if level<=0
draw_line()
else
sierpinski_a(level)
sierpinski_plus()
sierpinski_b(level)
sierpinski_plus()
sierpinski_a(level)
endif
Endfunction
Function sierpinski_start(level)
sierpinski_a(level)
Endfunction
Remstart
The Dragon curve drawn using an L-system.
start:FX
rules:(X=X+YF),(Y=FX-Y)
angle:90 degrees
Remend
Function dragon_minus()
z_angle(0)=z_angle(0)-90
Endfunction
Function dragon_plus()
z_angle(0)=z_angle(0)+90
Endfunction
Function dragon_f()
draw_line()
Endfunction
Function dragon_x(level)
level=level-1
if level>0
dragon_x(level)
dragon_plus()
dragon_y(level)
dragon_f()
endif
Endfunction
Function dragon_y(level)
level=level-1
if level>0
dragon_f()
dragon_x(level)
dragon_minus()
dragon_y(level)
endif
Endfunction
Function dragon_start(level)
dragon_f()
dragon_x(level)
Endfunction
From memory you should be able to find a fair bit of information by looking up "iterated function systems". They work by building formula(s) which have "attractors":
http://en.wikipedia.org/wiki/Attractor
For example, the formula f(x)=x*x:
If you start with x=1, f(f(f(f(f(x)))))=1 because there's an attractor at x=1.
If you start with x=0.5, f(f(f(f(x)))) approaches 0 because there's an attractor at x=0.
If you start with x=2, f(f(f(f(x)))) approaches infinite because the attractor at x=1 "repels above".
Depending on what number you start with, you may end up with a completely different number after many iterations.
By modifying the formula the slightest bit, you can create different types of effects, even a number that jumps up and down in a loop around an attractor. Something like f(x)=-x*x can have completely different attractors.
The L-System fractals "turtle fractals" illustrate where these attractors are in a geometric way.
Fractals "pretty fractals" illustrate how many times you have to iterate in order to break free of these attractors, and instead of using integers or real numbers, it's usually complex numbers (from x,y coordinates).
The mandelbrot formula is something like f(n)=f(n-1)*f(n-1)+c where f(0)=0, and c is your coordinate (between (-1,-1)-(1,1) is the most useful). At each coordinate you calculate how many iterations it takes to "break-free" from an attractor and then give it a colour.
Another way to draw the sierpinski shapes (triangle, square etc.), is to find the midpoint between a point and another point. You can randomly, but quickly draw it using the following code:
x1#=0.0 : y1#=0.0
x2#=Screen Width()-1.0 : y2#=Screen Height()-1.0
x3#=0.0 : y3#=Screen Height()-1.0
x#=x1# : y#=y1#
While 1
r=Rnd(2)
If r=0 Then x#=(x#+x1#)/2.0 : y#=(y#+y1#)/2.0
If r=1 Then x#=(x#+x2#)/2.0 : y#=(y#+y2#)/2.0
If r=2 Then x#=(x#+x3#)/2.0 : y#=(y#+y3#)/2.0
Dot x#,y#
Sync
Endwhile
I hope I was a little helpful. Just reading it back now I don't think I've made much sense, at least I've hopefully shown a relationship between the pretty fractals and the turtle ones.