Example #1
0
 def draw(self):
     """ Render the Icosahedron in OGL , This function assumes that a graphics context already exists """
     # [1]. If OGL transforms enabled , Translate and rotate the OGL state machine to desired rendering frame
     self.state_transform()
     # [2]. Set color , size , and shape-specific parameters
     glColor3ub(
         *self.colors[0])  # Get the color according to the voxel type
     # [3]. Render!
     pyglet.graphics.draw_indexed(
         12,  # --------------------- Number of seqential triplet in vertex list
         GL_TRIANGLES,  # -------------- Draw quadrilaterals
         self.
         faceDices,  # ---------- Indices where the coordinates are stored
         (
             'v3f', self.vertX
         )  # vertex list , OpenGL offers an optimized vertex list object , but this is not it
     )  #   'v3i' # This is for integers I suppose!
     # [2]. Set color , size , and shape-specific parameters
     glColor3ub(
         *self.colors[1])  # Get the color according to the voxel type
     pyglet.gl.glLineWidth(3)
     # [3]. Render!
     pyglet.graphics.draw_indexed(
         12,  # --------------------- Number of seqential triplet in vertex list
         GL_LINES,  # -------------- Draw quadrilaterals
         self.
         linDices,  # ---------- Indices where the coordinates are stored
         (
             'v3f', self.vertX
         )  # vertex list , OpenGL offers an optimized vertex list object , but this is not it
     )  #   'v3i' # This is for integers I suppose!
     # [4]. If OGL transforms enabled , Return the OGL state machine to previous rendering frame
     self.state_untransform()
Example #2
0
 def draw(self):
     """ Draw the axes """
     # [1]. If OGL transforms enabled , Translate and rotate the OGL state machine to desired rendering frame
     self.state_transform()
     # [2]. Set color , size , and shape-specific parameters
     pyglet.gl.glLineWidth(self.__class__.lineWidth)
     # [3]. Render! # Basis vectors are drawn one at a time in the conventional colors
     glColor3ub(*self.colors[0])  # There is only one color
     # Draw the vector shaft
     pyglet.graphics.draw_indexed(
         6,  # ------------------ Number of seqential triplet in vertex list
         GL_LINES,  # ------------ Draw quadrilaterals
         self.ndx_vctr,  # ----- Indices where the coordinates are stored
         (
             'v3f', self.vertX
         )  #- Vertex list , OpenGL offers an optimized vertex list object , but this is not it
     )
     # Draw the fletchings
     for i in xrange(len(self.fltchngs)):
         pyglet.graphics.draw_indexed(
             6,  # ------------------ Number of seqential triplet in vertex list
             GL_TRIANGLES,  # -------- Draw quadrilaterals
             self.
             fltchngs[i],  # ------ Indices where the coordinates are stored
             (
                 'v3f', self.vertX
             )  #- Vertex list , OpenGL offers an optimized vertex list object , but this is not it
         )
     # [4]. If OGL transforms enabled , Return the OGL state machine to previous rendering frame
     self.state_untransform()
Example #3
0
 def draw(self):
     """ Render the point """
     # [1]. If OGL transforms enabled , Translate and rotate the OGL state machine to desired rendering frame
     if self.trnsByOGL:
         glTranslated(
             *self.pos3D
         )  # This moves the origin of drawing , so that we can use the above coordinates at each draw location
     # ( Rotation is not applicable to points )
     # [2]. Set color & size
     glColor3ub(*self.colors[0])
     glPointSize(self.size)
     # [3]. Render!
     # print "DEBUG ," , "self.vertX:  " , self.vertX
     # print "DEBUG ," , "self.indices:" , self.indices
     pyglet.graphics.draw_indexed(
         1,  # --------------------- Number of seqential triplet in vertex list
         GL_POINTS,  # ------------- Draw quadrilaterals
         self.
         indices,  # ----------------- Indices where the coordinates are stored
         (
             'v3f', self.vertX
         )  # -- vertex list , OpenGL offers an optimized vertex list object , but this is not it
     )
     # [4]. If OGL transforms enabled , Translate and rotate the OGL state machine to desired rendering frame
     # ( Rotation is not applicable to points )
     if self.trnsByOGL:
         glTranslated(*np.multiply(self.pos3D,
                                   -1))  # Reset the transform coordinates
Example #4
0
 def on_draw(self):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT)
     gl.glColor3ub(255,255,255)
     self.heading.draw()
     for row in self.items:
         for item in row:
             item.draw()
Example #5
0
    def draw_palette(self):
        pyglet.graphics.draw(4, gl.GL_QUADS,
            ("v2i", (0, 0, 0, 33, 32, 33, 32, 0)),
            ("c3B", self.left_color*4))
        pyglet.graphics.draw(4, gl.GL_QUADS,
            ("v2i", (33, 0, 33, 33, 65, 33, 65, 0)),
            ("c3B", self.right_color*4))

        if self.palette:
            swatches = []
            for x, y in self.swatch_loc:
                swatches.extend((x, y, x, y+16, x+16, y+16, x+16, y))
            for x, y in self.swatch2_loc:
                swatches.extend((x, y, x, y+16, x+16, y+16, x+16, y))

            sw_color = []
            for color in self.palette[::2]:
                sw_color.extend(color*4)
            for color in self.palette[1::2]:
                sw_color.extend(color*4)

            pyglet.graphics.draw(4*len(self.palette), gl.GL_QUADS,
                ("v2i", swatches),
                ("c3B", sw_color))

        x, y = self.tool_loc[-1][0]+35, self.tool_loc[-1][1]
        pyglet.graphics.draw(4, gl.GL_QUADS,
            ("v2i", (x, y, x, y+32, x+32, y+32, x+32, y)),
            ("c3B", self.background_color*4))

        gl.glColor3ub(255,255,255)
Example #6
0
 def on_draw(self):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT)
     gl.glColor3ub(255, 255, 255)
     self.heading.draw()
     for row in self.items:
         for item in row:
             item.draw()
Example #7
0
 def draw(self):
     gl.glColor3ub(255,30,30)
     gl.glRecti(*(self.p1+self.p2))
     gl.glColor3ub(150,255,45)
     gl.glRecti(*(self.p1+self.p3))
     #gl.glColor3ub(255,255,255)
     self.text.draw()
Example #8
0
def drawRect(grey, win):
    gl.glBegin(gl.GL_QUADS)
    gl.glColor3ub( grey[0], grey[1], grey[2] )
    gl.glVertex2f(0,0)
    gl.glVertex2f(win.width, 0)
    gl.glVertex2f(win.width, win.height)
    gl.glVertex2f(0, win.height)
    gl.glEnd()
def draw_rectangle(x1, y1, x2, y2):  # vykreslí výplň stěn
    gl.glBegin(gl.GL_QUADS)
    gl.glColor3ub(102, 0, 51)
    gl.glVertex2f(x1, y1)
    gl.glVertex2f(x1, y2)
    gl.glVertex2f(x2, y2)
    gl.glVertex2f(x2, y1)
    gl.glEnd()
def draw_background(x1, y1, x2, y2):  # vykreslí pozadí hry
    gl.glBegin(gl.GL_QUADS)
    gl.glColor3ub(0, 0, 40)
    gl.glVertex2f(x1, y1)
    gl.glVertex2f(x1, y2)
    gl.glVertex2f(x2, y2)
    gl.glVertex2f(x2, y1)
    gl.glEnd()
Example #11
0
def display_pointer(angle, color, radius):
    x_value = math.cos(angle)
    y_value = math.sin(angle)
    glBegin(GL_LINES)
    glColor3ub(*color)
    glVertex2f(0.0, 0.0)
    glVertex2f(x_value * radius, y_value * radius)
    glEnd()
Example #12
0
def display_pointer(angle, color, radius):
    x_value = math.cos(angle)
    y_value = math.sin(angle)
    glBegin(GL_LINES)
    glColor3ub(*color)
    glVertex2f(0.0, 0.0)
    glVertex2f(x_value * radius, y_value * radius)
    glEnd()
Example #13
0
def drawRect(grey, win):
    gl.glBegin(gl.GL_QUADS)
    gl.glColor3ub(grey[0], grey[1], grey[2])
    gl.glVertex2f(0, 0)
    gl.glVertex2f(win.width, 0)
    gl.glVertex2f(win.width, win.height)
    gl.glVertex2f(0, win.height)
    gl.glEnd()
Example #14
0
def draw_red_square():
    gl.glColor3ub(127, 0, 0)
    gl.glBegin(gl.GL_QUADS)
    gl.glVertex2f(-10, -10)
    gl.glVertex2f(10, -10)
    gl.glVertex2f(10, 10)
    gl.glVertex2f(-10, 10)
    gl.glEnd()
def draw_outline(x1, y1, x2, y2):  # vykreslí stěny
    gl.glBegin(gl.GL_QUADS)
    gl.glColor3ub(255, 0, 102)
    gl.glVertex2f(x1, y1)
    gl.glVertex2f(x1, y2)
    gl.glVertex2f(x2, y2)
    gl.glVertex2f(x2, y1)
    gl.glEnd()
Example #16
0
def render_rect_filled(shape, offset):
    """ Render the shape at the right spot. """
    # Set color
    GL.glLoadIdentity()
    GL.glColor3ub(shape.color[0], shape.color[1], shape.color[2])

    GL.glTranslatef(shape.x + shape.width / 2, shape.y + shape.height / 2, 0)

    GL.glDrawArrays(GL.GL_QUADS, offset, 4)
 def draw(self):
     if not self.visible:
         return
     gl.glLineWidth(2)  # deprecated
     gl.glColor3ub(*self.color3)
     gl.glBegin(gl.GL_LINE_STRIP)
     for v in self.vertexes:
         gl.glVertex2f(*v)
     gl.glVertex2f(*self.vertexes[0])
     gl.glEnd()
Example #18
0
def plot_box(minx, maxx, miny, maxy):
    # gl is using default origin in bottom right
    gl.glColor3ub(*COLOR_BOX)
    gl.glBegin(gl.GL_LINE_STRIP)
    #vertexes = [(0.0, 0.0), (0.0, window.height//2), (window.width//2, window.height//2), (window.width//2, 0.0)]
    vertexes = [(minx, miny), (minx, maxy), (maxx, maxy), (maxx, miny)]
    for v in vertexes:
        gl.glVertex2f(*v)
    gl.glVertex2f(*vertexes[0])
    gl.glEnd()
Example #19
0
 def draw(self):
     if not self.visible:
         return
     gl.glLineWidth(2)  # deprecated
     gl.glColor3ub(*self.color3)
     gl.glBegin(gl.GL_LINE_STRIP)
     for v in self.vertexes:
         gl.glVertex2f(*v)
     gl.glVertex2f(*self.vertexes[0])
     gl.glEnd()
def draw_points(x1, y1, x2, y2, x3, y3, x4, y4):  # vykreslí tečky
    global k
    gl.glBegin(gl.GL_TRIANGLE_FAN)
    gl.glColor3ub(0 + int(102 * k), 77 + int(142 * k), 102 + int(153 * k))
    # pomocí koeficientu k měníme barvu (viditelnost) teček
    gl.glVertex2f(x1, y1)
    gl.glVertex2f(x2, y2)
    gl.glVertex2f(x3, y3)
    gl.glVertex2f(x4, y4)
    gl.glEnd()
Example #21
0
 def render_slow(self):
     self.disp_list = gl.glGenLists(1)
     gl.glNewList(self.disp_list, gl.GL_COMPILE)
     for x in range(ROOM_X):
         for y in range(ROOM_Y):
             square = self[x,y]
             if square.material and square.material.visible and square.material.texture != None:
                 gl.glColor3ub(*square.material.colour)
                 square.material.texture.blit(x*16,y*16)
     gl.glEndList()
Example #22
0
def plot_box(bottom_left_x, bottom_left_y, width, height):
    COLOR_BOX = (0, 0, 255)
    gl.glColor3ub(*COLOR_BOX)
    gl.glBegin(gl.GL_LINE_STRIP)
    top_right_x = bottom_left_x + width
    top_right_y = bottom_left_y + height
    vertexes = [(bottom_left_x, bottom_left_y), (bottom_left_x, top_right_y),
                (top_right_x, top_right_y), (top_right_x, bottom_left_y)]
    for v in vertexes:
        gl.glVertex2f(*v)
    gl.glVertex2f(*vertexes[0])
    gl.glEnd()
Example #23
0
 def draw_block(self, block):
     glBegin(GL_TRIANGLE_FAN)
     glColor3ub(
         int(block.material.color[0] * 0.25),
         int(block.material.color[1] * 0.25),
         int(block.material.color[2] * 0.25),
     )
     glVertex2f(0, 0)
     glColor3ub(*block.material.color)
     for idx in range(len(block.verts)):
         glVertex2f(*block.verts[idx])
     glVertex2f(*block.verts[0])
     glEnd()
Example #24
0
    def draw(self):
        """ Draws all of the tiles and tray """
        gl.glPushMatrix()
        gl.glTranslated(self.rect.x, self.rect.y, 0)
        for y in range(self.height):
            for x in range(self.width):
                gl.glBegin(gl.GL_QUADS)
                gl.glColor3ub(*[30 + ((x + y) % 2) * 50] * 3)
                gl.glVertex2f(x * TILE_SIZE * self.scale,
                              y * TILE_SIZE * self.scale)
                gl.glVertex2f((x + 1) * TILE_SIZE * self.scale,
                              y * TILE_SIZE * self.scale)
                gl.glVertex2f((x + 1) * TILE_SIZE * self.scale,
                              (y + 1) * TILE_SIZE * self.scale)
                gl.glVertex2f(x * TILE_SIZE * self.scale,
                              (y + 1) * TILE_SIZE * self.scale)
                gl.glEnd()

        for y in range(self.height):
            for x in range(self.width):
                if self(x, y):
                    self(x, y).draw((x + 0.5) * TILE_SIZE * self.scale,
                                    (y + 0.5) * TILE_SIZE * self.scale,
                                    self.scale)
                    if self(x, y).highlighted:
                        gl.glBegin(gl.GL_QUADS)
                        gl.glColor4ub(*[255, 0, 0, 180])
                        gl.glVertex2f(x * TILE_SIZE * self.scale,
                                      y * TILE_SIZE * self.scale)
                        gl.glVertex2f((x + 1) * TILE_SIZE * self.scale,
                                      y * TILE_SIZE * self.scale)
                        gl.glVertex2f((x + 1) * TILE_SIZE * self.scale,
                                      (y + 1) * TILE_SIZE * self.scale)
                        gl.glVertex2f(x * TILE_SIZE * self.scale,
                                      (y + 1) * TILE_SIZE * self.scale)
                        gl.glEnd()

        row = 0
        col = 0
        for tile in self.tray:
            if col == self.tray_cols:
                col = 0
                row += 1
            x = self.tray_start_x + ((col + 0.5) * self.tray_cols_width)
            y = self.rect.height - ((row + 0.5) * self.tray_cols_width)
            tile.draw(x, y, TRAY_SCALE * self.scale * 9 / 10)
            col += 1
        gl.glPopMatrix()
        if self.dragging:
            self.dragging.draw(self.dragging.x, self.dragging.y,
                               self.scale * DRAG_SCALE)
Example #25
0
    def draw(self, scale, pos):
        LINE_COLOUR = (255, 255, 255)

        # gl.glEnable(gl.GL_DEPTH_TEST);
        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
        gl.glEnable(gl.GL_LINE_SMOOTH)
        gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_DONT_CARE)

        gl.glBegin(gl.GL_LINES)
        for link in self.links:
            if link.highlight:
                gl.glColor3ub(*self.colour)
                gl.glColor3ub(*self.colour)
            else:
                gl.glColor3ub(*LINE_COLOUR)
                gl.glColor3ub(*LINE_COLOUR)
            if link.highlight:
                depth = 0.5
            else:
                depth = 0.5
            gl.glVertex3f(*util.add_tup(pos, util.scale_tup(link.points[0].pos, scale)) + (depth,))
            gl.glVertex3f(*util.add_tup(pos, util.scale_tup(link.points[1].pos, scale)) + (depth,))
            print util.add_tup(pos, util.scale_tup(link.points[0].pos, scale))
        gl.glEnd()
Example #26
0
    def on_draw(self):
        self.fenetre3d.clear()
        #pgl.glPushMatrix()
        #pgl.glRotatef(self.fenetre3d.xRotation, 0, 1, 0)
        #pgl.glRotatef(0, 0, 1, 1)
        pgl.glBegin(ogl.GL_QUADS)
        #bleu
        pgl.glColor3ub(0, 0, 255)
        pgl.glVertex3f(0, 0, 0)
        pgl.glVertex3f(0, 10, 0)
        pgl.glVertex3f(self.arene.nb_colonne, 10, 0)
        pgl.glVertex3f(self.arene.nb_colonne, 0, 0)
        #rouge
        pgl.glColor3ub(255, 0, 0)
        pgl.glVertex3f(self.arene.nb_colonne, 0, 0)
        pgl.glVertex3f(self.arene.nb_colonne, 10, 0)
        pgl.glVertex3f(self.arene.nb_colonne, 10, self.arene.nb_ligne)
        pgl.glVertex3f(self.arene.nb_colonne, 0, self.arene.nb_ligne)

        #vert
        pgl.glColor3ub(0, 255, 0)
        pgl.glVertex3f(0, 0, self.arene.nb_ligne)
        pgl.glVertex3f(0, 10, self.arene.nb_ligne)
        pgl.glVertex3f(self.arene.nb_colonne, 10, self.arene.nb_ligne)
        pgl.glVertex3f(self.arene.nb_colonne, 0, self.arene.nb_ligne)

        #jaune
        pgl.glColor3ub(255, 255, 0)
        pgl.glVertex3f(00, 0, 00)
        pgl.glVertex3f(00, 10, 00)
        pgl.glVertex3f(00, 10, self.arene.nb_ligne)
        pgl.glVertex3f(00, 0, self.arene.nb_ligne)

        #blanc
        pgl.glColor3ub(255, 255, 255)
        pgl.glVertex3f(00, 0, self.arene.nb_ligne)
        pgl.glVertex3f(00, 0, 0)
        pgl.glVertex3f(self.arene.nb_colonne, 0, 0)
        pgl.glVertex3f(self.arene.nb_colonne, 0, self.arene.nb_ligne)

        self.draw()
        pgl.glEnd()
        """Permet de faire un screenshot"""
        kitten = pyglet.image.load('balise2.png')
        sprite = pyglet.sprite.Sprite(kitten)
        sprite.set_position(00, 80)
        sprite.draw()
        pyglet.image.get_buffer_manager().get_color_buffer().save(
            'screenshot.png')
        pgl.glFlush()
Example #27
0
    def draw(self, scale, pos):
        LINE_COLOUR = (255, 255, 255)

        #gl.glEnable(gl.GL_DEPTH_TEST);
        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
        gl.glEnable(gl.GL_LINE_SMOOTH)
        gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_DONT_CARE)

        gl.glBegin(gl.GL_LINES)
        for link in self.links:
            if link.highlight:
                gl.glColor3ub(*self.colour)
                gl.glColor3ub(*self.colour)
            else:
                gl.glColor3ub(*LINE_COLOUR)
                gl.glColor3ub(*LINE_COLOUR)
            if link.highlight:
                depth = 0.5
            else:
                depth = 0.5
            gl.glVertex3f(
                *util.add_tup(pos, util.scale_tup(link.points[0].pos, scale)) +
                (depth, ))
            gl.glVertex3f(
                *util.add_tup(pos, util.scale_tup(link.points[1].pos, scale)) +
                (depth, ))
            print util.add_tup(pos, util.scale_tup(link.points[0].pos, scale))
        gl.glEnd()
Example #28
0
def draw_filled_circle(position, size=20, num_of_segments=30, color=None):
    if color is None:
        glColor3ub(255, 0, 0)
    else:
        glColor3f(*color)

    twice_pi = 2.0 * 3.141596
    glBegin(GL_TRIANGLE_FAN)
    glVertex2f(position.x, position.y)
    for i in range(num_of_segments + 1):
        glVertex2f(
            (position.x + (size * math.cos(i * twice_pi / num_of_segments))),
            (position.y + (size * math.sin(i * twice_pi / num_of_segments))))
    glEnd()
Example #29
0
 def draw_rooms(self, rooms):
     for room in rooms.itervalues():
         glColor3ub(*room.color)
         glBegin(GL_TRIANGLE_FAN)
         for vert in room.verts:
             glVertex2f(*vert)
         glEnd()
     for room in rooms.itervalues():
         glColor3ub(255, 255, 255)
         glBegin(GL_LINES)
         for idx in xrange(len(room.verts)):
             if idx not in room.neighbours:
                 glVertex2f(*room.verts[idx])
                 nextidx = (idx + 1) % len(room.verts)
                 glVertex2f(*room.verts[nextidx])
         glEnd()
Example #30
0
    def draw(self):
        gl.glColor3ub(*self.col)
        gl.glBegin(gl.GL_LINE_LOOP)
        gl.glVertex2f(int(self.rect.x),int(self.rect.y))
        gl.glVertex2f(int(self.rect.x),int(self.rect.y+self.rect.height))
        gl.glVertex2f(int(self.rect.x+self.rect.width),int(self.rect.y+self.rect.height))
        gl.glVertex2f(int(self.rect.x+self.rect.width),int(self.rect.y))
        gl.glEnd()
        gl.glBegin(gl.GL_QUADS)
        gl.glVertex2f(int((self.rect.x)*self.filled),int(self.rect.y))
        gl.glVertex2f(int((self.rect.x)*self.filled),int(self.rect.y+self.rect.height))
        gl.glVertex2f(int((self.rect.x+self.rect.width)*self.filled),int(self.rect.y+self.rect.height))
        gl.glVertex2f(int((self.rect.x+self.rect.width)*self.filled),int(self.rect.y))
        gl.glEnd()

        self.label.draw()
Example #31
0
    def draw(self):
        grid = self._grid
        live = []
        dead = []

        for x, y, value in self._creator.flat:
            if value:
                live.extend(grid[x, y])
            else:
                dead.extend(grid[x, y])

        gl.glColor3ub(*LIVE_COLOR)
        graphics.draw(len(live) // 2, gl.GL_QUADS, ('v2i', live))

        gl.glColor3ub(*DEAD_COLOR)
        graphics.draw(len(dead) // 2, gl.GL_QUADS, ('v2i', dead))
Example #32
0
def plot_test_box():
    gl.glColor3ub(*COLOR_BOX)
    gl.glBegin(gl.GL_LINE_STRIP)
    vertexes = [(0.0, 0.0), (0.0, window.height // 2),
                (window.width // 2, window.height // 2),
                (window.width // 2, 0.0)]
    for v in vertexes:
        gl.glVertex2f(*v)
    gl.glVertex2f(*vertexes[0])
    gl.glEnd()
    label = pyglet.text.Label('Hello, world',
                              font_name='Times New Roman',
                              font_size=36,
                              x=window.width // 2,
                              y=window.height // 2,
                              anchor_x='center',
                              anchor_y='center')
    label.draw()
Example #33
0
    def _draw_rect(self, backColor, polyColor, left, bottom, right, top):
        glClearColor(
            backColor[0]/255,
            backColor[1]/255,
            backColor[2]/255,
            1.0)
        self.window.clear()

        verts = [
            (left, bottom),
            (right, bottom),
            (right, top),
            (left, top),
        ]
        glColor3ub(*polyColor)
        glBegin(GL_TRIANGLE_FAN)
        for vert in verts:
            glVertex2f(*vert)
        glEnd()
Example #34
0
def draw_triangle(position, velocity, size=20, color=None):
    glPushMatrix()
    glTranslatef(position.x, position.y, 0.0)

    glRotatef(math.degrees(math.atan2(velocity.x, velocity.y)), 0.0, 0.0, -1.0)

    glBegin(GL_TRIANGLES)

    if color is None:
        glColor3ub(255, 0, 0)
    else:
        glColor3f(*color)

    glVertex2f(size, 0.0)
    glVertex2f(-size, 0.0)
    glVertex2f(0.0, size * 3.0)

    glEnd()
    glPopMatrix()
Example #35
0
    def draw(self):
        gl.glColor3ub(*self.col)
        gl.glBegin(gl.GL_LINE_LOOP)
        gl.glVertex2f(int(self.rect.x), int(self.rect.y))
        gl.glVertex2f(int(self.rect.x), int(self.rect.y + self.rect.height))
        gl.glVertex2f(int(self.rect.x + self.rect.width),
                      int(self.rect.y + self.rect.height))
        gl.glVertex2f(int(self.rect.x + self.rect.width), int(self.rect.y))
        gl.glEnd()
        gl.glBegin(gl.GL_QUADS)
        gl.glVertex2f(int((self.rect.x) * self.filled), int(self.rect.y))
        gl.glVertex2f(int((self.rect.x) * self.filled),
                      int(self.rect.y + self.rect.height))
        gl.glVertex2f(int((self.rect.x + self.rect.width) * self.filled),
                      int(self.rect.y + self.rect.height))
        gl.glVertex2f(int((self.rect.x + self.rect.width) * self.filled),
                      int(self.rect.y))
        gl.glEnd()

        self.label.draw()
Example #36
0
 def draw(self):
     """ Draws all of the tiles and tray """
     gl.glPushMatrix()
     gl.glTranslated(self.rect.x,self.rect.y,0)
     for y in range(self.height):
         for x in range(self.width):
             gl.glBegin(gl.GL_QUADS)
             gl.glColor3ub(*[30+((x+y)%2)*50]*3)
             gl.glVertex2f(x*TILE_SIZE*self.scale,y*TILE_SIZE*self.scale)
             gl.glVertex2f((x+1)*TILE_SIZE*self.scale,y*TILE_SIZE*self.scale)
             gl.glVertex2f((x+1)*TILE_SIZE*self.scale,(y+1)*TILE_SIZE*self.scale)
             gl.glVertex2f(x*TILE_SIZE*self.scale,(y+1)*TILE_SIZE*self.scale)
             gl.glEnd()
             
     
     for y in range(self.height):
         for x in range(self.width):
             if self(x,y):
                 self(x,y).draw((x+0.5)*TILE_SIZE*self.scale,(y+0.5)*TILE_SIZE*self.scale,self.scale) 
                 if self(x,y).highlighted:
                     gl.glBegin(gl.GL_QUADS)
                     gl.glColor4ub(*[255,0,0,180])
                     gl.glVertex2f(x*TILE_SIZE*self.scale,y*TILE_SIZE*self.scale)
                     gl.glVertex2f((x+1)*TILE_SIZE*self.scale,y*TILE_SIZE*self.scale)
                     gl.glVertex2f((x+1)*TILE_SIZE*self.scale,(y+1)*TILE_SIZE*self.scale)
                     gl.glVertex2f(x*TILE_SIZE*self.scale,(y+1)*TILE_SIZE*self.scale)
                     gl.glEnd()
     
     row = 0
     col = 0
     for tile in self.tray:
         if col == self.tray_cols:
             col = 0
             row += 1
         x = self.tray_start_x + ((col+0.5)*self.tray_cols_width)
         y = self.rect.height - ((row+0.5)*self.tray_cols_width)
         tile.draw(x,y,TRAY_SCALE*self.scale*9/10)
         col += 1
     gl.glPopMatrix()
     if self.dragging: self.dragging.draw(self.dragging.x,self.dragging.y,self.scale*DRAG_SCALE)
Example #37
0
	def draw(self):
		self.back.draw(self.rect)
		k = self._expression()
		if self._inrect is None or k != self._expRes:
			self._inrect = self.rect.clone().inset(5).scale(scaleX=k,scaleY=1,origin=self._grow_origin)
			self._expRes = k

		if k > 0:
			if k < 0.4:
				gl.glColor3ub(255,0,0)
			elif k < 0.7:
				gl.glColor3ub(255,255,0)
			else:
				gl.glColor3ub(0,255,0)
			self.front.draw(self._inrect)
			gl.glColor3ub(255,255,255)
Example #38
0
    def draw(self):
        self.back.draw(self.rect)
        k = self._expression()
        if self._inrect is None or k != self._expRes:
            self._inrect = self.rect.clone().inset(5).scale(
                scaleX=k, scaleY=1, origin=self._grow_origin)
            self._expRes = k

        if k > 0:
            if k < 0.4:
                gl.glColor3ub(255, 0, 0)
            elif k < 0.7:
                gl.glColor3ub(255, 255, 0)
            else:
                gl.glColor3ub(0, 255, 0)
            self.front.draw(self._inrect)
            gl.glColor3ub(255, 255, 255)
Example #39
0
 def draw_disc(self, disc):
     num_tris = 32
     x, y = disc.get_offset()
     glBegin(GL_TRIANGLE_FAN)
     darker = (
         int(disc.material.color[0] * 0.75),
         int(disc.material.color[1] * 0.75),
         int(disc.material.color[2] * 0.75),
     )
     glColor3ub(0, 0, 0)
     glVertex2f(x, y)
     col_freq = 4
     for idx in range(num_tris + 1):
         if idx % (col_freq * 2) == 0:
             glColor3ub(*disc.material.color)
         elif (idx + col_freq) % col_freq == 0:
             glColor3ub(*darker)
         theta = 2 * pi / num_tris * idx
         glVertex2f(
             x + disc.radius * sin(theta),
             y + disc.radius * cos(theta))
     glEnd()
Example #40
0
    def draw(self):
        for i in self.arene.list_obj:
            i.hauteur = 50
            # Debut du dessin
            #pgl.glBegin(ogl.GL_QUADS)
            x = i.x - i.largeur // 2
            y = i.y - i.longueur // 2

            # Premier carre rouge de derrier
            pgl.glColor3ub(255, 0, 0)
            pgl.glVertex3f(x, 0, y)
            pgl.glVertex3f(x, i.hauteur, y)
            pgl.glVertex3f(x + i.largeur, i.hauteur, y)
            pgl.glVertex3f(x + i.largeur, 0, y)

            # Second carre bleu de gauche
            pgl.glColor3ub(0, 0, 255)
            pgl.glVertex3f(x, 0, y)
            pgl.glVertex3f(x, i.hauteur, y)
            pgl.glVertex3f(x, i.hauteur, y + i.longueur)
            pgl.glVertex3f(x, 0, y + i.longueur)

            # Troisieme carre vert du dessous
            pgl.glColor3ub(0, 255, 0)
            pgl.glVertex3f(x, 0, y)
            pgl.glVertex3f(x + i.largeur, 0, y)
            pgl.glVertex3f(x + i.largeur, 0, y + i.longueur)
            pgl.glVertex3f(x, 0, y + i.longueur)

            # Quatrieme carre rose de droite
            pgl.glColor3ub(255, 0, 255)
            pgl.glVertex3f(x + i.largeur, 0, y)
            pgl.glVertex3f(x + i.largeur, i.hauteur, y)
            pgl.glVertex3f(x + i.largeur, i.hauteur, y + i.longueur)
            pgl.glVertex3f(x + i.largeur, 0, y + i.longueur)

            # Cinquieme carre gris fclair du haut
            pgl.glColor3ub(122, 122, 122)
            pgl.glVertex3f(x, i.hauteur, y)
            pgl.glVertex3f(x + i.largeur, i.hauteur, y)
            pgl.glVertex3f(x + i.largeur, i.hauteur, y + i.longueur)
            pgl.glVertex3f(x, i.hauteur, y + i.longueur)

            # Sixieme face fonce
            pgl.glColor3ub(40, 40, 40)
            pgl.glVertex3f(x, 0, y + i.longueur)
            pgl.glVertex3f(x, i.hauteur, y + i.longueur)
            pgl.glVertex3f(x + i.largeur, i.hauteur, y + i.longueur)
            pgl.glVertex3f(x + i.largeur, 0, y + i.longueur)
Example #41
0
    def on_draw(self):
        self.clear()

        if CENTER_ON:
            gl.glBegin(gl.GL_POLYGON)
            for delta in POINT_DELTAS:
                gl.glColor3ub(*CENTER_COLOUR)
                gl.glVertex2f(
                    *util.add_tup(self.vector_to_screen(0, 0), delta))

            gl.glEnd()

        if GRID_ON:
            gl.glBegin(gl.GL_LINES)
            for x in range(-int(self.view_size[0] / GRID_SIZE),
                           int(self.view_size[0] / GRID_SIZE)):
                gl.glColor3ub(*GRID_COLOUR)
                gl.glColor3ub(*GRID_COLOUR)
                gl.glVertex2f(
                    *self.vector_to_screen(x * GRID_SIZE, -self.view_size[1] /
                                           2))
                gl.glVertex2f(
                    *self.vector_to_screen(x * GRID_SIZE, +self.view_size[1] /
                                           2))

            for y in range(-int(self.view_size[1] / GRID_SIZE),
                           int(self.view_size[1] / GRID_SIZE)):
                gl.glColor3ub(*GRID_COLOUR)
                gl.glColor3ub(*GRID_COLOUR)
                gl.glVertex2f(*self.vector_to_screen(-self.view_size[0] /
                                                     2, y * GRID_SIZE))
                gl.glVertex2f(*self.vector_to_screen(+self.view_size[0] /
                                                     2, y * GRID_SIZE))
            gl.glEnd()

        gl.glBegin(gl.GL_LINES)
        for link in self.vector.links:
            if link.highlight:
                gl.glColor3ub(*self.vector.colour)
                gl.glColor3ub(*self.vector.colour)
            else:
                gl.glColor3ub(*LINE_COLOUR)
                gl.glColor3ub(*LINE_COLOUR)

            gl.glVertex2f(*self.vector_to_screen(*link.points[0].pos))
            gl.glVertex2f(*self.vector_to_screen(*link.points[1].pos))
        gl.glEnd()

        for point in self.vector.points:
            gl.glBegin(gl.GL_POLYGON)
            if point == self.hover_point:
                for x in range(4):
                    gl.glColor3ub(*POINT_HOVER_COLOUR)
            elif point == self.active_point:
                for x in range(4):
                    gl.glColor3ub(*POINT_ACTIVE_COLOUR)
            else:
                for x in range(4):
                    gl.glColor3ub(*POINT_COLOUR)
            for delta in POINT_DELTAS:
                gl.glVertex2f(*util.add_tup(self.vector_to_screen(
                    *point.pos), delta))

            gl.glEnd()
Example #42
0
 def on_draw(self):
     self.clear()
     
     if CENTER_ON:
         gl.glBegin(gl.GL_POLYGON)
         for delta in POINT_DELTAS:
             gl.glColor3ub(*CENTER_COLOUR)
             gl.glVertex2f(*util.add_tup(self.vector_to_screen(0,0),delta))
             
         gl.glEnd()
     
     if GRID_ON:
         gl.glBegin(gl.GL_LINES)
         for x in range(-int(self.view_size[0]/GRID_SIZE),int(self.view_size[0]/GRID_SIZE)):
             gl.glColor3ub(*GRID_COLOUR)
             gl.glColor3ub(*GRID_COLOUR)
             gl.glVertex2f(*self.vector_to_screen(x*GRID_SIZE,-self.view_size[1]/2))
             gl.glVertex2f(*self.vector_to_screen(x*GRID_SIZE,+self.view_size[1]/2))
             
         for y in range(-int(self.view_size[1]/GRID_SIZE),int(self.view_size[1]/GRID_SIZE)):
             gl.glColor3ub(*GRID_COLOUR)
             gl.glColor3ub(*GRID_COLOUR)
             gl.glVertex2f(*self.vector_to_screen(-self.view_size[0]/2,y*GRID_SIZE))
             gl.glVertex2f(*self.vector_to_screen(+self.view_size[0]/2,y*GRID_SIZE))
         gl.glEnd()
         
         
     gl.glBegin(gl.GL_LINES)
     for link in self.vector.links:
         if link.highlight:
             gl.glColor3ub(*self.vector.colour)
             gl.glColor3ub(*self.vector.colour)
         else:
             gl.glColor3ub(*LINE_COLOUR)
             gl.glColor3ub(*LINE_COLOUR)
             
         gl.glVertex2f(*self.vector_to_screen(*link.points[0].pos))
         gl.glVertex2f(*self.vector_to_screen(*link.points[1].pos))
     gl.glEnd()
     
     for point in self.vector.points:
         gl.glBegin(gl.GL_POLYGON)
         if point == self.hover_point:
             for x in range(4): gl.glColor3ub(*POINT_HOVER_COLOUR)
         elif point == self.active_point:
             for x in range(4): gl.glColor3ub(*POINT_ACTIVE_COLOUR)
         else:
             for x in range(4): gl.glColor3ub(*POINT_COLOUR)
         for delta in POINT_DELTAS:
             gl.glVertex2f(*util.add_tup(self.vector_to_screen(*point.pos),delta))
             
         gl.glEnd()
Example #43
0
    def draw(self):
        mid_x, mid_y = self.get_center()
        glLineWidth(2)
        if self.displayType == ANALOG_CLOCK:
            radius = min(self.width, self.height) / 2.0 - 10
            radius_end = radius - 10
            glPushMatrix()
            glTranslatef(mid_x, mid_y, 0)
            if self.clockLabels is not None or self.drawLines:
                for i in xrange(0, 12):
                    glPushMatrix()
                    angle = get_mark_angle(i + 1)
                    x_value = math.cos(angle)
                    y_value = math.sin(angle)
                    if self.drawLines:
                        glBegin(GL_LINES)
                        glColor3ub(*self.color)
                        glVertex2f(x_value * radius_end, y_value * radius_end)
                        glVertex2f(x_value * (radius - 20),
                                   y_value * (radius - 20))
                        glEnd()
                    if self.clockLabels is not None:
                        x = x_value * radius
                        y = y_value * radius
                        glTranslatef(x, y, 0)
                        self.clockLabels[-i].draw()
                    glPopMatrix()
            # second pointer
            second, minute, hour = self.get_time()
            if self.displaySeconds:
                display_pointer(get_second_minute_angle(second),
                                self.secondsColor, radius_end)

            if self.displayHours:
                display_pointer(get_hour_angle(hour + minute / 60.0),
                                self.hoursColor, radius_end / 1.5)

            if self.displayMinutes:
                display_pointer(
                    get_second_minute_angle(minute + second / 60.0),
                    self.minutesColor, radius_end)
            glPopMatrix()
            if self.border is not None:
                glPushMatrix()
                glTranslatef(self.x + 20, self.y - 20, 0.0)
                self.border.draw(GL_LINE_LOOP)
                glPopMatrix()

        elif self.displayType in (DIGITAL_CLOCK, CALENDAR):
            text = self.get_text()
            if text != self.text:
                self.label.text = text
                self.text = text
            glPushMatrix()
            glTranslatef(self.x, self.y, 0)
            self.label.draw()
            if self.displayType == DIGITAL_CLOCK and self.drawBorder:
                glBegin(GL_LINE_LOOP)
                glColor3ub(*self.color)
                glVertex2f(0, 0)
                glVertex2f(self.width, 0)
                glVertex2f(self.width, -self.height)
                glVertex2f(0, -self.height)
                glEnd()
            glPopMatrix()
def draw_ghost(x, y,
               ghost):  # nakreslí příšerku s barvou podle argumentu ghost
    global EYES, c
    if ghost == 0:
        r = 255
        g = 1
        b = 1
    if ghost == 1:
        r = 1
        g = 255
        b = 1
    if ghost == 2:
        r = 1
        g = 1
        b = 255
    if ghost == 3:
        r = 255
        g = 1
        b = 255
    if ghost == 4:
        r = 255
        g = 1
        b = 125
    if ghost == 5:
        r = 0
        g = 205
        b = 205

    color = (r, g, b)

    ghost = pyglet.shapes.Circle(x + 20, y + 24, 15, color=color, batch=batch)
    ghost.draw()

    gl.glBegin(gl.GL_POLYGON)
    gl.glColor3ub(r, g, b)
    gl.glVertex2f(x + 20, y + 30)
    gl.glVertex2f(x + 35, y + 25)
    gl.glVertex2f(x + 35, y + 4)
    gl.glVertex2f(x + 27.5, y + 11.5)
    gl.glVertex2f(x + 20, y + 4)
    gl.glVertex2f(x + 12.5, y + 11.5)
    gl.glVertex2f(x + 5, y + 4)
    gl.glVertex2f(x + 5, y + 25)
    gl.glEnd()

    c = sin(EYES)  # pohyb očí opět pomocí funkce sinus

    # pomocí koeficientu c se mění x-ová souřadnice očí - pohyb ze strany na stranu
    eye1 = pyglet.shapes.Circle((x + 13) + c * 4,
                                y + 24,
                                6.5,
                                segments=15,
                                color=(255, 255, 255),
                                batch=batch)  # levé oko
    eye2 = pyglet.shapes.Circle((x + 27) + c * 4,
                                y + 24,
                                6.5,
                                segments=15,
                                color=(255, 255, 255),
                                batch=batch)  # pravé oko

    pupil1 = pyglet.shapes.Circle((x + 13) + c * 8,
                                  y + 24,
                                  3,
                                  segments=10,
                                  color=(1, 1, 1),
                                  batch=batch)  # levá zornička

    pupil2 = pyglet.shapes.Circle((x + 27) + c * 8,
                                  y + 24,
                                  3,
                                  segments=10,
                                  color=(1, 1, 1),
                                  batch=batch)  # pravá zornička

    eye1.draw()
    eye2.draw()
    pupil1.draw()
    pupil2.draw()
def draw_pacman():  # nakreslí pacmana včetně pohybu úst
    global PACMAN_DIRECTION, MOUTH, MOUTH_DIRECTION
    if PACMAN_DIRECTION > 0:
        MOUTH_DIRECTION = PACMAN_DIRECTION
    pacman = pyglet.shapes.Circle(
        position_pacman[0] + 20,
        position_pacman[1] + 20,
        16,
        color=(255, 255, 1),
        batch=batch,
    )
    pacman.draw()

    if status != 6:  # pokud není pozastavená hra, ústa se hýbou
        MOUTH += 0.25
        if MOUTH > pi:  # pokud je větší než π, resetuje se na 0
            # zajistí tak plynulé otevírání a zavírání úst pomocí funkce sinus níže
            MOUTH = 0

    # otevírání a zavírání úst podle směru Pac-Mana
    if status != 4:  # pokud hráč nezemřel, ústa se hýbou
        n = sin(MOUTH)  # koeficientem k  a funkcí sinus se násobí souřadnice
        # Pac-manových úst --> zavírání a otevírání úst
        x1, y1 = position_pacman[0] + 20, position_pacman[1] + 20
        x2, y2, x3, y3 = 1, 1, 1, 1
        if MOUTH_DIRECTION == 1:  # pokud jsou ústa nasměrována doprava
            x2 = position_pacman[0] + 36
            x3 = position_pacman[0] + 36
            y = position_pacman[1] + 20
            y2, y3 = y - 20 * n, y + 20 * n
        if MOUTH_DIRECTION == 2:  # dolů
            x = position_pacman[0] + 20
            x2 = x - 20 * n
            x3 = x + 20 * n
            y2 = position_pacman[1] + 36
            y3 = position_pacman[1] + 36
        if MOUTH_DIRECTION == 3:  # doleva
            x2 = position_pacman[0] + 4
            x3 = position_pacman[0] + 4
            y = position_pacman[1] + 20
            y2, y3 = y - 20 * n, y + 20 * n
        if MOUTH_DIRECTION == 4:  # nahoru
            x = position_pacman[0] + 20
            x2 = x - 20 * n
            x3 = x + 20 * n
            y2 = position_pacman[1] + 4
            y3 = position_pacman[1] + 4

        # vykreslení úst
        gl.glBegin(gl.GL_TRIANGLES)
        gl.glColor3ub(0, 0, 40)
        gl.glVertex2f(x1, y1)
        gl.glVertex2f(x2, y2)
        gl.glVertex2f(x3, y3)
        gl.glEnd()

    if status == 4:  # pokud hráč umřel
        dead_eye1 = pyglet.shapes.Rectangle(
            position_pacman[0] + 13,
            position_pacman[1] + 24,
            4,
            4,
            color=(1, 1, 1),
        )
        dead_eye1.rotation = 45
        dead_eye1.draw()

        dead_eye2 = pyglet.shapes.Rectangle(
            position_pacman[0] + 26,
            position_pacman[1] + 24,
            4,
            4,
            color=(1, 1, 1),
        )
        dead_eye2.rotation = 45
        dead_eye2.draw()
Example #46
0
    def draw(self):
        mid_x, mid_y = self.get_center()
        glLineWidth(2)
        if self.displayType == ANALOG_CLOCK:
            radius = min(self.width, self.height) / 2.0 - 10
            radius_end = radius - 10
            glPushMatrix()
            glTranslatef(mid_x, mid_y, 0)
            if self.clockLabels is not None or self.drawLines:
                for i in xrange(0, 12):
                    glPushMatrix()
                    angle = get_mark_angle(i + 1)
                    x_value = math.cos(angle)
                    y_value = math.sin(angle)
                    if self.drawLines:
                        glBegin(GL_LINES)
                        glColor3ub(*self.color)
                        glVertex2f(x_value * radius_end, y_value * radius_end)
                        glVertex2f(x_value * (radius - 20), 
                            y_value * (radius - 20))
                        glEnd()
                    if self.clockLabels is not None:
                        x = x_value * radius
                        y = y_value * radius
                        glTranslatef(x, y, 0)
                        self.clockLabels[-i].draw()
                    glPopMatrix()
            # second pointer
            second, minute, hour = self.get_time()
            if self.displaySeconds:
                display_pointer(get_second_minute_angle(
                    second), 
                    self.secondsColor, radius_end)
            
            if self.displayHours:
                display_pointer(get_hour_angle(hour + minute / 60.0), 
                    self.hoursColor, radius_end / 1.5)
            
            if self.displayMinutes:
                display_pointer(get_second_minute_angle(
                    minute + second / 60.0), self.minutesColor, 
                    radius_end)
            glPopMatrix()
            if self.border is not None:
                glPushMatrix()
                glTranslatef(self.x + 20, self.y - 20, 0.0)
                self.border.draw(GL_LINE_LOOP)
                glPopMatrix()

        elif self.displayType in (DIGITAL_CLOCK, CALENDAR):
            text = self.get_text()
            if text != self.text:
                self.label.text = text
                self.text = text
            glPushMatrix()
            glTranslatef(self.x, self.y, 0)
            self.label.draw()
            if self.displayType == DIGITAL_CLOCK and self.drawBorder:
                glBegin(GL_LINE_LOOP)
                glColor3ub(*self.color)
                glVertex2f(0, 0)
                glVertex2f(self.width, 0)
                glVertex2f(self.width, -self.height)
                glVertex2f(0, -self.height)
                glEnd()
            glPopMatrix()