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
image: cytopia/pylint
commands:
- apk add --no-cache py3-pip
- pip3 install -r requirements.txt
- find . -type f -name "*.py" | xargs pylint

View file

@ -1,6 +1,6 @@
#!/usr/bin/python
# -*- coding: iso8859-15 -*-
# projection variable d'un hypercube
""" projection variable d'un hypercube"""
# pour l'interaction avec le système
# pour sqrt() et pow()
@ -8,6 +8,9 @@ import math
# pour les nombres aléatoires
from random import randint
import pygame as pg
from pygame.locals import *
# importe tout ce qui est contenu dans le package OpenGL
from OpenGL.GL import *
# GLU première couche au dessus d'OpenGL
@ -83,13 +86,7 @@ def draw():
# couleur par défaut (le fond entre autre)
glClearColor(0.0, 0.0, 0.0, 0.0)
glClear(GL_COLOR_BUFFER_BIT)
glLoadIdentity()
# positionne la vue
gluLookAt(x, y, z,
cx, cy, cz,
0.0, 1.0, 0.0)
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
if frepere == 1:
draw_repere()
@ -103,43 +100,47 @@ def draw():
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
def keyboard(key, x, y):
def keyboard(key):
""" gère les touches normales"""
global frepere
global flagsAnim
global fullscreen
global cx, cy, cz
if key == chr(27):
sys.exit(0)
if key == K_ESCAPE:
pg.quit()
quit()
if key == 'f':
if fullscreen:
glutReshapeWindow(640, 480)
else:
glutFullScreen()
if key == K_f:
pass
fullscreen = 1 - fullscreen
if key == 'a':
if key == K_a:
frepere = 1 - frepere
if key == 'u':
if key == K_u:
flagsAnim[0] = 1 - flagsAnim[0]
if key == 'i':
if key == K_i:
flagsAnim[1] = 1 - flagsAnim[1]
if key == 'o':
if key == K_o:
flagsAnim[2] = 1 - flagsAnim[2]
if key == 'p':
if key == K_p:
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):
""" dessine une ligne"""
@ -149,6 +150,7 @@ def draw_line(x1, y1, z1, x2, y2, z2):
glVertex3f(x2, y2, z2)
glEnd()
def draw_repere():
""" dessine le repère orthogonal"""
glBegin(GL_LINES)
@ -163,6 +165,7 @@ def draw_repere():
glVertex3i(0, 0, 1)
glEnd()
def draw_hypercube(a1, b1, c1, d1):
"""dessine l'hypercube """
@ -299,56 +302,20 @@ def draw_hypercube(a1, b1, c1, d1):
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
# initialisation
glutInit([])
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE)
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)
pg.init()
windowSize = (1152, 720)
pg.display.set_mode(windowSize, DOUBLEBUF | OPENGL)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(-5, 5, -5, 5, -5, 5)
glMatrixMode(GL_MODELVIEW)
# setup PoV
gluPerspective(60, (windowSize[0]/windowSize[1]), 0.1, 100.0)
# boucle glut, gère les évènements, et appèle draw()
glutMainLoop()
glTranslatef(0.0, 0.0, -5)
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