Advertisement
Pug_coder

GraphicsLab1

Mar 1st, 2022
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. import glfw
  2.  
  3. delta = 0.1
  4. angle = 0.0
  5. posx = 0.0
  6. posy = 0.0
  7. size = 0.0
  8. window = None
  9.  
  10. from OpenGL.GL import *
  11.  
  12.  
  13. def main():
  14. global window
  15.  
  16. if not glfw.init():
  17. return
  18. window = glfw.create_window(640, 640, "Lab1", None, None)
  19. if not window:
  20. glfw.terminate()
  21. return
  22. glfw.make_context_current(window)
  23. glfw.set_key_callback(window, key_callback)
  24. glfw.set_scroll_callback(window, scroll_callback)
  25. while not glfw.window_should_close(window):
  26. display()
  27. glfw.destroy_window(window)
  28. glfw.terminate()
  29.  
  30.  
  31. def key_callback(window, key, scancode, action, mods):
  32. global angle, delta, posx, posy
  33. if action == glfw.PRESS:
  34. if key == glfw.KEY_RIGHT:
  35. delta = -3
  36. if key == 263:
  37. delta = 3
  38. if key == glfw.KEY_ENTER:
  39. delta = 0
  40. if key == glfw.KEY_UP:
  41. posy += 0.05
  42. if key == glfw.KEY_DOWN:
  43. posy -= 0.05
  44.  
  45.  
  46. def scroll_callback(window, xoffset, yoffset):
  47. global size
  48. if xoffset > 0:
  49. size -= yoffset / 10
  50. else:
  51. size += yoffset / 10
  52.  
  53.  
  54. def display():
  55. global angle, delta
  56.  
  57. glClear(GL_COLOR_BUFFER_BIT)
  58. glLoadIdentity()
  59. glClearColor(1.0, 1.0, 1.0, 1.0)
  60. glPushMatrix()
  61. glRotatef(angle, 0, 0, 1)
  62. glBegin(GL_POLYGON)
  63. glColor3f(0.1, 0.1, 0.1)
  64. glVertex2f(posx + size, posy + size + 0.5)
  65. glColor3f(0.0, 1.0, 1.0)
  66. glVertex2f(posx + size - 0.6, posy - size + 0.1)
  67. glColor3f(0.35, 0.0, 0.89)
  68. glVertex2f(posx - size - 0.5, posy + size + -0.5)
  69. glColor3f(0.0, 1.0, 1.0)
  70. glVertex2f(posx + size + 0.5, posy - size + -0.5)
  71. glColor3f(0.0, 1.0, 1.0)
  72. glVertex2f(posx + size + 0.6, posy - size + 0.1)
  73. glEnd()
  74. glPopMatrix()
  75. angle += delta
  76. glfw.swap_buffers(window)
  77. glfw.poll_events()
  78.  
  79.  
  80. main()
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement