Python kivy.graphics.Mesh() Examples
The following are 11
code examples of kivy.graphics.Mesh().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
kivy.graphics
, or try the search function
.
Example #1
Source File: backend_kivy.py From garden.matplotlib with MIT License | 6 votes |
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)
Example #2
Source File: __init__.py From kivy-smoothie-host with GNU General Public License v3.0 | 5 votes |
def __init__(self, **kwargs): super(Graph, self).__init__(**kwargs) with self.canvas: self._fbo = Fbo(size=self.size, with_stencilbuffer=self._with_stencilbuffer) with self._fbo: self._background_color = Color(*self.background_color) self._background_rect = Rectangle(size=self.size) self._mesh_ticks_color = Color(*self.tick_color) self._mesh_ticks = Mesh(mode='lines') self._mesh_rect_color = Color(*self.border_color) self._mesh_rect = Mesh(mode='line_strip') with self.canvas: Color(1, 1, 1) self._fbo_rect = Rectangle(size=self.size, texture=self._fbo.texture) mesh = self._mesh_rect mesh.vertices = [0] * (5 * 4) mesh.indices = range(5) self._plot_area = StencilView() self.add_widget(self._plot_area) t = self._trigger = Clock.create_trigger(self._redraw_all) ts = self._trigger_size = Clock.create_trigger(self._redraw_size) tc = self._trigger_color = Clock.create_trigger(self._update_colors) self.bind(center=ts, padding=ts, precision=ts, plots=ts, x_grid=ts, y_grid=ts, draw_border=ts) self.bind(xmin=t, xmax=t, xlog=t, x_ticks_major=t, x_ticks_minor=t, xlabel=t, x_grid_label=t, ymin=t, ymax=t, ylog=t, y_ticks_major=t, y_ticks_minor=t, ylabel=t, y_grid_label=t, font_size=t, label_options=t, x_ticks_angle=t) self.bind(tick_color=tc, background_color=tc, border_color=tc) self._trigger()
Example #3
Source File: __init__.py From kivy-smoothie-host with GNU General Public License v3.0 | 5 votes |
def create_drawings(self): self._color = Color(*self.color) self._mesh = Mesh(mode='line_strip') self.bind(color=lambda instr, value: setattr(self._color, "rgba", value)) return [self._color, self._mesh]
Example #4
Source File: __init__.py From kivy-smoothie-host with GNU General Public License v3.0 | 5 votes |
def create_drawings(self): self._color = Color(*self.color) self._mesh = Mesh() self.bind(color=lambda instr, value: setattr(self._color, 'rgba', value)) return [self._color, self._mesh]
Example #5
Source File: backend_kivy.py From garden.matplotlib with MIT License | 5 votes |
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
Example #6
Source File: colorpickercustom.py From Snu-Photo-Manager with GNU Lesser General Public License v3.0 | 5 votes |
def get_mesh(self): v = [] # first calculate the distance between endpoints of the inner # arc, so we know how many steps to use when calculating # vertices end_point_inner = polar_to_rect( self.origin, self.r_min, self.theta_max) d_inner = d_outer = 3. theta_step_inner = (self.theta_max - self.theta_min) / d_inner end_point_outer = polar_to_rect( self.origin, self.r_max, self.theta_max) if self.r_min == 0: theta_step_outer = (self.theta_max - self.theta_min) / d_outer for x in range(int(d_outer)): v += (polar_to_rect(self.origin, 0, 0) * 2) v += (polar_to_rect( self.origin, self.r_max, self.theta_min + x * theta_step_outer) * 2) else: for x in range(int(d_inner + 2)): v += (polar_to_rect( self.origin, self.r_min - 1, self.theta_min + x * theta_step_inner) * 2) v += (polar_to_rect( self.origin, self.r_max + 1, self.theta_min + x * theta_step_inner) * 2) v += (end_point_inner * 2) v += (end_point_outer * 2) return Mesh(vertices=v, indices=range(int(len(v) / 4)), mode='triangle_strip')
Example #7
Source File: colorpicker.py From Tickeys-linux with MIT License | 5 votes |
def get_mesh(self): v = [] # first calculate the distance between endpoints of the inner # arc, so we know how many steps to use when calculating # vertices end_point_inner = polar_to_rect( self.origin, self.r_min, self.theta_max) d_inner = d_outer = 3. theta_step_inner = (self.theta_max - self.theta_min) / d_inner end_point_outer = polar_to_rect( self.origin, self.r_max, self.theta_max) if self.r_min == 0: theta_step_outer = (self.theta_max - self.theta_min) / d_outer for x in range(int(d_outer)): v += (polar_to_rect(self.origin, 0, 0) * 2) v += (polar_to_rect( self.origin, self.r_max, self.theta_min + x * theta_step_outer) * 2) else: for x in range(int(d_inner + 2)): v += (polar_to_rect( self.origin, self.r_min - 1, self.theta_min + x * theta_step_inner) * 2) v += (polar_to_rect( self.origin, self.r_max + 1, self.theta_min + x * theta_step_inner) * 2) v += (end_point_inner * 2) v += (end_point_outer * 2) return Mesh(vertices=v, indices=range(int(len(v) / 4)), mode='triangle_strip')
Example #8
Source File: colorpicker.py From Tickeys-linux with MIT License | 5 votes |
def get_mesh(self): v = [] # first calculate the distance between endpoints of the inner # arc, so we know how many steps to use when calculating # vertices end_point_inner = polar_to_rect( self.origin, self.r_min, self.theta_max) d_inner = d_outer = 3. theta_step_inner = (self.theta_max - self.theta_min) / d_inner end_point_outer = polar_to_rect( self.origin, self.r_max, self.theta_max) if self.r_min == 0: theta_step_outer = (self.theta_max - self.theta_min) / d_outer for x in range(int(d_outer)): v += (polar_to_rect(self.origin, 0, 0) * 2) v += (polar_to_rect( self.origin, self.r_max, self.theta_min + x * theta_step_outer) * 2) else: for x in range(int(d_inner + 2)): v += (polar_to_rect( self.origin, self.r_min - 1, self.theta_min + x * theta_step_inner) * 2) v += (polar_to_rect( self.origin, self.r_max + 1, self.theta_min + x * theta_step_inner) * 2) v += (end_point_inner * 2) v += (end_point_outer * 2) return Mesh(vertices=v, indices=range(int(len(v) / 4)), mode='triangle_strip')
Example #9
Source File: __init__.py From RaceCapture_App with GNU General Public License v3.0 | 5 votes |
def __init__(self, **kwargs): super(Graph, self).__init__(**kwargs) with self.canvas: self._fbo = Fbo(size=self.size) self._marker_color = Color(self.marker_color) self._marker = Line() with self._fbo: self._background_color = Color(*self.background_color) self._background_rect = Rectangle(size=self.size) self._mesh_ticks_color = Color(*self.tick_color) self._mesh_ticks = Mesh(mode='lines') self._mesh_rect_color = Color(*self.border_color) self._mesh_rect = Mesh(mode='line_strip') with self.canvas: Color(1, 1, 1) self._fbo_rect = Rectangle(size=self.size) mesh = self._mesh_rect mesh.vertices = [0] * (5 * 4) mesh.indices = range(5) self._plot_area = StencilView() self.add_widget(self._plot_area) t = self._trigger = Clock.create_trigger(self._redraw_all) ts = self._trigger_size = Clock.create_trigger(self._redraw_size) tc = self._trigger_color = Clock.create_trigger(self._update_colors) self.bind(center=ts, padding=ts, precision=ts, plots=ts, x_grid=ts, y_grid=ts, draw_border=ts) self.bind(xmin=t, xmax=t, xlog=t, x_ticks_major=t, x_ticks_minor=t, xlabel=t, x_grid_label=t, ymin=t, ymax=t, ylog=t, y_ticks_major=t, y_ticks_minor=t, ylabel=t, y_grid_label=t, font_size=t, label_options=t) self.bind(tick_color=tc, background_color=tc, border_color=tc) self._trigger()
Example #10
Source File: __init__.py From RaceCapture_App with GNU General Public License v3.0 | 5 votes |
def create_drawings(self): self._color = Color(*self.color) self._mesh = Mesh(mode='line_strip') self.bind(color=lambda instr, value: setattr(self._color.rgba, value)) return [self._color, self._mesh]
Example #11
Source File: game.py From kivy-2014 with MIT License | 4 votes |
def update_glsl(self, nap): ''' https://github.com/kivy/kivy/issues/2178 if Game.REPLACE_CURSOR: cur_x, cur_y = g_window.mouse_pos cur_x += CURSOR_OFFSET_X cur_y += CURSOR_OFFSET_Y for c in (self.begin_cursor, self.begin_cursor + VERTEX_SIZE, self.begin_cursor + VERTEX_SIZE * 2, self.begin_cursor + VERTEX_SIZE * 3): self.vertices[c] = cur_x self.vertices[c + 1] = cur_y ''' if self.animate: for i in self.animate.copy(): idx = i * VERTEX_SIZE * 4 + 2 val = self.vertices[idx] * (nap * 25 + 1) if val >= 1: val = 1 self.animate.remove(i) for c in (idx, idx + VERTEX_SIZE, idx + VERTEX_SIZE * 2, idx + VERTEX_SIZE * 3): self.vertices[c] = val if not self.animate and not Game.REPLACE_CURSOR: Clock.unschedule(self.update_glsl) self.canvas.clear() if self.blending_is_broken: self.canvas.before.add(select_blend_func) self.canvas.after.add(reset_blend_func) self.canvas.add(Mesh(indices=self.indices, vertices=self.vertices, fmt=VERTEX_FORMAT, mode='triangles', texture=self.tex))