Results 1 to 4 of 4

Thread: Example section 5.3 ff: circles, ellipse and more (page 50-53)

  1. #1
    Member
    Join Date
    Feb 2010
    Age
    30
    Posts
    47
    Rep Power
    19

    Example section 5.3 ff: circles, ellipse and more (page 50-53)

    my first attempt

    page 50-53, section 5.3 ff.
    nearly exactly code conversion from stans PyOpenGL book.
    modified only a little the view point because there were no exactly definitions for this.

    [code=thinbasic]' Example 5.3 ff. plotting circles, ellipses and more

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

    ' Converted by denis christianssen, march 02, 2010


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

    ' -- Function where program begins
    Function TBMain()
    ' Handle for our window
    Local hWnd As DWord

    ' Create and show window
    hWnd = TBGL_CreateWindowEx("page 50-52: section 5.3ff: Circle, Ellipse.. by Denis", 400, 400, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX)
    TBGL_ShowWindow

    Init()

    ' Resets status of all keys
    TBGL_ResetKeyState()

    ' Define "Callback" to be fired + that it should be fired each 40ms
    TBGL_BindPeriodicFunction(hWnd, "PlotFunc", 40)

    ' -- Once the command below is executed, further script execution
    ' -- is halted and only periodic calling of the bound function is performed
    TBGL_ProcessPeriodicFunction(hWnd)

    ' -- Close window, if we have quite periodic function
    TBGL_DestroyWindow

    End Function

    Sub Init()
    ' Set background from default black to white
    TBGL_BackColor(255,255,255)

    ' Set rendering color to black
    TBGL_Color(0,0,0)

    ' Set point size to 3
    TBGL_PointSize 3
    End Sub

    'def plotfunc():
    'glClear(GL_COLOR_BUFFER_BIT)
    'glColor3f(0.0, 0.0, 0.0)
    'glPointSize(1.0)
    '# Plot the coordinate axes
    'glBegin(GL_LINES)
    'glVertex2f(-2.0, 0.0)
    'glVertex2f(2.0, 0.0)
    'glVertex2f(0.0, 2.0)
    'glVertex2f(0.0, -2.0)
    'glEnd()
    '# Plot the parametric equations
    'For t In arange(0.0,6.28, 0.001):
    'x = Sin(t)
    'y = Cos(t)
    'glBegin(GL_POINTS)
    'glVertex2f(x, y)
    'glEnd()
    'glFlush()
    '# End plotfunc()


    Sub PlotFunc()
    ' -- Which window does call?
    Local hWnd As DWord = TBGL_CallingWindow
    Local x,y,t As Single

    TBGL_ClearFrame
    ' Init OpenGl, like gluOrtho2D in example code
    TBGL_RenderMatrix2D( -2, -2, 2, 2 )

    TBGL_Color(0,0,0)
    TBGL_PointSize 1
    x = 0.5
    y = 0.5

    TBGL_BeginPoly(%GL_LINES)
    TBGL_Vertex(-2.0,0.0)
    TBGL_Vertex(2.0,0.0)
    TBGL_Vertex(0.0,2.0)
    TBGL_Vertex(0.0,-2.0)
    TBGL_EndPoly

    ' Like glBegin(GL_POINTS) in example code
    TBGL_BeginPoly(%GL_LINES)

    'For t In arange(0.0,6.28, 0.001):
    'x = Sin(t)
    'y = Cos(t)
    'glBegin(GL_POINTS)
    'glVertex2f(x, y)

    TBGL_Color(0,0,255)
    For t = 0.0 To 6.28 Step 0.001
    x = Sin(t)
    y = Cos(t)
    TBGL_Vertex(x,y)
    Next

    'What happens If we change the
    'equations For x And y? What happens If we let t range from -6.28 To 6.28?3 Try it!
    'Change the x And y equations To: x = Cos(3*t) And y = Sin(5*t) respectively
    'And change the range of t To: For t In arange(-6.28, 6.28, 0.01):

    TBGL_Color(255,0,0)
    For t = -6.28 To 6.28 Step 0.01
    x = Cos(3*t)
    y = Sin(5*t)
    TBGL_Vertex(x,y)
    Next

    TBGL_EndPoly

    TBGL_DrawFrame

    ' ESCAPE key to disable callback
    If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then
    TBGL_UnBindPeriodicFunction( hWnd )
    Exit Sub
    End If

    End Sub

    [/code]

    makes fun! -> by the way: what's the math. name for the spiral thing ?

    bye, denis
    Attached Images Attached Images
    Attached Files Attached Files

  2. #2
    Member sblank's Avatar
    Join Date
    Feb 2010
    Location
    Wayne City, Illinois
    Posts
    80
    Rep Power
    23

    Re: Example section 5.3 ff: circles, ellipse and more (page 50-53)

    Nicely done, Denis...

    As a class of objects, these spirals are usually called Bowditch or Lissajous curves although particular ones may have their own specific names as stated in the text. They are formed using a set of parametric equations [x = Asin(at+c), y = Bsin(bt)] or something similar. I call them "Etch-a-Sketch" curves, although I've probably violated copyright laws by doing so

    Does this answer your question? Anyway, well done!

    Stan

    Quote Originally Posted by christianssen
    my first attempt

    page 50-53, section 5.3 ff.
    nearly exactly code conversion from stans PyOpenGL book.
    modified only a little the view point because there were no exactly definitions for this.


    makes fun! -> by the way: what's the math. name for the spiral thing ?

    bye, denis

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

    Re: Example section 5.3 ff: circles, ellipse and more (page 50-53)

    hello denis, stan,

    denis, you made a good work for your circle, ellipse conversion ! cool job for a beginner!

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

  4. #4
    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 5.3 ff: circles, ellipse and more (page 50-53)

    Thanks for joining the fun Denis and good job converting, especially since you are so new to thinBasic too.
    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 5.4 (page 41), Combined with Exercise 1 (page 44)
    By kryton9 in forum ThinBASIC programming in OpenGL/TBGL
    Replies: 2
    Last Post: 26-02-2010, 20:46

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
  •