用Python&OpenGL采用种子递归法填充汉字

来源:互联网 发布:加内特2004季后赛数据 编辑:程序博客网 时间:2024/05/16 05:52

这个glReadPixels()的印度函数跟E哥研究了一下午感觉有毒,至于蓝色的值为什么是那个数字,说实话我也没搞明白,哪位大佬知道了告诉我一下

贴一下运行结果

贼丑的梦字

贼丑的梦字,我快丑哭了

下面贴代码

from OpenGL.GL import *  from OpenGL.GLU import *  from OpenGL.GLUT import *import syspoint = 0sys.setrecursionlimit(1000000)def drawmeng():    glClear(GL_COLOR_BUFFER_BIT)    glBegin(GL_LINE_LOOP)    glColor3f(0.0, 0.0, 1.0)    glVertex2i(-5, 15)    glVertex2i(-15, 15)    glVertex2i(-15, 25)    glVertex2i(-20, 25)    glVertex2i(-20, 15)    glVertex2i(-30, 15)    glVertex2i(-30, 10)    glVertex2i(-25, 10)    glVertex2i(-30, 5)    glVertex2i(-30, 0)    glVertex2i(-20, 5)    glVertex2i(-20, 0)    glVertex2i(-15, 0)    glVertex2i(-15, 5)    glVertex2i(-5, 0)    glVertex2i(-5, 5)    glVertex2i(-10, 10)    glVertex2i(-5, 10)    glEnd()    glBegin(GL_LINE_LOOP)    glColor3f(0.0, 0.0, 1.0)    glVertex2i(5, 15)    glVertex2i(15, 15)    glVertex2i(15, 25)    glVertex2i(20, 25)    glVertex2i(20, 15)    glVertex2i(30, 15)    glVertex2i(30, 10)    glVertex2i(25, 10)    glVertex2i(30, 5)    glVertex2i(30, 0)    glVertex2i(20, 5)    glVertex2i(20, 0)    glVertex2i(15, 0)    glVertex2i(15, 5)    glVertex2i(5, 0)    glVertex2i(5, 5)    glVertex2i(10, 10)    glVertex2i(5, 10)    glEnd()    glBegin(GL_LINE_LOOP)    glColor3f(0.0, 0.0, 1.0)    glVertex2i(-15, -5)    glVertex2i(-20, -20)    glVertex2i(-15, -20)    glVertex2i(-10, -10)    glVertex2i(0, -20)    glVertex2i(-8, -30)    glVertex2i(0, -30)    glVertex2i(15, -5)    glEnd()    glBegin(GL_LINE_LOOP)    glColor3f(0.0, 0.0, 1.0)    glVertex2i(-8, -8)    glVertex2i(8, -8)    glVertex2i(2, -18)    glEnd()    fill(-17, 15, 16711680)    fill(17, 15, 16711680)    fill(8, -7, 16711680)def fill(x, y, bordercolor):    global point    point = point + 1    if getpixel(x, y) != bordercolor:        setpixel(x, y)        fill(x, y-1, bordercolor)        fill(x, y+1, bordercolor)        fill(x-1, y, bordercolor)        fill(x+1, y, bordercolor)def setpixel(x, y):    glBegin(GL_POINTS)    glColor3f(0.0, 0.0, 1.0)    glVertex2i(x, y)    glEnd()    glFlush()def getpixel(x, y):    a = (GLuint * 1)(0)    glReadPixels(x+100, y+100, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, a)    return int(a[0])if __name__ == '__main__':    glutInit()    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)    glutInitWindowSize(200, 200)    glutCreateWindow("HomeworkTwo")    glLoadIdentity()    gluOrtho2D(-100, 100, -100, 100)    glutDisplayFunc(drawmeng)    glutMainLoop()
0 0
原创粉丝点击