Python (with Turtle)

No description

fork
loading
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *


class Pyramid:

    vertices = (
   	 (1, -1, -1),
   	 (1, 1, -1),
   	 (-1, 1, -1),
   	 (-1, -1, -1),
   	 (0, 0, 1)
    )
    edges = (
   	 (0, 1),
   	 (0, 3),
   	 (0, 4),
   	 (1, 4),
   	 (1, 2),
   	 (2, 4),
   	 (2, 3),
   	 (3, 4),
    )

    def __init__(self):
   	 self.edges = Pyramid.edges
   	 self.vertices = Pyramid.vertices

    def draw(self):
   	 glLineWidth(5)
   	 glBegin(GL_LINES)
   	 for edge in self.edges:
   		 for vertex in edge:
   			 glVertex3fv(self.vertices[vertex])
   			 glColor3f(1, 0, 1)
   	 glEnd()



def main():
    pygame.init()
    display = (800, 800)
    pygame.display.set_mode(display, DOUBLEBUF|OPENGL)

    gluPerspective(45, (display[0]/display[1]), 0.1, 50)

    p = Pyramid()

    vel = 0.1
    clock = pygame.time.Clock()
    while True:
   	 clock.tick(60)
   	 for event in pygame.event.get():
   		 if event.type == pygame.QUIT:
   			 pygame.quit()
   			 quit()

   	 keys = pygame.key.get_pressed()
   	 if keys[pygame.K_a]:
   		 glTranslatef(vel, 0, 0)
   	 if keys[pygame.K_d]:
   		 glTranslatef(-vel, 0, 0)
   	 if keys[pygame.K_w]:
   		 glTranslatef(0, -vel, 0)
   	 if keys[pygame.K_s]:
   		 glTranslatef(0, vel, 0)
   	 if keys[pygame.K_t]:
   		 glTranslatef(0, 0, vel)
   	 if keys[pygame.K_g]:
   		 glTranslatef(0, 0, -vel)
   	 if keys[pygame.K_LEFT]:
   		 glRotatef(0.5, 0, -1, 0)
   	 if keys[pygame.K_RIGHT]:
   		 glRotatef(0.5, 0,1, 0)


   	 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
   	 p.draw()
   	 pygame.display.flip()


main()


result
console