Page 4 of 4 FirstFirst ... 234
Results 31 to 36 of 36

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

  1. #31
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    51
    Posts
    934
    Rep Power
    109

    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

  2. #32
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

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

    Hi Frank,

    the reason of failing is obvious - array not big enough.
    Try to think how to calculate how much points it will have, if you go from -2 to 1 by 0.0055 and -1.5 to 1.5 by 0.0055.

    Three hints:
    • 1-(-2) = 3, 1.5-(-1.5) = 3
    • step is not well chosen
    • size of vertex and color array does not match



    Petr

    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #33

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

    By bending the algorithm, distorted structures can be produced. as shown in the images below. You
    can see where additional Asm instructions may be inserted. (The fsin & fmul instructions commented out).

    I've also improved the navigation by using smaller steps and improved the frame rate a bit though I cannot match Joshy's fractal program!
    (http://community.thinbasic.com/index...;topicseen#new)

    Charles

    [code=thinbasic]
    mov edx,shmo
    mov ecx,0
    (
    'zzman=zzman*zzman+zzcor 'COMPLEX OPERATIONS
    'esc=zzman.r * zzman.r + zzman.i * zzman.i
    'if esc>lmt then jmp fwd xff
    fld qword zzman.r
    fmul st(0),st(0)
    fld qword zzman.i
    fmul st(0),st(0)
    'fsin
    fsubp st(1),st(0)
    fld qword zzman.r
    fmul qword zzman.i
    'fsin
    fadd st(0),st(0)
    fadd qword zzcor.i
    fst qword zzman.i
    (
    cmp edx,3 : jz exit
    fmul st(0),st(0)
    'fmul st(0),st(0)
    )
    fstp qword esc
    fadd qword zzcor.r
    fst qword zzman.r
    (
    cmp edx,3 : jz exit
    fmul st(0),st(0)
    'fmul st(0),st(0)
    )
    fadd qword esc
    fst qword esc
    fld qword lmt
    fcomip st(1)
    fcomp st(0),st(0)
    jb exit
    inc ecx : cmp ecx,maxit : jl long repeat
    )
    mov i,ecx
    [/code]




    http://picasaweb.google.co.uk/charle...eat=directlink



    Number keys: 1..7 shading scheme

    Arrow keys: move around

    PageUp: zoom in
    PageDown: zoom out
    Home: Increase resolution (slower)
    End: Decrease resolution (faster)

    Esc: quit




    Attached Files Attached Files

  4. #34
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    51
    Posts
    934
    Rep Power
    109

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

    @petr: thanks! so I found after a while and three coffees one good solution for me !

    [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

    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("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_RenderMatrix2D( -2, -2.5, 2, 2.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(220000) As tbgl_tVector2f ' -- TYPE from TBGL
    Local MandelbrotColor (220000) As tbgl_tRGB ' -- TYPE from TBGL
    p = -0.001*Cos(GetTickCount/5000)*100

    ' -- Fill it with data
    'For x = -2 To 1.4 Step 0.00988 'ok
    For x = -2 To 2 Step 0.00988

    For y = -2.5 To 2.5 Step 0.00988
    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 30
    ' 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 = 255
    MandelbrotColor (MandelbrotIndex).B = 255
    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 other 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]

    I don't give up

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    2) part:

    Question!

    (last edit: this morning)

    about my thoughts for mandlebrot calculations:

    a) first and good attempt:

    Local MandelbrotVertex(160000) As tbgl_tVector2f ' -- TYPE from TBGL
    Local MandelbrotColor (160000) As tbgl_tRGB ' -- TYPE from TBGL

    ' -- Fill it with data
    For x = -2 To 1 Step 0.0075 '--> difference 3.0

    For y = -1.5 To 1.5 Step 0.0075 '--> difference 3.0

    b) my thoughts for bigger arranges, just an example.

    Local MandelbrotVertex(260000) As tbgl_tVector2f ' -- TYPE from TBGL
    Local MandelbrotColor (260000) As tbgl_tRGB ' -- TYPE from TBGL

    ' -- Fill it with data
    For x = -2 To 3 Step 0.0025 '--> difference 5.0

    For y = -1.5 To 3.5 Step 0.0025 '--> difference 5.0
    => that's calculation could be correct ?

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

  5. #35
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

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

    Hi Frank,

    you were on the right track with the differences.
    The total amount of items in array is equal to:

    (difference/step+1) * (difference/step+1)

    (so (5/0.0025+1) * (5/0.0025+1) = 4 004 001 in your second example).


    Petr

    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  6. #36
    Have you successfully resolved the issue with the Mandelbrot set rendering, and how do you plan to optimize the array size for larger arrangements in your calculations?

Page 4 of 4 FirstFirst ... 234

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: 35

Posting Permissions

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