-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.py
More file actions
63 lines (50 loc) · 1.65 KB
/
Copy path1.py
File metadata and controls
63 lines (50 loc) · 1.65 KB
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
import sys
from PyQt5 import QtWidgets
from PyQt5.QtOpenGL import QGLWidget
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
import numpy as np
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.widget = GLWidget(self)
self.setCentralWidget(self.widget)
self.show()
class GLWidget(QGLWidget):
def __init__(self, parent):
QGLWidget.__init__(self, parent)
self.setMinimumSize(500, 500)
def initializeGL(self):
glClearColor(0.0, 0.0, 0.0, 1.0)
glEnable(GL_DEPTH_TEST)
def paintGL(self):
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
self.draw_func()
def draw_func(self):
x = np.linspace(-5, 5, 400)
y = np.linspace(-5, 5, 400)
X, Y = np.meshgrid(x, y)
Z = np.sin(X*2)
glPushMatrix()
glRotatef(60, 1.0, 0.0, 0.0)
glRotatef(-20, 0.0, 0.0, 1.0)
for i in range(Z.shape[0]-1):
glBegin(GL_TRIANGLE_STRIP)
for j in range(Z.shape[1]):
glVertex3f(X[i,j], Y[i,j], Z[i,j])
glVertex3f(X[i+1,j], Y[i+1,j], Z[i+1,j])
glEnd()
glPopMatrix()
def resizeGL(self, w, h):
glViewport(0, 0, w, h)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(60.0, w/h, 1.0, 100.0)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
gluLookAt(0.0, -10.0, 10.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0)
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
window = MainWindow()
sys.exit(app.exec_())