2013-10-31 68 views
-5

我的python代碼不會運行!?我的python代碼不會運行?

我不知道如何解決這個問題。有人可以幫助我嗎?

錯誤:

Traceback (most recent call last): 
File "C:\Python27\lib\site-packages\OpenGL\GLUT\special.py", line 120, in safeCall 
return function(*args, **named) 
File "C:/Users/zera7777/Desktop/New.py", line 106, in testCyrusBeck 
numpy = point2Array([[0,3],[0,6],[4,6],[6,4],[6,0],[3,0]]) 
TypeError: 'list' object is not callable 
GLUT Idle callback <function testCyrusBeck at 0x02AD8F30> with(),{} failed: returning None 'list' object is not callable 

代碼:

from OpenGL.GL import * 
    from OpenGL.GLU import * 
    from OpenGL.GLUT import * 

    class Line2Segment(object): 
    def Vector2(self): 
     Vector2=norm() 
     Vector2.c = second - first 
     Vector2.normalVector = c.GetNormalVector() 
     return normalVector 
    def Line2Segment(self): 
     first.x=first.y=0 
     second.x=second.y=0 
    def __init__(self,first=0,second=0): 
     self.first=first 
     self.second=second 
    def Line2Segment(self): 
     first=self.first 
     second=self.second 

    class Line2(object): 
    def Line2(self): 
     pt.x=pt.y=0 
     norm.x=norm.y=0 
    def __init__(self,pt=0,norm=0): 
     self.pt=pt 
     self.norm=norm 
    def Line2(self): 
     pt=self.pt 
     norm=self.norm 

    class Line2List(object): 
    def num(self): 
     return line.size() 
    def push_back(self): 
     self.create_line(x0, y0, x1, y1, fill="#4760bf", width=3) 
    def __lshift__(self,index): 
     self.file.write(str(index)) 
     return self 

    def chopCI(tIn,tOut,number,denom): 
    if denom<0: 
     tHit=number/denom 
     if tHit>tOut: 
     return 0 
     elif tHit>tIn: 
     tIn=tHit 
     elif denom>0: 
     tHit=number/denom 
     if tHit<tIn: 
     return 0 
     if tHit<tOut: 
     tOut=tHit 
    elif number<=0: 
     return 0 
    return 1 


    def CyrusBeckClip(seg,L): 
    tIn=0.0 
    tOut=1.0 
    c=seg.second-seg.first 
    L=Line2List.num() 
    for i in range(1,L): 
     tmp=L.line[i].pt-seg.first 
     number=L.line[i].norm*tmp 
     denom=L.line[i].norm*c 
     if(not chopCI(tIn,tOut,number,denom)): 
     return 0 
    if tOut<1.0: 
     seg.second=seg.first+c*tOut 
    if tIn>0.0: 
     seg.first=seg.first+c*tIn 
    return 1 


    def testLineSegment(self,AC,polygon): 
    glColor3f(0.0,0.0,1.0) 
    glBegin(GL_LINES) 
    glVertex2d(AC.first.x,AC.first.y) 
    glVertex2d(AC.second.x,AC.second.y) 
    glEnd() 
    glColor3f(0.0,1.0,1.0) 
    glBegin(GL_POINTS) 
    glVertex2d(AC.first.x,AC.first.y) 
    glVertex2d(AC.second.x,AC.second.y) 
    glEnd() 

    result = CyrusBeckClip(AC,polygon) 
    if result==0: 
     printf("") 
    else: 
     glColor3f(0.0,1.0,0.0) 
     glBegin(GL_LINES) 
     glVertex2d(AC.first.x,AC.first.y) 
     glVertex2d(AC.second.x,AC.second.y) 
     glEnd() 
     glColor3f(1.0,0.0,1.0) 
     glBegin(GL_POINTS) 
     glVertex2d(AC.first.x,AC.first.y) 
     glVertex2d(AC.second.x,AC.second.y) 
     glEnd() 

    def testCyrusBeck(): 
    point2Array=[] 
    numpy = point2Array([[0,3],[0,6],[4,6],[6,4],[6,0],[3,0]]) 
    glColor3f(1.0,1.0,0.0) 
    glBegin(GL_LINE_LOOP) 
    for i in range(1,7): 
     tempPoint.x = point2Array[i][0] 
     tempPoint.y = point2Array[i][1] 
     tempPoint2.x = point2Array[(i+1)%6][0] 
     tempPoint2.y = point2Array[(i+1)%6][1] 
     tempLine2.norm = ((Vector2)(tempPoint2-tempPoint)).GetNormalVector() 
     tempLine2.pt = tempPoint 
     polygon.push_back(tempLine2) 
     glVertex2d(tempPoint.x,tempPoint.y) 
    glEnd() 


    tempPoint.set(0,0); 
    tempPoint2.set(6,6); 
    AC.first = tempPoint; 
    AC.second = tempPoint2; 
    testLineSegment(AC,polygon); 

    tempPoint.set(2,3); 
    tempPoint2.set(5,7); 
    AC.first = tempPoint; 
    AC.second = tempPoint2; 
    testLineSegment(AC,polygon); 

    tempPoint.set(7,0); 
    tempPoint2.set(7,4); 
    AC.first = tempPoint; 
    AC.second = tempPoint2; 
    testLineSegment(AC,polygon); 

    tempPoint.set(1,5); 
    tempPoint2.set(4,5); 
    AC.first = tempPoint; 
    AC.second = tempPoint2; 
    testLineSegment(AC,polygon); 

    glutInit() 
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA) 
    glutInitWindowSize(400, 400) 
    glutCreateWindow("test") 
    glutDisplayFunc(testCyrusBeck) 
    glutIdleFunc(testCyrusBeck) 
    glutMainLoop() 

    plt.show() 
+2

我們需要看到有問題的代碼來幫助你。 – BlackVegetable

+3

錯誤信息的哪部分你不明白?它試圖告訴你,這條線是沒有意義的。 – SLaks

+0

這是可能通過谷歌搜索解決的事情,似乎並不保證一個問題。你應該總是試着自己解決問題,只有在你確定已經到達隔離牆時纔會問,否則你只是將你的努力外包出去,這對社區並不公平。 – Dawson

回答

8

這兩條線都出現了問題:

point2Array=[] 
numpy = point2Array([[0,3],[0,6],[4,6],[6,4],[6,0],[3,0]]) 

您已經創建了一個list對象,並將其綁定到名字point2Array。您隨後致電該對象。

您不能() a list

也許你的意思是說:

point2Array = numpy.array([[0,3],[0,6],[4,6],[6,4],[6,0],[3,0]]) 

或者,也許你的意思是:

point2Array = [[0,3],[0,6],[4,6],[6,4],[6,0],[3,0]] 
+0

'import *'的另一個受害者。 –

+0

感謝您的幫助。它真的解決了我的問題。 但我的代碼仍然有其他錯誤。 –