import streamlit as st from OpenGL.GL import * from OpenGL.GLU import * from PyQt5.QtWidgets import QApplication import sys class Cube: def __init__(self): self.vertices = ((1.0,-1,-1),(1,1,-1),(-1,1,-1),(-1,-1,-1),(1,-1,1),(1,1,1),(-1,-1,1),(-1,1,1)) self.edges = ((0,1),(0,3),(0,4),(1,2),(1,5),(2,3),(2,6),(3,7),(4,5),(4,7),(5,6),(6,7)) def draw(self): glBegin(GL_LINES) for edge in self.edges: for vertex in edge: glVertex3fv(self.vertices[vertex]) glEnd() def main(): app = QApplication(sys.argv) cube = Cube() st.set_option('dephrecation.showPyplotGlobalUse', False) st.title("3D Cube") # Create an OpenGL context gl_viewport = st_gl(GLsizei(st._get_metric_impl("devicePixelRatio") * 600), GLsizei(st._get_metric_impl("devicePixelRatio") * 600)) st_gl_make_current(gl_viewport) # Set up projection gluPerspective(45, 1, 0.1, 50.0) glTranslatef(0.0, 0.0, -5.0) # Draw the cube glEnable(GL_DEPTH_TEST) while True: for event in QApplication.instance().flushEvents(): if event.type() == QEvent.Close: sys.exit() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) cube.draw() glRotatef(1, 1, 1, 1) st_gl_swap(gl_viewport) if __name__ == '__main__': main()