forked from burakbayramli/books
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ch5ex10.py
49 lines (39 loc) · 902 Bytes
/
ch5ex10.py
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
# PyFunc.py
# Plotting functions
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
from numpy import *
import sys
def init():
glClearColor(1.0, 1.0, 1.0, 1.0)
gluOrtho2D(-2.0, 2.0, -2.0, 2.0)
def plotFunc():
glClear(GL_COLOR_BUFFER_BIT)
glColor3f(0.0, 0.0, 0.0)
glBegin(GL_LINES)
glVertex2f(-5,0)
glVertex2f(5,0)
glVertex2f(0,5)
glVertex2f(0,-5)
glEnd()
#glPointSize(3.0)
glColor3f(1.0,0.0,0.0)
r = 1.0
glBegin(GL_POINTS)
for x in arange(-5.0, 5.0, 0.01):
y = sqrt(r**2 - x**2)
glVertex2f(x, y)
# do we need another glVertex2f statement here?
glEnd()
glFlush()
def main():
glutInit(sys.argv)
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB)
glutInitWindowPosition(50,50)
glutInitWindowSize(400,400)
glutCreateWindow("Function Plotter")
glutDisplayFunc(plotFunc)
init()
glutMainLoop()
main()