Hi Stan,
very nice example.
Here is slightly modified version:
' Example: Section 7.7 (page 222-224), Explorations with the Mandlebrot Set
' From Stan Blank's Book:
' "Python Programming in OpenGL
' "A Graphical Approach to Programming
' Converted by Stan Blank, this version is slightly downgraded in detail by Petr Schreiber
' Using the Predator-Prey framework by Michael Clease
' Last modified: February 28, 2010
' thinBasic does not use GLUT, we use instead tbgl
Uses "TBGL"
' insert Eros Olmi's new iComplex module
Uses "iComplex"
Function TBMain()
' Handle for our window
Local hWnd As DWord
Local Width As Long
Local Height As Long
Local n As Long
Local x,y, zz As Double
' Declare iComplex variables
Local z, c As tComplex
'# Initial values of width And height
width = 400
height = 400
'
' Create and show window
hWnd = TBGL_CreateWindowEx("Mandelbrot Set", Width, Height, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX Or %TBGL_WS_DONTSIZE)
TBGL_ShowWindow
' Set Foreground from default White to Green
TBGL_Color(76,152,51)
' Set background from default black to white
TBGL_BackColor(0,0,0)
' Init OpenGl, like gluOrtho2D in example code
TBGL_RenderMatrix2D( -2, -1.5, 1, 1.5 )
TBGL_PointSize 1
' Resets status of all keys
TBGL_ResetKeyState()
Local percent As Double
TBGL_NewList 1
' Choose each pixel in the graphics window
TBGL_BeginPoly(%GL_POINTS)
For x = -2 To 1 Step 0.0075
For y = -1.5 To 1.5 Step 0.0075
' Set complex points
c = iComplex_Set(x,y)
z = iComplex_Set(x,y)
n = 0
For n = 1 To 10
' Equation is z = z*z + c
z = iComplex_Mul(z,z)
z = iComplex_Add(z,c)
' Distance from origin to complex point
zz = iComplex_Abs(z)
' if distance is > 2.0, then point is NOT in the M-Set
' so plot it... the M-Set will be black
If zz > 2.0 Then
TBGL_Color zz*100,0,0
TBGL_Vertex(x,y)
End If
Next
Next
' ESCAPE key to exit application + status
percent = (x-(-2))/3*100
TBGL_SetWindowTitle(hWnd, Format$(percent, "#.00")+"%")
If TBGL_GetWindowKeyOnce(hWnd, %VK_ESCAPE) Then Exit For
Next
TBGL_EndPoly
TBGL_EndList
TBGL_SetWindowTitle(hWnd, "Behold - the Mandlebrot! :)")
' Main loop
While TBGL_IsWindow(hWnd)
TBGL_ClearFrame ' glClear(GL_COLOR_BUFFER_BIT)
TBGL_CallList 1
TBGL_DrawFrame
If TBGL_GetWindowKeyOnce(hWnd, %VK_ESCAPE) Then Exit While
Wend
TBGL_DestroyWindow
End Function
'Python code omitted due to length... see text.
With new release of thinBASIC, there will be possibility to avoid usage of display lists, resulting in slightly faster render, and much lower memory consumption.
Regarding processing speed ... I think Charles could have idea how.
The modified example above adds more color detail, and possibility to abort calculation to see at least part of the image.
Petr
Bookmarks