Lionheart008
26-02-2010, 16:25
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 ;)
' 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 ;)
edit: fixed version I add with correct window scaling and sizing
best regards, frank lionhead
' 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 ;)
edit: fixed version I add with correct window scaling and sizing
best regards, frank lionhead