Post by GuppyB on Aug 3, 2004 11:08:35 GMT -5
Was working through drawing pixels to the screen and this provided an excellent vehicle to do it, and also well... this is a classic.
Set your screen size using w and h (although honestly it will work even if you don't change it).
As noted in the code, changing the values of cx#,cy#,scale# and lplimit affect most of the "view" of the set that is drawn out to screen.
The program below gives you the "classic" view, here are a couple of vistas (replace in code to use) that I liked:
cx# = -0.725: cy# = 0.25 : scale# = 0.000001: lplimit = 500
cx# = -1.25: cy# = -0.35: scale# = 0.00009: lplimit = 150
cx# = -1.5025: cy# = 0.0: scale# = 0.000005: lplimit = 200
Enjoy...G
Set your screen size using w and h (although honestly it will work even if you don't change it).
As noted in the code, changing the values of cx#,cy#,scale# and lplimit affect most of the "view" of the set that is drawn out to screen.
The program below gives you the "classic" view, here are a couple of vistas (replace in code to use) that I liked:
cx# = -0.725: cy# = 0.25 : scale# = 0.000001: lplimit = 500
cx# = -1.25: cy# = -0.35: scale# = 0.00009: lplimit = 150
cx# = -1.5025: cy# = 0.0: scale# = 0.000005: lplimit = 200
Enjoy...G
' This program draws the famed Mandelbrot Set. X axis is real numbers and Y axis is imaginary.
' In order to get good sets, you'll want to try to keep -2 < CX < 2 and -1 < CY < 2
' from that point just change the zoom to get good views
dim cx#,cy# 'Center x and y location within the set
dim scale# 'zoom factor of the set, make smaller to zoom in and vice versa
dim limit# 'Diverge check, sets the stopping point of where it heads to infinity
dim lp 'converge check, sets where calculation is still within set
dim a1#,b1#,a2#,b2# 'holders for points
dim x,y 'actual pixel locations
dim ax#,ay# 'virtual set locations
dim w,h 'width and height of screen
dim pxfocus 'start large to cover screen and then focus in to 1 pixel
dim red#,blue#,green# 'colors
dim lplimit 'limit of iterations
pxfocus = 16 'start with pixel blocks of 16 and resolves down to 1 pixel, use exponents of 2 for this number
w = 1024: h = 768 'set to width and height of your screen
glMatrixMode (GL_PROJECTION)
glLoadIdentity ()
glOrtho (0, w, 0, h, -1, 1)
glMatrixMode (GL_MODELVIEW)
glDisable (GL_DEPTH_TEST)
glClear (GL_COLOR_BUFFER_BIT)
'******** NOTE: Changing cx#,cy#,Scale# and lplimit in below section will give you you're different view of the set
cx# = -0.5: cy# = 0.0 'can be set to wherever you want the center of the screen within the set to be
scale# = 0.004 'zoom factor
limit# = 4.0 ' determines where limit jumps to infinity, can be changed to better "resolve" set
lplimit = 125 'set top number of iterations
'**********************************************************************
w = w / pxfocus
h = h / pxfocus
scale# = scale# * pxfocus
while pxfocus >= 1
for x = 0 to w ' do horizontal
for y = 0 to h ' do vertical
ax# = cx# + ((x - (w/2))*scale#) : ay# = cy# + ((y - (h/2))*scale#) 'calculate from the center to point
a1# = ax# : b1# = ay# : lp = 0
while ((a1#*a1#)+(b1#*b1#)) < limit# and lp<lplimit ' test to see if outside set
lp = lp + 1 'increment counter 1
a2# = (a1# * a1#) - ( b1# * b1#) + ax# 'calculate x axis
b2# = (2 * a1# * b1#) + ay# 'calculate y axis
a1# = a2#: b1# = b2# 'swap to prepare for next iteration
WEND
GOSUB DrawPixel
NEXT
NEXT
w = w * 2
h = h * 2
scale# = scale# / 2
pxfocus = pxfocus / 2
wend
while true
wend
DrawPixel:
glDrawBuffer(gl_front)
red# = (1.0/(lplimit/4)) * lp 'caluculate red
green# = (1.0/(lplimit/2))* lp 'calc green
blue# = (1.0/lplimit) * lp 'calc blue
if lp>(lplimit-1) then red# = 0.0: blue# = 0.0: green# = 0.0: endif 'test for outside set and make black
glPointsize(pxfocus)
glBegin(GL_POINTS)
glColor3f(red#,green#,blue#) 'color based on lp number
glVertex2f(x * pxfocus,y * pxfocus) 'draw point on screen
glEnd()
return