Results 1 to 2 of 2

Thread: Example: Section 6.6 (page 148), Predator-prey Relationships

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    160

    Example: Section 6.6 (page 148), Predator-prey Relationships

    [code=thinbasic]
    ' Example: Section 6.6 (page 14, Predator-prey Relationships

    ' From Stan Blank's Book:
    ' "Python Programming in OpenGL
    ' "A Graphical Approach to Programming

    ' Converted by Michael Clease
    ' Last modified: February 26, 2010

    ' thinBasic does not use GLUT, we use instead tbgl
    Uses "TBGL"

    ' Handle for our window
    Local hWnd As DWord
    Local Width As Long
    Local Height As Long
    Local x,y As Double
    Local a,b,c As Double
    Local e,dt As Double
    Local v, n As Double
    '# Initial values of width And height
    width = 400
    height = 400
    '
    ' Create and show window
    hWnd = TBGL_CreateWindowEx("Predator-prey Relationships", Width, Height, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX)
    TBGL_ShowWindow

    ' Set Foreground from default White to Green
    TBGL_Color(76,152,51)
    ' Set background from default black to white
    TBGL_BackColor(255,255,255)
    ' Init OpenGl, like gluOrtho2D in example code
    TBGL_RenderMatrix2D( 0, 0, 10, 6 )
    ' Resets status of all keys
    TBGL_ResetKeyState()
    TBGL_PointSize 1

    dt = 0.001
    ' Main loop
    While TBGL_IsWindow(hWnd)

    a = 0.7
    b = 0.5
    c = 0.3
    e = 0.2
    x = 0.5
    y = 0.5

    TBGL_ClearFrame

    For n = 0 To 10 Step 0.0001
    '# predator-prey equations
    x = x + (a*x - b*x*y)*dt
    y = y + (-c*y + e*x*y)*dt
    TBGL_BeginPoly(%GL_POINTS)
    TBGL_Color(255,0,0)
    TBGL_Vertex(n,x)
    TBGL_Color(0,0,255)
    TBGL_Vertex(n,y)
    TBGL_Color(0,0,0)
    TBGL_Vertex(x,y)
    TBGL_EndPoly
    Next
    TBGL_DrawFrame

    dt += 0.0001
    If dt > 0.005 Then dt = 0.001

    ' ESCAPE key to exit application
    If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
    Wend

    TBGL_DestroyWindow

    [/code]
    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

Similar Threads

  1. Example: Section 6.6 (page 148), Predator-prey Relationships
    By Michael Clease in forum ThinBASIC programming in OpenGL/TBGL
    Replies: 1
    Last Post: 27-02-2010, 01:16

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
  •