Results 1 to 6 of 6

Thread: Example: Section 5.2 (page 38/39), Plot Point, Diagonale + mirror 2D Functions

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

    Example: Section 5.2 (page 38/39), Plot Point, Diagonale + mirror 2D Functions

    page 38/39: it's nearly perfect. I have taken two tasks into one. changed colour of plot points to make them different. there are in my eyes four task (lines, points, mirror points, diagonale), all are solved for me. next part will follow later. my doggy wants to walk out now

    [code=thinbasic]' Empty GUI script created on 02-26-2010 14:09:03 by (ThinAIR)

    ' Example 5.25 Plotting 2D Functions

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

    ' Converted by Frank Brübach
    ' Last modified: February 28, 2010


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


    ' Handle for our window
    Local hWnd As DWord

    ' Create and show window
    hWnd = TBGL_CreateWindowEx("Page 38: Plot Point + Mirror by Frank ", 400, 400, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX)
    TBGL_ShowWindow

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

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

    ' Resets status of all keys
    TBGL_ResetKeyState()

    Local x,y, x1,y1, x2,y2 As Single
    ' Main loop
    While TBGL_IsWindow(hWnd)

    TBGL_ClearFrame
    TBGL_Color(0,0,0)
    TBGL_PointSize 3
    x = 0.5
    y = 0.5

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

    TBGL_BeginPoly(%GL_LINES)
    TBGL_Vertex(-1.0,-1.0)
    TBGL_Vertex(1.0,1.0)
    TBGL_EndPoly


    TBGL_Color(255,0,0)

    'one
    TBGL_PointSize 3
    x = y*x
    TBGL_BeginPoly(%GL_POINTS)
    TBGL_Vertex(x,y)
    TBGL_EndPoly
    'two
    TBGL_PointSize 3
    y = x*y
    TBGL_BeginPoly(%GL_POINTS)
    TBGL_Vertex(x,y)
    TBGL_EndPoly
    'three
    TBGL_Color(0,0,255)
    TBGL_PointSize 3
    'mirror x !
    TBGL_BeginPoly(%GL_POINTS)
    TBGL_Vertex(x*(+1),y*(-1))
    TBGL_EndPoly
    'four
    TBGL_Color(0,0,255)
    TBGL_PointSize 3
    'mirror y !
    TBGL_BeginPoly(%GL_POINTS)
    TBGL_Vertex(x*(-1),y*(+1))
    TBGL_EndPoly

    '-------------------------------------------------
    '-----------part one normal
    'glColor3f(0.0, 0.0, 0.0)
    'glBegin(GL_LINES)
    'glVertex2f(-1.0, 0.0)
    'glVertex2f(1.0,0.0)
    'glVertex2f(0.0, 1.0)
    'glVertex2f(0.0, -1.0)
    'glEnd()
    '# Store an ordered pair In variables
    'x = 0.5
    'y = 0.5
    '# Plot points In bright red
    'glColor3f(1.0, 0.0, 0.0)
    '# Increase the point Size
    'glPointSize(3.0)
    'glBegin(GL_POINTS)
    '# Plot the point
    'glVertex2f(x, y)
    '-----------part two mirror!
    '# Plot the mirror Image Or reflection of the point
    '# In the x axis.
    'glVertex2f(-1.0,-1.0)
    'glVertex2f(1.0, 1.0)
    '
    '---------------------------------------------------------

    TBGL_DrawFrame

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

    TBGL_DestroyWindow

    '-I am not quite sure if this is 100 per cent right conversion for this solution [/code]

    edit: fixed version I add with correct window scaling and sizing

    best regards, frank lionhead
    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

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

    Re: Example: Section 5.2 (page 38/39), Plot Point, Diagonale + mirror 2D Functions

    Nicely done Frank!

    This was an exercise in symmetry for my students (and me). I was mainly trying to demonstrate symmetry across both the x and y axes and across the y = x diagonal (leading to inverse functions later, perhaps). I was wanting students to understand the role of switching signs from + to - and - to + for the ordered pairs (x, y) AND to see what happens when we switch x and y, plotting (y, x). Sometimes we get interesting visual and mathematical effects... sometimes almost like a kaleidoscope.

    I have never decided whether I was trying to teach a little programming using mathematics or to teach a little mathematics using programming. No matter... the students seemed to enjoy the experience for the most part and so did I.

    Thanks for your interest and help! I am the complete beginner here and I'm learning by everyone sharing their programs.

    Stan



  3. #3
    thinBasic MVPs Michael Hartlef's Avatar
    Join Date
    Sep 2006
    Location
    Germany
    Age
    58
    Posts
    3,299
    Rep Power
    348

    Re: Example: Section 5.2 (page 38/39), Plot Point, Diagonale + mirror 2D Functio

    Hi Stan,

    As i see that Franck add his personal style to the code i would like to ask if you would like a pure conversion to thinbasic or something modded?

    Michael

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

    Re: Example: Section 5.2 (page 38/39), Plot Point, Diagonale + mirror 2D Functio

    Hi Michael,

    Thanks for asking... the quick answer is that it really doesn't matter to me. I encourage my students to be creative and never intended the examples to be anything more than a starting point. Each exercise and example had a purpose when I wrote them, but it is always interesting to see what new ideas people come up with. The pure conversion would be easy to code based on what Frank has done, so no worries there at all.

    If Frank were in my class, I probably would want to see the original graphic with all symmetries displayed, but after that, students are free to create new versions and go wherever their imagination and code takes them. Also, I make no claims for elegance in coding! I tend to think in a very linear fashion and I'm not very creative, so I would encourage suggestions, improvements, modifications, etc.

    This is all very flattering to me, really, that anyone (not in my class!) would take the time to look through the text and start converting some of the examples to ThinBasic. I was more than willing to share the text, but really didn't expect this kind of response. There are so many great programmers here and I feel so inadequate... I have a lot of learning to do!

    So, Frank can just code away however he sees fit...

    I do think that as a service to others here, though, if the conversion does deviate from the original Python version it would be nice to communicate the differences? That's just my suggestion/opinion.

    Cheers... and thanks!

    Stan

    Quote Originally Posted by Michael Hartlef
    Hi Stan,

    As i see that Franck add his personal style to the code i would like to ask if you would like a pure conversion to thinbasic or something modded?

    Michael

  5. #5
    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.2 (page 38/39), Plot Point, Diagonale + mirror 2D Functions

    Glad you are joining the fun Frank. It is nice to have others getting into it 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

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

    Re: Example: Section 5.2 (page 38/39), Plot Point, Diagonale + mirror 2D Functions

    Yes... certainly! Hopefully I didn't sound critical in my previous post, because that was NOT my intention.

    Code to your heart's content, Frank... welcome!

    Cheers,

    Stan

    Quote Originally Posted by kent sarikaya
    Glad you are joining the fun Frank. It is nice to have others getting into it too.

Similar Threads

  1. Example: Section 5.2 (page 41), Plotting 2D Functions
    By kryton9 in forum ThinBASIC programming in OpenGL/TBGL
    Replies: 18
    Last Post: 01-03-2010, 22:26

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
  •