Results 1 to 2 of 2

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

  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 ' glClear(GL_COLOR_BUFFER_BIT)

    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


    'from OpenGL.GLUT import *
    'from random import *
    'from numpy import *
    'import sys
    '# Initial values of width And height
    'width = 400
    'height = 400
    'def init():
    '# White background
    'glClearColor(1.0, 1.0, 1.0, 0.0)
    '# Set the projection matrix... our "view"
    'glMatrixMode(GL_PROJECTION)
    'glLoadIdentity()
    '# Set the plot Window range
    'gluOrtho2D(0,10,0,6)
    '# Set the matrix For the object we are drawing
    'glMatrixMode(GL_MODELVIEW)
    'glLoadIdentity()
    'def plotpredprey():
    '# habitat And population PARAMETERS
    'a = 0.7
    'b = 0.5
    'c = 0.3
    'e = 0.2
    '# time increment
    'dt = 0.001
    '# initial populations
    'x = 0.5
    'y = 0.5
    'glClear(GL_COLOR_BUFFER_BIT)
    'For n In arange(0,10, 0.0001):
    '# predator-prey equations
    'x = x + (a*x - b*x*y)*dt
    'y = y + (-c*y + e*x*y)*dt
    'glBegin(GL_POINTS)
    '# parametric plot
    '#glColor3f(0.0,0.0,0.0)
    '#glVertex2f(x,y)
    '150
    '# prey
    'glColor3f(1.0, 0.0, 0.0)
    'glVertex2f(n,x)
    '# predator
    'glColor3f(0.0, 0.0, 1.0)
    'glVertex2f(n,y)
    'glEnd()
    'glFlush()
    [/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

  2. #2
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    68
    Posts
    3,865
    Rep Power
    405

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

    That's a neat one Michael!
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

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, 04:56

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
  •