def compile(self):
     glPolygonMode(GL_FRONT_AND_BACK, self.POLYGON_MODE)
     A = np.linspace(0, np.pi * 2, self.slices, endpoint=True)
     X = np.cos(A) * self.radius
     Y = np.sin(A) * self.radius
     # Draw top face
     with utils.glPrimitive(GL_TRIANGLE_FAN):
         glNormal3i(0, 0, 1)
         h = self.height / 2.
         glVertex3f(0, 0, h)
         for x, y in zip(X, Y):
             glVertex3f(x, y, h)
     # Draw bottom face
     with utils.glPrimitive(GL_TRIANGLE_FAN):
         glNormal3i(0, 0, -1)
         h = -self.height / 2.
         glVertex3f(0, 0, h)
         for x, y in zip(*map(reversed, (X, Y))):
             glVertex3f(x, y, h)
     # Draw side faces
     with utils.glPrimitive(GL_QUAD_STRIP):
         h = self.height / 2.
         glNormal3d(x, y, 0)
         for x, y in zip(X, Y):
             glVertex3f(x, y, -h)
             glVertex3f(x, y, h)
     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
    def compile(self):
        a = self.radius / 2.
        with utils.glPrimitive(GL_QUADS):
            # glVertex3f(a, a, 0)
            # glVertex3f(-a, a, 0)
            # glVertex3f(-a, -a, 0)
            # glVertex3f(a, -a, 0)

            glVertex3f(a, a, 0)
            glVertex3f(a, -a, 0)
            glVertex3f(-a, -a, 0)
            glVertex3f(-a, a, 0)
    def compile(self):
        r = self.radius
        d = 0.05 * r
        h = 0.4 * d
        b = .9

        glDisable(GL_LIGHTING)
        colors = [(b, .2, .2), (.2, b, .2), (.2, .2, b)]
        vertices = [(r, 0., 0.), (r - d, h, -h), (r - d, -h, h),
                (r, 0., 0.), (r - d, h, h), (r - d, -h, -h)]
        replaces = [(0, 1, 2), (2, 0, 1), (1, 2, 0)]
        with utils.glPrimitive(GL_LINES):
            for color, replace in zip(colors, replaces):
                glColor3f(*color)
                glVertex3f(0., 0., 0.)
                glVertex3f(*[(r, 0., 0.)[replace[i]] for i in range(3)])
        with utils.glPrimitive(GL_TRIANGLES):
            for color, replace in zip(colors, replaces):
                glColor3f(*color)
                for v in vertices:
                    glVertex3f(*[v[replace[i]] for i in range(3)])
        glEnable(GL_LIGHTING)
 def draw(self):
     glColor3f(0., 0., 0.)
     height = 0.002
     glDisable(GL_LIGHTING)
     with utils.glPreserveMatrix():
         glMultMatrixf(utils.npmat_to_glmat(self.localMat))
         glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
         with utils.glPrimitive(GL_POLYGON):
             glVertex3f(0, -self.top / 2, 0)
             glVertex3f(0, self.top / 2, 0)
             glVertex3f(self.length, self.bottom / 2, 0)
             glVertex3f(self.length, -self.bottom / 2, 0)
         with utils.glPrimitive(GL_LINES):
             y1 = self.top / 2
             y2 = self.bottom / 2
             l = self.length
             # draw bars
             for x in self.bars[1:]:
                 h = y1 + (y2 - y1) / l * x
                 glVertex3f(x, -h, 0)
                 glVertex3f(x, h, 0)
             # draw strings
             for i in range(1, 7):
                 y1, y2 = self.get_string_ys(i)
                 glVertex3f(0, y1, height)
                 glVertex3f(l, y2, height)
             # draw marks
             d = self.top / 12
             glColor3f(1., .2, .2)
             for fp in self.marks:
                 x, y = self.pos_fret_to_plane(fp)
                 glVertex3f(x - d, y + d, 0)
                 glVertex3f(x + d, y - d, 0)
                 glVertex3f(x + d, y + d, 0)
                 glVertex3f(x - d, y - d, 0)
         glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
     glEnable(GL_LIGHTING)