|
6 | 6 | """ |
7 | 7 |
|
8 | 8 | import sys, math, time |
9 | | -if sys.version_info[0] < 3 : |
| 9 | +if sys.version_info[0] < 3: |
10 | 10 | from Tkinter import Tk, YES, BOTH |
11 | 11 | else: |
12 | 12 | from tkinter import Tk, YES, BOTH |
13 | 13 | from OpenGL import GL, GLU |
14 | 14 | from pyopengltk import OpenGLFrame |
15 | 15 |
|
| 16 | + |
16 | 17 | class AppOgl(OpenGLFrame): |
17 | 18 |
|
18 | 19 | def initgl(self): |
19 | | - GL.glViewport( 0, 0, self.width, self.height) |
20 | | - GL.glClearColor(1.0,1.0,1.0,0.0) |
21 | | - GL.glColor3f(0.0,0.0, 0.0) |
| 20 | + GL.glViewport(0, 0, self.width, self.height) |
| 21 | + GL.glClearColor(1.0, 1.0, 1.0, 0.0) |
| 22 | + GL.glColor3f(0.0, 0.0, 0.0) |
22 | 23 | GL.glPointSize(4.0) |
23 | 24 | GL.glMatrixMode(GL.GL_PROJECTION) |
24 | 25 | GL.glLoadIdentity() |
25 | | - GLU.gluOrtho2D(-5,5,-5,5) |
| 26 | + GLU.gluOrtho2D(-5, 5, -5, 5) |
26 | 27 | self.start = time.time() |
27 | 28 | self.nframes = 0 |
28 | | - |
29 | 29 |
|
30 | 30 | def redraw(self): |
31 | 31 | GL.glClear(GL.GL_COLOR_BUFFER_BIT) |
32 | 32 | GL.glBegin(GL.GL_POINTS) |
33 | 33 | npt = 100 |
34 | 34 | for i in range(npt): |
35 | | - x = -5.0 + i*10.0/npt |
36 | | - y = math.sin(x+ time.time())*5/2 |
37 | | - GL.glVertex2f( x, y ) |
| 35 | + x = -5.0 + i * 10.0 / npt |
| 36 | + y = math.sin(x + time.time())*5/2 |
| 37 | + GL.glVertex2f(x, y) |
38 | 38 | GL.glEnd() |
39 | 39 | GL.glFlush() |
40 | | - self.nframes+=1 |
| 40 | + self.nframes += 1 |
41 | 41 | tm = time.time() - self.start |
42 | | - print("fps",self.nframes / tm, end="\r" ) |
| 42 | + print("fps", self.nframes / tm, end="\r") |
| 43 | + |
43 | 44 |
|
44 | 45 | if __name__ == '__main__': |
45 | 46 | root = Tk() |
46 | 47 | app = AppOgl(root, width=320, height=200) |
47 | 48 | app.pack(fill=BOTH, expand=YES) |
48 | | - app.animate=1 |
| 49 | + app.animate = 1 |
49 | 50 | app.after(100, app.printContext) |
50 | 51 | app.mainloop() |
0 commit comments