-6

我的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()
4

1 回答 1

8

这两行是一个问题:

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

您已经创建了一个list对象并将其绑定到 name point2Array。您随后调用该对象。

你不能()一个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]]
于 2013-10-31T17:06:32.877 回答