Post by gaviero on Dec 31, 2004 20:55:32 GMT -5
I was inspired by GuppyB's great fractal posts, so I had to create one of my own. Actually, the link to algorithmicbotany.org/papers was a big help, so thanks GuppyB!
If anyone knows why this program (and the other fractal demos for that matter) run fine from the IDE, but not from a double-click of the program file, please let me know. That said, run this from the Basic4GL IDE
You can create some very nice fractals by playing with the values...
If anyone knows why this program (and the other fractal demos for that matter) run fine from the IDE, but not from a double-click of the program file, please let me know. That said, run this from the Basic4GL IDE
You can create some very nice fractals by playing with the values...
glLoadIdentity()
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)
glTranslatef(0.0,-0.0,-150.0)
' Uncomment some of the r$ and p$ pairs below for some
' variations
Dim r$ : r$ = "F-F-F-F" ' The 'axiom' for the L-system
Dim p$ : p$ = "F+F-F-F+F" ' F -> F-F+F+FF-F-F+F
'Dim r$ : r$ = "F"
'Dim p$ : p$ = "F+F-F-F+F"
'Dim r$ : r$ = "F-F-F-F"
'Dim p$ : p$ = "F-F+F+FF-F-F+F"
Dim x1# : x1# = 60.0
Dim y1# : y1# = -40.0
Dim x2#
Dim y2#
Dim delta# : delta# = m_pi/2.0
Dim angle# : angle# = 0.0
Dim dist# : dist# = 1.0
Dim n : n = 3
Dim ctemp$
Dim leaf$ : leaf$ = r$
Dim temp$ : temp$ = ""
Dim index
Dim index2
Dim index3
while 1
leaf$ = r$
angle# = angle# + m_pi/4.0
x1# = 0.0
y1# = 0.0
gosub build
wend
end
build:
for index = 0 to n
for index2 = 1 to len(leaf$)
ctemp$ = mid$(leaf$,index2,1)
if ctemp$ = "F" then
temp$ = temp$ + p$
else
temp$ = temp$ + ctemp$
endif
next
leaf$ = temp$
temp$ = ""
gosub draw
next
return
draw:
glDrawBuffer(GL_FRONT_AND_BACK)
glColor3f(1.0/(rnd()%10+1), 1.0/(rnd()%10+1), 1.0/(rnd()%10+1))
glLineWidth(1.0)
glBegin(GL_LINE_STRIP)
glVertex3f(x1#, y1#, 0.0)
for index3 = 1 to len(leaf$)
ctemp$ = mid$(leaf$,index3,1)
if ctemp$ = "F" then
'Move with line
x2# = x1# + cos(angle#)*dist#
y2# = y1# + sin(angle#)*dist#
x1# = x2#
y1# = y2#
glVertex3f(x2#, y2#, 0.0)
elseif ctemp$ = "-" then
angle# = (angle# - delta#)
'Decrease angle (delta)
elseif ctemp$ = "+" then
angle# = (angle# + delta#)
'Increase angle
endif
next
glEnd()
WaitTimer(100)
return