I am trying to build a rotating 3d cube without using any external python 3d module. This is my code:
import pygame
WIDTH, HEIGHT = 700, 500
win = pygame.display.set_mode((WIDTH, HEIGHT))
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
points = [
[100, 100],
[200, 100],
[100, 200],
[200, 200],
[100, 100],
[200, 100],
[100, 190],
[100, 100],
[200, 100],
[100, 190],
[100, 100],
[200, 100],
[100, 190]
]
joining = [
(0, 1),
(0, 2),
(1, 3),
(2, 3),
(1, 4),
(2, 6),
(4, 6),
(4, 7),
(6, 9),
(7, 9),
(7, 10),
(9, 12),
(10, 12)
]
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
win.fill(WHITE)
if points[0][0] <= points[3][0]:
points[0][0] += 0.1
points[2][0] += 0.1
points[3][1] -= 0.03
points[6][1] += 0.009
elif points[4][0] <= points[0][0]:
points[4][0] += 0.1
points[6][0] += 0.1
points[2][1] -= 0.03
points[9][1] += 0.009
points[1][0] -= 0.1
points[3][0] -= 0.1
points[3][1] += 0.001
else:
points[7][0] += 0.1
points[9][0] += 0.1
points[6][1] -= 0.03
points[12][1] += 0.009
for point in points:
pygame.draw.circle(win, BLACK, point, 2)
for join in joining:
pygame.draw.line(win, BLACK, points[join[0]], points[join[1]])
pygame.display.flip()
pygame.quit()
The cube is not working fine. Can i have a more efficient way of drawing this cube in python without using any external module like OpenGl or something like that. Running the code is advised to check what i am saying.