Пример #1
0
    def draw_arrow(self, color):

        # Set material
        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color)
        #glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color)
        #glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [1, 1, 1, 0.0])
        #glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 20)

        # Draw cylinder
        quad = gluNewQuadric()
        gluQuadricDrawStyle(quad, GLU_FILL)
        gluQuadricTexture(quad, True)
        gluQuadricNormals(quad, GLU_SMOOTH)
        gluCylinder(quad, self.size / 30, self.size / 30,
                    self.size * 0.8, 20, 20)

        # Move to the arrowhead position
        glTranslatef(0, 0, self.size * 0.8)

        # Draw arrowhead
        gluQuadricDrawStyle(quad, GLU_FILL)
        gluQuadricTexture(quad, True)
        gluQuadricNormals(quad, GLU_SMOOTH)
        gluCylinder(quad, self.size / 15, 0,
                    self.size * 0.2, 20, 20)

        # Revert to the original position
        glTranslatef(0, 0, -self.size * 0.8)
Пример #2
0
def make_Cylinder():  #2
    #glNewList(G_OBJ_PLANE, GL_COMPILE)                             #2
    #glLineWidth(50.0)                                              #2
    #glColor3f(0.0, 0.0, 0.0)                                       #2
    #glBegin(GL_LINES)                                              #2
    #glVertex3f(1.0, 0.0, 0.0)                                      #2
    #glVertex3f(0.0, 1.0, 0.0)                                      #2
    #glEnd()                                                        #2
    #2
    #glColor3f(1.0, 0.0, 0.0)                                       #2
    #glBegin(GL_TRIANGLE_STRIP)                                     #2
    #glVertex3f(1.000000 ,0.000000, 0.000000)
    #glVertex3f(0.000000, 1.000000, 0.000000)
    #glVertex3f(1.000000, 1.000000, 1.000000)
    #glEnd()

    glNewList(G_OBJ_CYLINDER, GL_COMPILE)

    quad = gluNewQuadric()

    gluCylinder(quad, 0.2, 0.2, 2.0, 32, 32)  #半径半径长切分次数切分次数

    #glRotatef(2, 0, 0, 1)

    gluDeleteQuadric(quad)

    glEndList()  #2
Пример #3
0
 def drawBallAndStick(self, r_ball = 0.4, r_stick = 0.1):
     res = self.quality * 6
     quad = gluNewQuadric()
     glNewList(1,GL_COMPILE)
     for i in range(self.mol.natoms):
         glPushMatrix()
         # set atom color
         r,g,b = self.mol.col[i]
         glColor3f(r,g,b)
         # translate to atom position
         x,y,z = self.mol.pos[i]
         glTranslatef(x,y,z)
         # draw the atom
         gluSphere(quad, r_ball*self.mol.rad[i], res, res)
         glPopMatrix()
     for i,c in enumerate(self.mol.con):
         m = c[0]
         n = c[1]
         glPushMatrix()
         # set bond color
         r,g,b = self.mol.col[m]
         glColor3f(r,g,b)
         # translate to atom position
         x,y,z = self.mol.pos[m]
         glTranslatef(x,y,z)
         # draw the bond
         v = self.mol.pos[n] - self.mol.pos[m]
         angle = math.acos(numpy.dot([0.0,0.0,1.0], v)/self.mol.dist[i])*180./math.pi
         x,y,z = numpy.cross([0.0,0.0,1.0], v)
         glRotatef(angle,x,y,z)
         h = self.mol.dist[i] * self.mol.rad[m] / (self.mol.rad[m] + self.mol.rad[n])
         gluCylinder(quad, r_stick, r_stick, h, res, res)
         glPopMatrix()
     glEndList()
Пример #4
0
 def draw_pin(self, x, y):
     glPushMatrix()
     glColor3f(1.0, 1.0, 0.0)
     glTranslatef(x, 0.0, -y) 
     glRotatef(-90, 1.0, 0.0, 0.0)
     obj = gluNewQuadric()
     gluCylinder(obj, 0.05, 0.05, 0.5, 10, 10)
     glPushMatrix()
     gluDisk(obj, 0.0, 0.05, 10, 10)
     glTranslatef(0.0, 0.5, 0.0) 
     glPopMatrix()
     glPopMatrix()
Пример #5
0
 def paintCylinder(self, diameter, height):
     r = diameter / 70.
     height = 2 * height / 70.
     glColor3f(0., 0., 0.)
     glPushMatrix()
     glTranslatef(*self.offsets)  # move down
     glRotatef(-90., 1., 0., 0.)
     quadric = gluNewQuadric()
     gluQuadricDrawStyle(quadric, GLU_LINE)
     slices = max(int(round(r * 32)), 15)
     gluCylinder(quadric, r, r, height, slices, 1)
     glPopMatrix()
Пример #6
0
 def paintArrow(self, direction, color):
     d = 0.01
     length = 0.5
     glPushMatrix()
     glColor3fv(color)
     if direction == 'n':
         glTranslatef(0., -1.1, 2.)
     elif direction == 'gamma':
         glTranslatef(1.2, -1.1, 0.)
     else:
         glTranslatef(-1., -1., 1.)
     quadric = gluNewQuadric()
     if direction in ('x', 'gamma'):
         glRotatef(90., 0., 1., 0.)
     elif direction == 'y':
         glRotatef(90, -1., 0., 0.)
     elif direction in ('z', 'n'):
         glRotatef(180, -1, 0, 0)
     gluCylinder(quadric, d, d, length, 48, 48)
     glTranslatef(0, 0, length)
     glutSolidCone(2. * d, 0.1, 48, 48)
     glPopMatrix()
Пример #7
0
 def drawBallAndStick(self, r_ball=0.4, r_stick=0.1):
     res = self.quality * 6
     quad = gluNewQuadric()
     glNewList(1, GL_COMPILE)
     for i in range(self.mol.natoms):
         glPushMatrix()
         # set atom color
         r, g, b = self.mol.col[i]
         glColor3f(r, g, b)
         # translate to atom position
         x, y, z = self.mol.pos[i]
         glTranslatef(x, y, z)
         # draw the atom
         gluSphere(quad, r_ball * self.mol.rad[i], res, res)
         glPopMatrix()
     for i, c in enumerate(self.mol.con):
         m = c[0]
         n = c[1]
         glPushMatrix()
         # set bond color
         r, g, b = self.mol.col[m]
         glColor3f(r, g, b)
         # translate to atom position
         x, y, z = self.mol.pos[m]
         glTranslatef(x, y, z)
         # draw the bond
         v = self.mol.pos[n] - self.mol.pos[m]
         angle = math.acos(
             numpy.dot([0.0, 0.0, 1.0], v) /
             self.mol.dist[i]) * 180. / math.pi
         x, y, z = numpy.cross([0.0, 0.0, 1.0], v)
         glRotatef(angle, x, y, z)
         h = self.mol.dist[i] * self.mol.rad[m] / (self.mol.rad[m] +
                                                   self.mol.rad[n])
         gluCylinder(quad, r_stick, r_stick, h, res, res)
         glPopMatrix()
     glEndList()
Пример #8
0
def cylinder(radius, height, **kwargs):
    """ Draw a cylinder with given radius and height."""

    # Get any keyword arguments
    style = kwargs.get("style", "wireframe")
    texture = kwargs.get("texture", None)

    quadric = _get_quadric()

    # Setup texture if specified
    if texture:
        style = "solid"
        gluQuadricTexture(quadric, True)
        texture.bind()

    # Set the quadric draw style (line or fill)
    _set_draw_style(style)

    # Draw the bottom end of the cylinder
    glFrontFace(GL_CW)
    gluDisk(quadric, 0, radius, DiskRes["slices"], DiskRes["loops"])
    glFrontFace(GL_CCW)

    # Draw the body of the cylinder
    gluCylinder(quadric, radius, radius, height, CylinderRes["slices"], CylinderRes["stacks"])

    # Draw the top end of the cylinder
    glPushMatrix()
    translateZ(height)
    gluDisk(quadric, 0, radius, DiskRes["slices"], DiskRes["loops"])
    glPopMatrix()

    # Clean up texture data if specified
    if texture:
        texture.unbind()
        gluQuadricTexture(quadric, False)
Пример #9
0
 def draw_cone(self, radius1, radius2, length, quality):
     gluCylinder(self.quadric, radius1, radius2, length, quality, 1)
Пример #10
0
 def draw_cylinder(self, radius, length, quality):
     gluCylinder(self.quadric, radius, radius, length, quality, 1)
Пример #11
0
 def _cylinder_(self, r, h, rotate=True):
     '''
     '''
     if rotate:
         glRotatef(90, 1, 0, 0)
     gluCylinder(gluNewQuadric(), r, r, h, xseg, yseg)
Пример #12
0
 def draw_cone(self, radius1, radius2, length, quality):
     gluCylinder(self.quadric, radius1, radius2, length, quality, 1)
Пример #13
0
 def draw_cylinder(self, radius, length, quality):
     gluCylinder(self.quadric, radius, radius, length, quality, 1)