Initial working port
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
kleph 2022-11-09 00:18:27 +01:00
parent 593ff2075e
commit abc4d1976c
3 changed files with 45 additions and 75 deletions

View file

@ -10,4 +10,6 @@ steps:
- name: python lint - name: python lint
image: cytopia/pylint image: cytopia/pylint
commands: commands:
- apk add --no-cache py3-pip
- pip3 install -r requirements.txt
- find . -type f -name "*.py" | xargs pylint - find . -type f -name "*.py" | xargs pylint

View file

@ -1,6 +1,6 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: iso8859-15 -*- # -*- coding: iso8859-15 -*-
# projection variable d'un hypercube """ projection variable d'un hypercube"""
# pour l'interaction avec le système # pour l'interaction avec le système
# pour sqrt() et pow() # pour sqrt() et pow()
@ -8,6 +8,9 @@ import math
# pour les nombres aléatoires # pour les nombres aléatoires
from random import randint from random import randint
import pygame as pg
from pygame.locals import *
# importe tout ce qui est contenu dans le package OpenGL # importe tout ce qui est contenu dans le package OpenGL
from OpenGL.GL import * from OpenGL.GL import *
# GLU première couche au dessus d'OpenGL # GLU première couche au dessus d'OpenGL
@ -83,13 +86,7 @@ def draw():
# couleur par défaut (le fond entre autre) # couleur par défaut (le fond entre autre)
glClearColor(0.0, 0.0, 0.0, 0.0) glClearColor(0.0, 0.0, 0.0, 0.0)
glClear(GL_COLOR_BUFFER_BIT) glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
# positionne la vue
gluLookAt(x, y, z,
cx, cy, cz,
0.0, 1.0, 0.0)
if frepere == 1: if frepere == 1:
draw_repere() draw_repere()
@ -103,43 +100,47 @@ def draw():
draw_hypercube(varAnim[0], varAnim[1], varAnim[2], varAnim[3]) draw_hypercube(varAnim[0], varAnim[1], varAnim[2], varAnim[3])
# double buffer, on dessine en mémoire et on affiche quand c'est pret
glutSwapBuffers()
# gestion du clavier # gestion du clavier
def keyboard(key, x, y): def keyboard(key):
""" gère les touches normales""" """ gère les touches normales"""
global frepere global frepere
global flagsAnim global flagsAnim
global fullscreen global fullscreen
global cx, cy, cz
if key == chr(27): if key == K_ESCAPE:
sys.exit(0) pg.quit()
quit()
if key == 'f': if key == K_f:
if fullscreen: pass
glutReshapeWindow(640, 480)
else:
glutFullScreen()
fullscreen = 1 - fullscreen fullscreen = 1 - fullscreen
if key == 'a': if key == K_a:
frepere = 1 - frepere frepere = 1 - frepere
if key == 'u': if key == K_u:
flagsAnim[0] = 1 - flagsAnim[0] flagsAnim[0] = 1 - flagsAnim[0]
if key == 'i': if key == K_i:
flagsAnim[1] = 1 - flagsAnim[1] flagsAnim[1] = 1 - flagsAnim[1]
if key == 'o': if key == K_o:
flagsAnim[2] = 1 - flagsAnim[2] flagsAnim[2] = 1 - flagsAnim[2]
if key == 'p': if key == K_p:
flagsAnim[3] = 1 - flagsAnim[3] flagsAnim[3] = 1 - flagsAnim[3]
glutPostRedisplay() if key == K_LEFT:
cx = cx - 1
elif key == K_RIGHT:
cx = cx + 1
elif key == K_UP:
cy = cy + 1
elif key == K_DOWN:
cy = cy - 1
def draw_line(x1, y1, z1, x2, y2, z2): def draw_line(x1, y1, z1, x2, y2, z2):
""" dessine une ligne""" """ dessine une ligne"""
@ -149,6 +150,7 @@ def draw_line(x1, y1, z1, x2, y2, z2):
glVertex3f(x2, y2, z2) glVertex3f(x2, y2, z2)
glEnd() glEnd()
def draw_repere(): def draw_repere():
""" dessine le repère orthogonal""" """ dessine le repère orthogonal"""
glBegin(GL_LINES) glBegin(GL_LINES)
@ -163,6 +165,7 @@ def draw_repere():
glVertex3i(0, 0, 1) glVertex3i(0, 0, 1)
glEnd() glEnd()
def draw_hypercube(a1, b1, c1, d1): def draw_hypercube(a1, b1, c1, d1):
"""dessine l'hypercube """ """dessine l'hypercube """
@ -299,56 +302,20 @@ def draw_hypercube(a1, b1, c1, d1):
glEnd() glEnd()
def specialkey(key, kx, ky):
""" gère les touches spéciales"""
global cx, cy, cz
if key == GLUT_KEY_LEFT:
cx = cx - 1
elif key == GLUT_KEY_RIGHT:
cx = cx + 1
elif key == GLUT_KEY_UP:
cy = cy + 1
elif key == GLUT_KEY_DOWN:
cy = cy - 1
glutPostRedisplay()
def mouse_move(mx, my):
""" gère les mouvements de la souris lorqu'aucun bouton n'est enfoncé """
pass
def mouse_move_button(mx, my):
""" gère les mouvements de la souris lorqu'au moins un bouton est enfoncé """
pass
def mouse_button(boutton, etat, mx, my):
""" gère les appuis et relachement de bouttons de la souris """
pass
# main # main
# initialisation pg.init()
glutInit([]) windowSize = (1152, 720)
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE) pg.display.set_mode(windowSize, DOUBLEBUF | OPENGL)
glutInitWindowSize(640,480)
glutCreateWindow(sys.argv[0])
# glutFullScreen()
glutDisplayFunc(draw)
glutKeyboardFunc(keyboard)
glutSpecialFunc(specialkey)
glutPassiveMotionFunc(mouse_move)
glutMotionFunc(mouse_move_button)
glutMouseFunc(mouse_button)
glutIdleFunc(draw)
glMatrixMode(GL_PROJECTION) # setup PoV
glLoadIdentity() gluPerspective(60, (windowSize[0]/windowSize[1]), 0.1, 100.0)
glOrtho(-5, 5, -5, 5, -5, 5)
glMatrixMode(GL_MODELVIEW)
# boucle glut, gère les évènements, et appèle draw() glTranslatef(0.0, 0.0, -5)
glutMainLoop()
while True:
for event in pg.event.get():
if event.type == pg.KEYDOWN:
keyboard(event.key)
draw()
pg.display.flip()

1
requirements.txt Normal file
View file

@ -0,0 +1 @@
pygame