Results 1 to 10 of 36

Thread: Example: Section 7.7 (pages 222-224) Explorations with the Mandelbrot Set

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #31
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    52
    Posts
    944
    Rep Power
    111

    Re: Example: Section 7.7 (pages 222-224) Explorations with the Mandelbrot Set

    this example didn't work complete. rendering abort at about 53 per cent.

    [code=thinbasic]' Empty GUI script created on 03-04-2010 16:47:52 by (ThinAIR)

    ' 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 = 680
    height = 500
    '
    ' Create and show window
    hWnd = TBGL_CreateWindowEx("Frankos_Mandelbrot Set", Width, Height, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX Or %TBGL_WS_DONTSIZE)
    TBGL_ShowWindow

    ' -- 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
    Local p,v As Double

    ' -- Create new GBuffer
    Local gbMandelbrot As DWord = TBGL_GBufferCreate(%TBGL_POINTS, %TBGL_2D)
    Local MandelbrotIndex As Long
    Local MandelbrotVertex(160000) As tbgl_tVector2f ' -- TYPE from TBGL
    Local MandelbrotColor (320000) As tbgl_tRGB ' -- TYPE from TBGL
    p = -0.001*Cos(GetTickCount/5000)*100

    ' -- Fill it with data
    For x = -2 To 1 Step 0.0055

    For y = -1.5 To 1.5 Step 0.0055
    Incr MandelbrotIndex
    Incr MandelbrotColor(MandelbrotIndex).r

    ' Set complex points
    c = iComplex_Set(x,y)
    z = iComplex_Set(x,y)
    v = iComplex_Set(x,y)
    n = 0

    For n = 1 To 50
    ' Equation is z = z*z + c
    z = iComplex_Mul(z,z)
    z = iComplex_Add(z,c)
    z = iComplex_Sin(z)
    'z = iComplex_sub(z,v)

    ' 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
    MandelbrotColor (MandelbrotIndex).R = 455 '--> ? problem
    MandelbrotVertex(MandelbrotIndex).x = x
    MandelbrotVertex(MandelbrotIndex).y = y
    End If
    Next
    Next

    ' -- Write status
    percent = (x-(-2))/3*100
    TBGL_SetWindowTitle(hWnd, Format$(percent, "#.00")+"%, rendering full detail")
    DoEvents

    ' -- Dynamically say to TBGL where the data are, this is just pointer gymnastics, no copy
    TBGL_GBufferDefineFromArray(gbMandelbrot, %TBGL_DYNAMIC, MandelbrotIndex, MandelbrotVertex(1), MandelbrotColor(1))

    ' -- Redraw
    TBGL_ClearFrame
    TBGL_GBufferRender(gbMandelbrot)
    TBGL_DrawFrame

    ' -- Escape sooner?
    If TBGL_GetWindowKeyOnce(hWnd, %VK_ESCAPE) Then Exit For

    Next

    TBGL_SetWindowTitle(hWnd, "Behold - the Mandlebrot! ")

    ' Main loop
    While TBGL_IsWindow(hWnd)

    TBGL_ClearFrame

    TBGL_GBufferRender(gbMandelbrot)

    TBGL_DrawFrame

    If TBGL_GetWindowKeyOnce(hWnd, %VK_ESCAPE) Then Exit While

    Wend

    TBGL_DestroyWindow

    End Function
    [/code]

    perhaps somebody can help to fix this code that's run fine or give hint where I can do that, would be nice ?

    best regards, frank
    Attached Images Attached Images
    you can't always get what you want, but if you try sometimes you might find, you get what you need

Similar Threads

  1. 3D Mandelbrot Set
    By zak in forum General
    Replies: 11
    Last Post: 29-11-2010, 06:40
  2. Benoit Mandelbrot, RIP
    By LanceGary in forum Shout Box Area
    Replies: 6
    Last Post: 05-11-2010, 03:35

Members who have read this thread: 2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •