Advertisement
RockField64

CubeOrSquareStickTogether

Dec 6th, 2022
1,108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.91 KB | Source Code | 0 0
  1. import pygame
  2. from pygame.locals import*
  3.  
  4. from OpenGL.GL import*
  5. from OpenGL.GLU import*
  6.  
  7.  
  8. def draw_cube():
  9.     glBegin(GL_SQUARE)
  10.  
  11.     glColor(1, 0, 0)
  12.     glVertex3f(0, 1, 0)
  13.     glVertex3f(-1, -1, 1)
  14.     glVertex3f(1, -1, 1)
  15.  
  16.     glColor(0, 1, 0)
  17.     glVertex3f(0, 1, 0)
  18.     glVertex3f(1, -1, 1)
  19.     glVertex3f(1, -1, -1)
  20.  
  21.     glColor(1, 1, 0)
  22.     glVertex3f(0, 1, 0)
  23.     glVertex3f(1, -1, -1)
  24.     glVertex3f(-1, -1, -1)
  25.  
  26.     glColor(0, 0, 1)
  27.     glVertex3f(0, 1, 0)
  28.     glVertex3f(-1, -1, -1)
  29.     glVertex3f(-1, -1, 1)
  30.  
  31.     glColor(1, 0, 0)
  32.     glVertex3f(0, 3, 0)
  33.     glVertex3f(1, -1, 1)
  34.     glVertex3f(-1, -1, 1)
  35.  
  36.     glColor(1, 1, 0)
  37.     glVertex3f(0, 3, 0)
  38.     glVertex3f(-1, -1, -1)
  39.     glVertex3f(1, -1, -1)
  40.  
  41.     glColor(0, 1, 0)
  42.     glVertex3f(0, -3, 0)
  43.     glVertex3f(1, -1, -1)
  44.     glVertex3f(1, -1, 1)
  45.  
  46.     glColor(0, 0, 1)
  47.     glVertex3f(0, 3, 0)
  48.     glVertex3f(-1, -1, 1)
  49.     glVertex3f(-1, -1, -1)
  50.  
  51.     glEnd()
  52.  
  53. def main():
  54.  pygame.init()
  55. display = (800, 600)
  56. pygame.display.set_mode(display, DOUBLEBUF | OPENGL)
  57. pygame.display.set_caption("05 Performance Task 01")
  58. gluPerspective(45, (display[0] / display[1]), 0.1, 50.0)
  59. glTranslatef(0.0, 0.0, -5)
  60. glScalef(0.5, 0.5, 0.5)
  61. glRotatef(180, 0, 0, 1)
  62.  
  63. while True:
  64.  for event in pygame.event.get():
  65.    if event.type == pygame.QUIT:
  66.       pygame.quit()
  67.    if event.type == pygame.KEYDOWN:
  68.       if event.key == pygame.K_a:
  69.          glTranslatef(-1, 0, 0)
  70.          glScalef(1, 1, 1)
  71.  
  72.       if event.key == pygame.K_d:
  73.          glTranslatef(1, 0, 0)
  74.          glScalef(1, 1, 1)
  75.  
  76.       if event.key == pygame.K_w:
  77.          glTranslatef(0, 1, 0)
  78.          glScalef(-1, -1, -1)
  79.  
  80.       if event.key == pygame.K_s:
  81.          glTranslatef(0, -1, 0)
  82.          glScalef(-1, -1, -1)
  83.  
  84.    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
  85.    draw_cube()
  86.    pygame.display.flip()
  87.    pygame.time.wait(30)
  88.    main()
  89.  
  90.  
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement