Results 1 to 2 of 2

Thread: Tree Recursion 2

  1. #1

    Tree Recursion 2

    about the Tree recursion here http://www.thinbasic.com/community/s...ll=1#post90956
    it needs dll and inc file to plot thick lines using another graphics lib. here is an adaptation to use thinbasic TBGL lines in 3D environment. i have used as a skeleton TBGL_TestOf3DViewports.tbasic from the thinbasic examples and using TBGL_NewList tree
    but there is some flicker due to the rotation of thick lines, if it does not rotate then there is no flicker.
    thanks for the original contributors
    tree.PNG
    Uses "math" , "tbgl" 
    Const tree Value 1
    
    ' -- Create and show window
    Dim hWnd As DWord  = TBGL_CreateWindowEx("recursive tree - press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX) 
    
    TBGL_ShowWindow 
    
    TBGL_UseLighting %TRUE
    TBGL_UseLightSource %GL_LIGHT0, %TRUE
    
    TBGL_SetLightParameter %GL_LIGHT0, %TBGL_LIGHT_POSITION, 10, 15, 15, 1
    
    DIM i AS DOUBLE
    DIM FrameRate AS DOUBLE
    
    ' -- Resets status of all keys 
    TBGL_ResetKeyState()
    Dim depth As Long = 9
      TBGL_NewList tree 
      TBGL_PushMatrix
       MainDraw(0, 0, 90, depth)
      TBGL_PopMatrix 
      TBGL_EndList
      
    ' -- Main loop
    While TBGL_IsWindow(hWnd) 
      FrameRate = TBGL_GetFrameRate
    
      TBGL_ClearFrame   
      
     TBGL_PushMatrix
          TBGL_Translate 0, -25, -75
          TBGL_Rotate GetTickCount/20, 0, 1, 0
          'TBGL_Scale 0.7, 0.7, 0.7
          TBGL_UseLighting %FALSE 
          TBGL_CallList tree 
          'MainDraw(0, 0, 90, depth)
          
     TBGL_PopMatrix
       
      
      TBGL_Viewport(0.0, 0, 1.0, 1)
        TBGL_ResetMatrix
        TBGL_RenderMatrix3D(%TBGL_VIEWPORT)
        
        TBGL_Camera 15, 15, 15, 0, 0, 0 
        TBGL_UseLighting %TRUE
    
        TBGL_Color 250, 100, 255
        TBGL_PushMatrix
        TBGL_Translate 5, -10, -5
        TBGL_Sphere 1.5
        TBGL_PopMatrix   
        
        TBGL_Color 255, 255, 250
        TBGL_Box 120, 120, 120    
        'tbgl_box 10, 10, 10
      
    
      TBGL_DrawFrame 
    
      ' -- ESCAPE key to exit application
      If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While 
    
    Wend 
    
    TBGL_DestroyWindow
     
    Sub MainDraw(x1, y1 As Long, angle As Single, d As Long)
    Dim x2, y2 As Long
    
    If d >0 Then
    x2 = x1 + Cos(DegToRad(angle)) * d * 1
    y2 = y1 + Sin(DegToRad(angle)) * d * 1 
    
    'TBGL_Color 255-d*10, 100-d, 70 
    TBGL_Color 255-d*70, 150-d,20 
    TBGL_LineWidth d
    TBGL_Line(x1, y1, x2, y2)
    
    'DrawLine x1, y1, x2, y2, d, Rgb(255-d*10, 100-d, 70)
    MainDraw(x2, y2, angle - 20, d-1)
    MainDraw(x2, y2, angle + 20, d-1)
    End If
    End Sub
    

  2. #2
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,527
    Rep Power
    170
    on my environment it runs fine without any flickering effect.
    I think there are missing some Forum-sections as beta-testing and support

Similar Threads

  1. Tree Recursion
    By peter in forum Sources, Templates, Code Snippets, Tips and Tricks, Do you know ...
    Replies: 13
    Last Post: 12-05-2017, 08:58
  2. Bananas Tree
    By peter in forum Sources, Templates, Code Snippets, Tips and Tricks, Do you know ...
    Replies: 0
    Last Post: 26-03-2014, 20:51
  3. A nice (verbal) example of recursion
    By RobbeK in forum General
    Replies: 2
    Last Post: 25-03-2014, 02:05
  4. Various types of recursion
    By Petr Schreiber in forum Sources, Templates, Code Snippets, Tips and Tricks, Do you know ...
    Replies: 6
    Last Post: 25-05-2010, 06:38
  5. tree view?
    By sandyrepope in forum UI (User Interface)
    Replies: 3
    Last Post: 16-07-2007, 18:18

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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