当前位置: 首页>>代码示例>>Python>>正文


Python kivy.graphics方法代码示例

本文整理汇总了Python中kivy.graphics方法的典型用法代码示例。如果您正苦于以下问题:Python kivy.graphics方法的具体用法?Python kivy.graphics怎么用?Python kivy.graphics使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kivy的用法示例。


在下文中一共展示了kivy.graphics方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: draw_path

# 需要导入模块: import kivy [as 别名]
# 或者: from kivy import graphics [as 别名]
def draw_path(self, gc, path, transform, rgbFace=None):
        '''Produce the rendering of the graphics elements using
           :class:`kivy.graphics.Line` and :class:`kivy.graphics.Mesh` kivy
           graphics instructions. The paths are converted into polygons and
           assigned either to a clip rectangle or to the same canvas for
           rendering. Paths are received in matplotlib coordinates. The
           aesthetics is defined by the `GraphicsContextKivy` gc.
        '''
        if _mpl_ge_2_0:
            polygons = path.to_polygons(transform, self.widget.width,
                                        self.widget.height, closed_only=False)
        else:
            polygons = path.to_polygons(transform, self.widget.width,
                                        self.widget.height)
        list_canvas_instruction = self.get_path_instructions(gc, polygons,
                                    closed=True, rgbFace=rgbFace)
        for widget, instructions in list_canvas_instruction:
            widget.canvas.add(instructions) 
开发者ID:kivy-garden,项目名称:garden.matplotlib,代码行数:20,代码来源:backend_kivy.py

示例2: update_all

# 需要导入模块: import kivy [as 别名]
# 或者: from kivy import graphics [as 别名]
def update_all(self, *args):
        '''
        Update all positions and sizes for graphics in widgets.
        '''
        x = self.pos[0]
        y = self.pos[1]
        self.gauge_translate.x = x
        self.gauge_translate.y = y
        self.shadow_translate.x = x
        self.shadow_translate.y = y
        self.mask_translate.x = x
        self.mask_translate.y = y

        scale_x = self.width / self.gauge_width
        scale_y = self.height / self.gauge_height
        self.gauge_scale.x = scale_x
        self.gauge_scale.y = scale_y
        self.shadow_scale.x = scale_x
        self.shadow_scale.y = scale_y
        self.mask_scale.x = scale_x
        self.mask_scale.y = scale_y 
开发者ID:autosportlabs,项目名称:RaceCapture_App,代码行数:23,代码来源:tachometer.py

示例3: handle_clip_rectangle

# 需要导入模块: import kivy [as 别名]
# 或者: from kivy import graphics [as 别名]
def handle_clip_rectangle(self, gc, x, y):
        '''It checks whether the point (x,y) collides with any already
           existent stencil. If so it returns the index position of the
           stencil it collides with. if the new clip rectangle bounds are
           None it draws in the canvas otherwise it finds the correspondent
           stencil or creates a new one for the new graphics instructions.
           The point x,y is given in matplotlib coordinates.
        '''
        x = self.widget.x + x
        y = self.widget.y + y
        collides = self.collides_with_existent_stencil(x, y)
        if collides > -1:
            return collides
        new_bounds = gc.get_clip_rectangle()
        if new_bounds:
            x = self.widget.x + int(new_bounds.bounds[0])
            y = self.widget.y + int(new_bounds.bounds[1])
            w = int(new_bounds.bounds[2])
            h = int(new_bounds.bounds[3])
            collides = self.collides_with_existent_stencil(x, y)
            if collides == -1:
                cliparea = StencilView(pos=(x, y), size=(w, h))
                self.clip_rectangles.append(cliparea)
                self.widget.add_widget(cliparea)
                return len(self.clip_rectangles) - 1
            else:
                return collides
        else:
            return -2 
开发者ID:kivy-garden,项目名称:garden.matplotlib,代码行数:31,代码来源:backend_kivy.py

示例4: get_path_instructions

# 需要导入模块: import kivy [as 别名]
# 或者: from kivy import graphics [as 别名]
def get_path_instructions(self, gc, polygons, closed=False, rgbFace=None):
        '''With a graphics context and a set of polygons it returns a list
           of InstructionGroups required to render the path.
        '''
        instructions_list = []
        points_line = []
        for polygon in polygons:
            for x, y in polygon:
                x = x + self.widget.x
                y = y + self.widget.y
                points_line += [float(x), float(y), ]
            tess = Tesselator()
            tess.add_contour(points_line)
            if not tess.tesselate():
                Logger.warning("Tesselator didn't work :(")
                return
            newclip = self.handle_clip_rectangle(gc, x, y)
            if newclip > -1:
                instructions_list.append((self.clip_rectangles[newclip],
                        self.get_graphics(gc, tess, points_line, rgbFace,
                                          closed=closed)))
            else:
                instructions_list.append((self.widget,
                        self.get_graphics(gc, tess, points_line, rgbFace,
                                          closed=closed)))
        return instructions_list 
开发者ID:kivy-garden,项目名称:garden.matplotlib,代码行数:28,代码来源:backend_kivy.py

示例5: get_graphics

# 需要导入模块: import kivy [as 别名]
# 或者: from kivy import graphics [as 别名]
def get_graphics(self, gc, polygons, points_line, rgbFace, closed=False):
        '''Return an instruction group which contains the necessary graphics
           instructions to draw the respective graphics.
        '''
        instruction_group = InstructionGroup()
        if isinstance(gc.line['dash_list'], tuple):
            gc.line['dash_list'] = list(gc.line['dash_list'])
        if rgbFace is not None:
            if len(polygons.meshes) != 0:
                instruction_group.add(Color(*rgbFace))
                for vertices, indices in polygons.meshes:
                    instruction_group.add(Mesh(
                        vertices=vertices,
                        indices=indices,
                        mode=str("triangle_fan")
                    ))
        instruction_group.add(Color(*gc.get_rgb()))
        if _mpl_ge_1_5 and (not _mpl_ge_2_0) and closed:
            points_poly_line = points_line[:-2]
        else:
            points_poly_line = points_line
        if gc.line['width'] > 0:
            instruction_group.add(Line(points=points_poly_line,
                width=int(gc.line['width'] / 2),
                dash_length=gc.line['dash_length'],
                dash_offset=gc.line['dash_offset'],
                dash_joint=gc.line['join_style'],
                dash_list=gc.line['dash_list']))
        return instruction_group 
开发者ID:kivy-garden,项目名称:garden.matplotlib,代码行数:31,代码来源:backend_kivy.py

示例6: draw_markers

# 需要导入模块: import kivy [as 别名]
# 或者: from kivy import graphics [as 别名]
def draw_markers(self, gc, marker_path, marker_trans, path,
        trans, rgbFace=None):
        '''Markers graphics instructions are stored on a dictionary and
           hashed through graphics context and rgbFace values. If a marker_path
           with the corresponding graphics context exist then the instructions
           are pulled from the markers dictionary.
        '''
        if not len(path.vertices):
            return
        # get a string representation of the path
        path_data = self._convert_path(
            marker_path,
            marker_trans + Affine2D().scale(1.0, -1.0),
            simplify=False)
        # get a string representation of the graphics context and rgbFace.
        style = str(gc._get_style_dict(rgbFace))
        dictkey = (path_data, str(style))
        # check whether this marker has been created before.
        list_instructions = self._markers.get(dictkey)
        # creating a list of instructions for the specific marker.
        if list_instructions is None:
            if _mpl_ge_2_0:
                polygons = marker_path.to_polygons(marker_trans, closed_only=False)
            else:
                polygons = marker_path.to_polygons(marker_trans)
            self._markers[dictkey] = self.get_path_instructions(gc,
                                        polygons, rgbFace=rgbFace)
        # Traversing all the positions where a marker should be rendered
        for vertices, codes in path.iter_segments(trans, simplify=False):
            if len(vertices):
                x, y = vertices[-2:]
                for widget, instructions in self._markers[dictkey]:
                    widget.canvas.add(PushMatrix())
                    widget.canvas.add(Translate(x, y))
                    widget.canvas.add(instructions)
                    widget.canvas.add(PopMatrix()) 
开发者ID:kivy-garden,项目名称:garden.matplotlib,代码行数:38,代码来源:backend_kivy.py


注:本文中的kivy.graphics方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。