Post by wybiral on May 16, 2006 17:59:10 GMT -5
These fractals were all based off of an algorithm I learned by a man named Daniel LeCheminant. He has a fractal tutorial somewhere on the web, I'm sure you can find it. I took the algorithm from his tutorial and added a number of steps. Basically, for a good fractal generater... You need two algorithms:
1. The fractal algorithm
2. The color algorithm
These programs show some very interesting fractals. The are all also smoothed out with a simple pixel based smoothing algorithm (in case you wonder, the offset for the smoothing IS for a reason... You cant smooth pixels that havent been drawn, lol)
These programs will also save the fractals as bmp's, you will find the file in the folder that these programs are in, it saves them as "output.bmp". Well, here they are....
The balloon universe:
Your brain on drugs:
The nebula:
Structured Randomness:
5 leaf clovers:
Enjoy!
1. The fractal algorithm
2. The color algorithm
These programs show some very interesting fractals. The are all also smoothed out with a simple pixel based smoothing algorithm (in case you wonder, the offset for the smoothing IS for a reason... You cant smooth pixels that havent been drawn, lol)
These programs will also save the fractals as bmp's, you will find the file in the folder that these programs are in, it saves them as "output.bmp". Well, here they are....
The balloon universe:
'Clear screen (just to be safe)
glClear(GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT)
dim realWidth#, realHeight#, realMin#, realMax#, realPart#
dim imgWidth#, imgHeight#, imgMin#, imgMax#, imgPart#
dim itReal#, itIMG#
dim x#, y#, c#
dim cimg#, creal#
dim cutoff#, MaxIterations#
dim PrevItReal#, PrevItImg#
dim Width, Height
dim r#, g#, b#
dim file
'Open output file
file=OpenFileWrite("Output.bmp")
'Set image size
Width=640
Height=480
'Smoothing variable
Const Offset#=10
dim Fractal#(Width)(Height)(2)
dim Tx, Ty, Tc#(2)
'Setup 2d opengl
glMatrixMode(gl_Projection)
glPushMatrix()
glLoadIdentity()
glOrtho(0,Width, Height,0,-1,1)
glMatrixMode(gl_ModelView)
glPushMatrix()
glLoadIdentity()
glDisable(gl_depth_test)
'Set our zoom
realMin# = -.1
realMax# = .1
imgMin# = -.1
imgMax# = .1
realWidth# = realMax# - realMin#
imgHeight# = imgMax# - imgMin#
'Set our seed
cImg# = .46
cReal# = -.62
cutoff# = 2
maxIterations# = 255
FOR y# = 1 TO Height + Offset#
FOR x# = 1 TO Width
'Smooth Fractal
if y#>=Offset# then
'Reset temporary color holder
Tc#(0)=0
Tc#(1)=0
Tc#(2)=0
'Add up the colors from a nine pixel square (around the current pixel)
for Ty=-1 to 1
for Tx=-1 to 1
'Make sure we arent grabbing from beyond edge, if not, add pixel to sum
if x#+Tx > 1 and X#+Tx<Width and y#+Ty-Offset#>1 and y#+ty-Offset#<Height then
Tc#(0)=Tc#(0)+Fractal#(x#+Tx)(y#+Ty-Offset#)(0)
Tc#(1)=Tc#(1)+Fractal#(x#+Tx)(y#+Ty-Offset#)(1)
Tc#(2)=Tc#(2)+Fractal#(x#+Tx)(y#+Ty-Offset#)(2)
endif
next
next
'Average the current pixel by the surrounding sum
Fractal#(x#)(y#-Offset#)(0)=tc#(0)/9
Fractal#(x#)(y#-Offset#)(1)=tc#(1)/9
Fractal#(x#)(y#-Offset#)(2)=tc#(2)/9
'Grab pixel that we just drew from the array
r#=Fractal#(x#)(y#-Offset#)(0)
g#=Fractal#(x#)(y#-Offset#)(1)
b#=Fractal#(x#)(y#-Offset#)(2)
'Draw smoothed pixel
glBegin(GL_POINTS)
glColor3f(r#,g#,b#)
glVertex2f(x#, y#-Offset#)
glEND()
endif
'Generate fractal
if y#<=Height then
realPart# = realMin# + realWidth# * (x# / Width)
imgPart# = imgMin# + imgHeight# * (y# / Height)
prevItReal# = realPart#
prevItImg# = imgPart#
FOR c# = 0 TO maxIterations# - 1
itReal# = prevItReal# * prevItReal# - prevItImg# * prevItImg# + cReal#
itImg# = 2.1 * prevItReal# * prevItImg# + cImg#
IF (itReal# * itReal# + itImg# / itImg#) > cutoff# * cutoff# THEN Goto Exit endif
prevItReal# = itReal#
prevItImg# = itImg#
NEXT
Exit:
'Translate to 0-1 color range
r#=.25+cos(c#+x#/100)
b#=.25+cos(c#+y#/100)
g#=.25+sin(c#+x#/100)
'Do a range check
if r#>1 then r#=1 endif
if g#>1 then g#=1 endif
if b#>1 then b#=1 endif
if r#<0 then r#=0 endif
if g#<0 then g#=0 endif
if b#<0 then b#=0 endif
'Save our pixel to the array
Fractal#(x#)(y#)(0)=r#
Fractal#(x#)(y#)(1)=g#
Fractal#(x#)(y#)(2)=b#
'Draw Pixel
glBegin(GL_POINTS)
glColor3f(r#,g#,b#)
glVertex2f(x#, y#)
glEND()
endif
NEXT
SwapBuffers()
NEXT
'Setup bmp header
Writeword(File, 19778)
WriteInt(File, Width*Height*3.1)
Writeword(File, 0)
Writeword(File, 0)
WriteInt(File, 54)
WriteInt(File, 40)
WriteInt(File, Width)
WriteInt(File, Height)
Writeword(File, 1)
Writeword(File, 24)
WriteInt(File, 0)
WriteInt(File, 0)
WriteInt(File, 2834)
WriteInt(File, 2834)
WriteInt(File, 0)
WriteInt(File, 0)
'Save Fractal
for y#=Height to 1 step - 1
for x#=1 to Width
'Translate back to 0-255 color range
r#=Fractal#(x#)(y#)(0)*255
g#=Fractal#(x#)(y#)(1)*255
b#=Fractal#(x#)(y#)(2)*255
'Write pixel to file
WriteByte(File, b#)
WriteByte(File, g#)
WriteByte(File, r#)
next
next
Beep()
Your brain on drugs:
'Clear screen (just to be safe)
glClear(GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT)
dim realWidth#, realHeight#, realMin#, realMax#, realPart#
dim imgWidth#, imgHeight#, imgMin#, imgMax#, imgPart#
dim itReal#, itIMG#
dim x#, y#, c#
dim cimg#, creal#
dim cutoff#, MaxIterations#
dim PrevItReal#, PrevItImg#
dim Width, Height
dim r#, g#, b#
dim file
'Open output file
file=OpenFileWrite("Output.bmp")
'Set image size
Width=640
Height=480
'Smoothing variable
Const Offset#=10
dim Fractal#(Width)(Height)(2)
dim Tx, Ty, Tc#(2)
'Setup 2d opengl
glMatrixMode(gl_Projection)
glPushMatrix()
glLoadIdentity()
glOrtho(0,Width, Height,0,-1,1)
glMatrixMode(gl_ModelView)
glPushMatrix()
glLoadIdentity()
glDisable(gl_depth_test)
'Set our zoom
realMin# = -.1
realMax# = .05
imgMin# = -.1
imgMax# = .05
realWidth# = realMax# - realMin#
imgHeight# = imgMax# - imgMin#
'Set our seed
cImg# = .46
cReal# = -.62
cutoff# = 2
maxIterations# = 255
FOR y# = 1 TO Height + Offset#
FOR x# = 1 TO Width
'Smooth Fractal
if y#>=Offset# then
'Reset temporary color holder
Tc#(0)=0
Tc#(1)=0
Tc#(2)=0
'Add up the colors from a nine pixel square (around the current pixel)
for Ty=-1 to 1
for Tx=-1 to 1
'Make sure we arent grabbing from beyond edge, if not, add pixel to sum
if x#+Tx > 1 and X#+Tx<Width and y#+Ty-Offset#>1 and y#+ty-Offset#<Height then
Tc#(0)=Tc#(0)+Fractal#(x#+Tx)(y#+Ty-Offset#)(0)
Tc#(1)=Tc#(1)+Fractal#(x#+Tx)(y#+Ty-Offset#)(1)
Tc#(2)=Tc#(2)+Fractal#(x#+Tx)(y#+Ty-Offset#)(2)
endif
next
next
'Average the current pixel by the surrounding sum
Fractal#(x#)(y#-Offset#)(0)=tc#(0)/9
Fractal#(x#)(y#-Offset#)(1)=tc#(1)/9
Fractal#(x#)(y#-Offset#)(2)=tc#(2)/9
'Grab pixel that we just drew from the array
r#=Fractal#(x#)(y#-Offset#)(0)
g#=Fractal#(x#)(y#-Offset#)(1)
b#=Fractal#(x#)(y#-Offset#)(2)
'Draw smoothed pixel
glBegin(GL_POINTS)
glColor3f(r#,g#,b#)
glVertex2f(x#, y#-Offset#)
glEND()
endif
'Generate fractal
if y#<=Height then
realPart# = realMin# + realWidth# * (x# / Width)
imgPart# = imgMin# + imgHeight# * (y# / Height)
prevItReal# = realPart#
prevItImg# = imgPart#
FOR c# = 0 TO maxIterations# - 1
itReal# = prevItReal# * prevItReal# - prevItImg# * prevItImg# + cReal#
itImg# = 1.99 * prevItReal# * prevItImg# + cImg#
IF (itReal# * itReal# + itImg# * itImg#) > cutoff# * cutoff# THEN Goto Exit endif
prevItReal# = itReal#
prevItImg# = itImg#
NEXT
Exit:
'Translate to 0-1 color range
r#=cos((c#/10)+(y#)/100)*2
b#=cos((c#/10)+x#/100)*2
g#=sin((c#/10)+y#/100)*2
'Do a range check
if r#>1 then r#=1 endif
if g#>1 then g#=1 endif
if b#>1 then b#=1 endif
if r#<0 then r#=0 endif
if g#<0 then g#=0 endif
if b#<0 then b#=0 endif
'Save our pixel to the array
Fractal#(x#)(y#)(0)=r#
Fractal#(x#)(y#)(1)=g#
Fractal#(x#)(y#)(2)=b#
'Draw Pixel
glBegin(GL_POINTS)
glColor3f(r#,g#,b#)
glVertex2f(x#, y#)
glEND()
endif
NEXT
SwapBuffers()
NEXT
'Setup bmp header
Writeword(File, 19778)
WriteInt(File, Width*Height*3.1)
Writeword(File, 0)
Writeword(File, 0)
WriteInt(File, 54)
WriteInt(File, 40)
WriteInt(File, Width)
WriteInt(File, Height)
Writeword(File, 1)
Writeword(File, 24)
WriteInt(File, 0)
WriteInt(File, 0)
WriteInt(File, 2834)
WriteInt(File, 2834)
WriteInt(File, 0)
WriteInt(File, 0)
'Save Fractal
for y#=Height to 1 step - 1
for x#=1 to Width
'Translate back to 0-255 color range
r#=Fractal#(x#)(y#)(0)*255
g#=Fractal#(x#)(y#)(1)*255
b#=Fractal#(x#)(y#)(2)*255
'Write pixel to file
WriteByte(File, b#)
WriteByte(File, g#)
WriteByte(File, r#)
next
next
Beep()
The nebula:
'Clear screen (just to be safe)
glClear(GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT)
dim realWidth#, realHeight#, realMin#, realMax#, realPart#
dim imgWidth#, imgHeight#, imgMin#, imgMax#, imgPart#
dim itReal#, itIMG#
dim x#, y#, c#
dim cimg#, creal#
dim cutoff#, MaxIterations#
dim PrevItReal#, PrevItImg#
dim Width, Height
dim r#, g#, b#
dim file
'Open output file
file=OpenFileWrite("Output.bmp")
'Set image size
Width=640
Height=480
'Smoothing variable
Const Offset#=10
dim Fractal#(Width)(Height)(2)
dim Tx, Ty, Tc#(2)
'Setup 2d opengl
glMatrixMode(gl_Projection)
glPushMatrix()
glLoadIdentity()
glOrtho(0,Width, Height,0,-1,1)
glMatrixMode(gl_ModelView)
glPushMatrix()
glLoadIdentity()
glDisable(gl_depth_test)
'Set our zoom
realMin# = -.1
realMax# = .05
imgMin# = -.1
imgMax# = .05
realWidth# = realMax# - realMin#
imgHeight# = imgMax# - imgMin#
'Set our seed
cImg# = .46
cReal# = -.62
cutoff# = 2
maxIterations# = 255
FOR y# = 1 TO Height + Offset#
FOR x# = 1 TO Width
'Smooth Fractal
if y#>=Offset# then
'Reset temporary color holder
Tc#(0)=0
Tc#(1)=0
Tc#(2)=0
'Add up the colors from a nine pixel square (around the current pixel)
for Ty=-1 to 1
for Tx=-1 to 1
'Make sure we arent grabbing from beyond edge, if not, add pixel to sum
if x#+Tx > 1 and X#+Tx<Width and y#+Ty-Offset#>1 and y#+ty-Offset#<Height then
Tc#(0)=Tc#(0)+Fractal#(x#+Tx)(y#+Ty-Offset#)(0)
Tc#(1)=Tc#(1)+Fractal#(x#+Tx)(y#+Ty-Offset#)(1)
Tc#(2)=Tc#(2)+Fractal#(x#+Tx)(y#+Ty-Offset#)(2)
endif
next
next
'Average the current pixel by the surrounding sum
Fractal#(x#)(y#-Offset#)(0)=tc#(0)/9
Fractal#(x#)(y#-Offset#)(1)=tc#(1)/9
Fractal#(x#)(y#-Offset#)(2)=tc#(2)/9
'Grab pixel that we just drew from the array
r#=Fractal#(x#)(y#-Offset#)(0)
g#=Fractal#(x#)(y#-Offset#)(1)
b#=Fractal#(x#)(y#-Offset#)(2)
'Draw smoothed pixel
glBegin(GL_POINTS)
glColor3f(r#,g#,b#)
glVertex2f(x#, y#-Offset#)
glEND()
endif
'Generate fractal
if y#<=Height then
realPart# = realMin# + realWidth# * (x# / Width)
imgPart# = imgMin# + imgHeight# * (y# / Height)
prevItReal# = realPart#
prevItImg# = imgPart#
FOR c# = 0 TO maxIterations# - 1
itReal# = prevItReal# * prevItReal# - prevItImg# * prevItImg# + cReal#
itImg# = 1.99 * prevItReal# * prevItImg# + cImg#
IF (itReal# * itReal# + itImg# * itImg#) > cutoff# * cutoff# THEN Goto Exit endif
prevItReal# = itReal#
prevItImg# = itImg#
NEXT
Exit:
'Translate to 0-1 color range
r#=(1-cos(c#/70)*2)/6
b#=(1-cos(c#/70)*2)/2
g#=(1-cos(c#/70)*2)/4
'Do a range check
if r#>1 then r#=1 endif
if g#>1 then g#=1 endif
if b#>1 then b#=1 endif
if r#<0 then r#=0 endif
if g#<0 then g#=0 endif
if b#<0 then b#=0 endif
'Save our pixel to the array
Fractal#(x#)(y#)(0)=r#
Fractal#(x#)(y#)(1)=g#
Fractal#(x#)(y#)(2)=b#
'Draw Pixel
glBegin(GL_POINTS)
glColor3f(r#,g#,b#)
glVertex2f(x#, y#)
glEND()
endif
NEXT
SwapBuffers()
NEXT
'Setup bmp header
Writeword(File, 19778)
WriteInt(File, Width*Height*3.1)
Writeword(File, 0)
Writeword(File, 0)
WriteInt(File, 54)
WriteInt(File, 40)
WriteInt(File, Width)
WriteInt(File, Height)
Writeword(File, 1)
Writeword(File, 24)
WriteInt(File, 0)
WriteInt(File, 0)
WriteInt(File, 2834)
WriteInt(File, 2834)
WriteInt(File, 0)
WriteInt(File, 0)
'Save Fractal
for y#=Height to 1 step - 1
for x#=1 to Width
'Translate back to 0-255 color range
r#=Fractal#(x#)(y#)(0)*255
g#=Fractal#(x#)(y#)(1)*255
b#=Fractal#(x#)(y#)(2)*255
'Write pixel to file
WriteByte(File, b#)
WriteByte(File, g#)
WriteByte(File, r#)
next
next
Beep()
Structured Randomness:
'Clear screen (just to be safe)
glClear(GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT)
dim realWidth#, realHeight#, realMin#, realMax#, realPart#
dim imgWidth#, imgHeight#, imgMin#, imgMax#, imgPart#
dim itReal#, itIMG#
dim x#, y#, c#
dim cimg#, creal#
dim cutoff#, MaxIterations#
dim PrevItReal#, PrevItImg#
dim Width, Height
dim r#, g#, b#
dim file
'Open output file
file=OpenFileWrite("Output.bmp")
'Set image size
Width=640
Height=480
'Smoothing variable
Const Offset#=10
dim Fractal#(Width)(Height)(2)
dim Tx, Ty, Tc#(2)
'Setup 2d opengl
glMatrixMode(gl_Projection)
glPushMatrix()
glLoadIdentity()
glOrtho(0,Width, Height,0,-1,1)
glMatrixMode(gl_ModelView)
glPushMatrix()
glLoadIdentity()
glDisable(gl_depth_test)
'Set our zoom
realMin# = -.1
realMax# = .05
imgMin# = -.1
imgMax# = .05
realWidth# = realMax# - realMin#
imgHeight# = imgMax# - imgMin#
'Set our seed
cImg# = .46
cReal# = -.62
cutoff# = 2
maxIterations# = 255
FOR y# = 1 TO Height + Offset#
FOR x# = 1 TO Width
'Smooth Fractal
if y#>=Offset# then
'Reset temporary color holder
Tc#(0)=0
Tc#(1)=0
Tc#(2)=0
'Add up the colors from a nine pixel square (around the current pixel)
for Ty=-1 to 1
for Tx=-1 to 1
'Make sure we arent grabbing from beyond edge, if not, add pixel to sum
if x#+Tx > 1 and X#+Tx<Width and y#+Ty-Offset#>1 and y#+ty-Offset#<Height then
Tc#(0)=Tc#(0)+Fractal#(x#+Tx)(y#+Ty-Offset#)(0)
Tc#(1)=Tc#(1)+Fractal#(x#+Tx)(y#+Ty-Offset#)(1)
Tc#(2)=Tc#(2)+Fractal#(x#+Tx)(y#+Ty-Offset#)(2)
endif
next
next
'Average the current pixel by the surrounding sum
Fractal#(x#)(y#-Offset#)(0)=tc#(0)/9
Fractal#(x#)(y#-Offset#)(1)=tc#(1)/9
Fractal#(x#)(y#-Offset#)(2)=tc#(2)/9
'Grab pixel that we just drew from the array
r#=Fractal#(x#)(y#-Offset#)(0)
g#=Fractal#(x#)(y#-Offset#)(1)
b#=Fractal#(x#)(y#-Offset#)(2)
'Draw smoothed pixel
glBegin(GL_POINTS)
glColor3f(r#,g#,b#)
glVertex2f(x#, y#-Offset#)
glEND()
endif
'Generate fractal
if y#<=Height then
realPart# = realMin# + realWidth# * (x# / Width)
imgPart# = imgMin# + imgHeight# * (y# / Height)
prevItReal# = realPart#
prevItImg# = imgPart#
FOR c# = 0 TO maxIterations# - 1
itReal# = prevItReal# * prevItReal# - prevItImg# * prevItImg# + cReal#
itImg# = 2.02 * prevItReal# * prevItImg# + cImg#
IF (itReal# * itReal# + itImg# * itImg#) > cutoff# * cutoff# THEN Goto Exit endif
prevItReal# = itReal#
prevItImg# = itImg#
NEXT
Exit:
'Translate to 0-1 color range
if c#>80 then
r#=(Rnd()%2)*(c#/255)
b#=(Rnd()%2)*(c#/255)
g#=(Rnd()%2)*(c#/255)
else
r#=0
b#=0
g#=0
endif
'Do a range check
if r#>1 then r#=1 endif
if g#>1 then g#=1 endif
if b#>1 then b#=1 endif
if r#<0 then r#=0 endif
if g#<0 then g#=0 endif
if b#<0 then b#=0 endif
'Save our pixel to the array
Fractal#(x#)(y#)(0)=r#
Fractal#(x#)(y#)(1)=g#
Fractal#(x#)(y#)(2)=b#
'Draw Pixel
glBegin(GL_POINTS)
glColor3f(r#,g#,b#)
glVertex2f(x#, y#)
glEND()
endif
NEXT
SwapBuffers()
NEXT
'Setup bmp header
Writeword(File, 19778)
WriteInt(File, Width*Height*3.1)
Writeword(File, 0)
Writeword(File, 0)
WriteInt(File, 54)
WriteInt(File, 40)
WriteInt(File, Width)
WriteInt(File, Height)
Writeword(File, 1)
Writeword(File, 24)
WriteInt(File, 0)
WriteInt(File, 0)
WriteInt(File, 2834)
WriteInt(File, 2834)
WriteInt(File, 0)
WriteInt(File, 0)
'Save Fractal
for y#=Height to 1 step - 1
for x#=1 to Width
'Translate back to 0-255 color range
r#=Fractal#(x#)(y#)(0)*255
g#=Fractal#(x#)(y#)(1)*255
b#=Fractal#(x#)(y#)(2)*255
'Write pixel to file
WriteByte(File, b#)
WriteByte(File, g#)
WriteByte(File, r#)
next
next
Beep()
5 leaf clovers:
'Clear screen (just to be safe)
glClear(GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT)
dim realWidth#, realHeight#, realMin#, realMax#, realPart#
dim imgWidth#, imgHeight#, imgMin#, imgMax#, imgPart#
dim itReal#, itIMG#
dim x#, y#, c#
dim cimg#, creal#
dim cutoff#, MaxIterations#
dim PrevItReal#, PrevItImg#
dim Width, Height
dim r#, g#, b#
dim file
'Open output file
file=OpenFileWrite("Output.bmp")
'Set image size
Width=640
Height=480
'Smoothing variable
Const Offset#=10
dim Fractal#(Width)(Height)(2)
dim Tx, Ty, Tc#(2)
'Setup 2d opengl
glMatrixMode(gl_Projection)
glPushMatrix()
glLoadIdentity()
glOrtho(0,Width, Height,0,-1,1)
glMatrixMode(gl_ModelView)
glPushMatrix()
glLoadIdentity()
glDisable(gl_depth_test)
'Set our zoom
realMin# = -.1
realMax# = .05
imgMin# = -.1
imgMax# = .05
realWidth# = realMax# - realMin#
imgHeight# = imgMax# - imgMin#
'Set our seed
cImg# = -.462
cReal# = -.627
cutoff# = 2
maxIterations# = 255
FOR y# = 1 TO Height + Offset#
FOR x# = 1 TO Width
'Smooth Fractal
if y#>=Offset# then
'Reset temporary color holder
Tc#(0)=0
Tc#(1)=0
Tc#(2)=0
'Add up the colors from a nine pixel square (around the current pixel)
for Ty=-1 to 1
for Tx=-1 to 1
'Make sure we arent grabbing from beyond edge, if not, add pixel to sum
if x#+Tx > 1 and X#+Tx<Width and y#+Ty-Offset#>1 and y#+ty-Offset#<Height then
Tc#(0)=Tc#(0)+Fractal#(x#+Tx)(y#+Ty-Offset#)(0)
Tc#(1)=Tc#(1)+Fractal#(x#+Tx)(y#+Ty-Offset#)(1)
Tc#(2)=Tc#(2)+Fractal#(x#+Tx)(y#+Ty-Offset#)(2)
endif
next
next
'Average the current pixel by the surrounding sum
Fractal#(x#)(y#-Offset#)(0)=tc#(0)/9
Fractal#(x#)(y#-Offset#)(1)=tc#(1)/9
Fractal#(x#)(y#-Offset#)(2)=tc#(2)/9
'Grab pixel that we just drew from the array
r#=Fractal#(x#)(y#-Offset#)(0)
g#=Fractal#(x#)(y#-Offset#)(1)
b#=Fractal#(x#)(y#-Offset#)(2)
'Draw smoothed pixel
glBegin(GL_POINTS)
glColor3f(r#,g#,b#)
glVertex2f(x#, y#-Offset#)
glEND()
endif
'Generate fractal
if y#<=Height then
realPart# = realMin# + realWidth# * (x# / Width)
imgPart# = imgMin# + imgHeight# * (y# / Height)
prevItReal# = realPart#
prevItImg# = imgPart#
FOR c# = 0 TO maxIterations# - 1
itReal# = prevItReal# * prevItReal# - prevItImg# * prevItImg# + cReal#
itImg# = 2.02 * prevItReal# * prevItImg# + cImg#
IF (itReal# * itReal# + itImg# * itImg#) > cutoff# * cutoff# THEN Goto Exit endif
prevItReal# = itReal#
prevItImg# = itImg#
NEXT
Exit:
'Translate to 0-1 color range
r#=c#/255 * cos(x#/Width)
b#=c#/255 * sin(x#/Width)
g#=c#/255
'Do a range check
if r#>1 then r#=1 endif
if g#>1 then g#=1 endif
if b#>1 then b#=1 endif
if r#<0 then r#=0 endif
if g#<0 then g#=0 endif
if b#<0 then b#=0 endif
'Save our pixel to the array
Fractal#(x#)(y#)(0)=r#
Fractal#(x#)(y#)(1)=g#
Fractal#(x#)(y#)(2)=b#
'Draw Pixel
glBegin(GL_POINTS)
glColor3f(r#,g#,b#)
glVertex2f(x#, y#)
glEND()
endif
NEXT
SwapBuffers()
NEXT
'Setup bmp header
Writeword(File, 19778)
WriteInt(File, Width*Height*3.1)
Writeword(File, 0)
Writeword(File, 0)
WriteInt(File, 54)
WriteInt(File, 40)
WriteInt(File, Width)
WriteInt(File, Height)
Writeword(File, 1)
Writeword(File, 24)
WriteInt(File, 0)
WriteInt(File, 0)
WriteInt(File, 2834)
WriteInt(File, 2834)
WriteInt(File, 0)
WriteInt(File, 0)
'Save Fractal
for y#=Height to 1 step - 1
for x#=1 to Width
'Translate back to 0-255 color range
r#=Fractal#(x#)(y#)(0)*255
g#=Fractal#(x#)(y#)(1)*255
b#=Fractal#(x#)(y#)(2)*255
'Write pixel to file
WriteByte(File, b#)
WriteByte(File, g#)
WriteByte(File, r#)
next
next
Beep()
Enjoy!