pyopengl
安装 pip install pyopengl
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
from math import pi
import numpy as np
a=-2*pi
b=2*pi
def init():
glClearColor(0,0,0,1)
gluOrtho2D(a,b,a,b)
def drawfunc():
glClear(GL_COLOR_BUFFER_BIT)
#建立坐标系
glColor3f(0,1,0)
glBegin(GL_LINES)
glVertex2f(a,0)
glVertex2f(b,0)
glVertex2f(0,a)
glVertex2f(0,b)
glEnd()
#正弦函数
glColor3f(0,1,1)
glBegin(GL_LINE_STRIP)
for x in np.arange(a,b,0.1):
y=np.sin(x)
glVertex2f(x,y)
glEnd()
glFlush()
def main():
glutInit()
glutInitDisplayMode(GLUT_RGBA|GLUT_SINGLE)
glutInitWindowPosition(500,300)
glutInitWindowSize(400,400)
glutCreateWindow('window CE')
glutDisplayFunc(drawfunc)
init()
glutMainLoop()
main()