本文整理汇总了Python中kivy.graphics.Line方法的典型用法代码示例。如果您正苦于以下问题:Python graphics.Line方法的具体用法?Python graphics.Line怎么用?Python graphics.Line使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kivy.graphics
的用法示例。
在下文中一共展示了graphics.Line方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_drawings
# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Line [as 别名]
def create_drawings(self):
from kivy.graphics import Line, RenderContext
# very first time, create a texture for the shader
if not hasattr(SmoothLinePlot, '_texture'):
tex = Texture.create(size=(1, 64), colorfmt='rgb')
tex.add_reload_observer(SmoothLinePlot._smooth_reload_observer)
SmoothLinePlot._texture = tex
SmoothLinePlot._smooth_reload_observer(tex)
self._grc = RenderContext(
fs=SmoothLinePlot.SMOOTH_FS,
use_parent_modelview=True,
use_parent_projection=True)
with self._grc:
self._gcolor = Color(*self.color)
self._gline = Line(
points=[], cap='none', width=2.,
texture=SmoothLinePlot._texture)
return [self._grc]
示例2: draw_annulars
# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Line [as 别名]
def draw_annulars(self):
# draw annulars that are in the annulars list:
# requires properties annular_thickness, and a list of dicts {color: , start: , stop: }, ...,
# where start and stop are the values of the scale to start and stop the annular
if len(self.annulars) == 0:
return
awidth = self.annular_thickness
self.annular_canvas = InstructionGroup()
if self.semi_circle:
self.annular_canvas.add(PushMatrix())
self.annular_canvas.add(Translate(0, -self.dial_diameter / 2 + self.hub_radius))
for a in self.annulars:
self.annular_canvas.add(Color(*a.get('color', [0, 1, 0, 1])))
st = self.value_to_angle(a.get('start', self.scale_min))
en = self.value_to_angle(a.get('stop', self.scale_max))
self.annular_canvas.add(Line(ellipse=(self.pos[0] + awidth, self.pos[1] + awidth, self.dial_diameter - awidth * 2, self.dial_diameter - awidth * 2, st + awidth / 2.0 - self.tic_width, en + awidth / 2.0), width=awidth, cap='none', joint='round'))
if self.semi_circle:
self.annular_canvas.add(PopMatrix())
self.canvas.before.add(self.annular_canvas)
示例3: draw_setpoint
# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Line [as 别名]
def draw_setpoint(self, *args):
# draw a setpoint
if self.setpoint_canvas:
self.canvas.after.remove(self.setpoint_canvas)
self.setpoint_canvas = None
if math.isnan(self.setpoint_value) or math.isinf(self.setpoint_value):
return
v = self.value_to_angle(self.setpoint_value)
length = self.dial_diameter / 2.0 - self.tic_length if not self.setpoint_length else self.setpoint_length
self.setpoint_canvas = InstructionGroup()
self.setpoint_canvas.add(PushMatrix())
self.setpoint_canvas.add(Color(*self.setpoint_color))
self.setpoint_canvas.add(Rotate(angle=v, axis=(0, 0, -1), origin=self.dial_center))
self.setpoint_canvas.add(Translate(self.dial_center[0], self.dial_center[1]))
self.setpoint_canvas.add(Line(points=[0, 0, 0, length], width=self.setpoint_thickness, cap='none'))
# self.setpoint_canvas.add(SmoothLine(points=[0, 0, 0, length], width=self.setpoint_thickness))
self.setpoint_canvas.add(PopMatrix())
self.canvas.after.add(self.setpoint_canvas)
示例4: draw_path
# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Line [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)
示例5: draw_rubberband
# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Line [as 别名]
def draw_rubberband(self, event, x0, y0, x1, y1):
w = abs(x1 - x0)
h = abs(y1 - y0)
rect = [int(val)for val in (min(x0, x1) + self.canvas.x, min(y0, y1)
+ self.canvas.y, w, h)]
if self.lastrect is None:
self.canvas.canvas.add(Color(*self.rubberband_color))
else:
self.canvas.canvas.remove(self.lastrect)
self.lastrect = InstructionGroup()
self.lastrect.add(Line(rectangle=rect, width=1.0, dash_length=5.0,
dash_offset=5.0))
self.lastrect.add(Color(1.0, 0.0, 0.0, 0.2))
self.lastrect.add(Rectangle(pos=(rect[0], rect[1]),
size=(rect[2], rect[3])))
self.canvas.canvas.add(self.lastrect)
示例6: drawWorkspace
# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Line [as 别名]
def drawWorkspace(self, *args):
self.scatterObject.canvas.remove_group('workspace')
with self.scatterObject.canvas:
Color(.47, .47, .47)
#create the bounding box
height = float(self.data.config.get('Maslow Settings', 'bedHeight'))
width = float(self.data.config.get('Maslow Settings', 'bedWidth'))
Line(points = ( -width/2 , -height/2 , width/2 , -height/2), group='workspace')
Line(points = ( -width/2 , height/2 , width/2 , height/2), group='workspace')
Line(points = ( -width/2 , -height/2 , -width/2 , height/2), group='workspace')
Line(points = ( width/2 , -height/2 , width/2 , height/2), group='workspace')
#create the axis lines
Line(points = (-width/2,0,width/2,0), dash_offset = 5, group='workspace')
Line(points = (0, -height/2,0,height/2), dash_offset = 5, group='workspace')
texture = self.data.backgroundTexture
if texture is not None:
Rectangle(texture=texture, pos=(-width/2, -height/2),
size=(width, height),
tex_coords=self.data.backgroundManualReg)
示例7: callBackMechanism
# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Line [as 别名]
def callBackMechanism(self, callback) :
'''
Call the loadNextLine function periodically in a non-blocking way to
update the gcode.
'''
with self.scatterObject.canvas:
self.line = Line(points = (), width = 1, group = 'gcode')
#Draw numberOfTimesToCall lines on the canvas
numberOfTimesToCall = 500
for _ in range(numberOfTimesToCall):
self.loadNextLine()
#Repeat until end of file
if self.lineNumber < min(len(self.data.gcode),self.maxNumberOfLinesToRead):
Clock.schedule_once(self.callBackMechanism)
示例8: init_stroke
# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Line [as 别名]
def init_stroke(self, g, touch):
l = [touch.x, touch.y]
col = g.color
new_line = Line(
points=l,
width=self.line_width,
group=g.id)
g._strokes[str(touch.uid)] = new_line
if self.line_width:
canvas_add = self.canvas.add
canvas_add(Color(col[0], col[1], col[2], mode='rgb', group=g.id))
canvas_add(new_line)
# Update the bbox in case; this will normally be done in on_touch_move,
# but we want to update it also for a single press, force that here:
g.update_bbox(touch)
if self.draw_bbox:
self._update_canvas_bbox(g)
# Register the stroke in GestureContainer so we can look it up later
g.add_stroke(touch, new_line)
示例9: __init__
# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Line [as 别名]
def __init__(self, **kwargs):
super(CustomPopup, self).__init__(**kwargs)
border_color = kwargs.get("border_color", tm.c_popup_background)
label = self.children[0].children[-1]
label.shorten = True
label.shorten_from = "right"
label.markup = True
with self.canvas.after:
Color(*border_color)
self.line = Line(width=0.6,
rectangle=[self.x, self.y, self.width, self.height])
self.bind(pos=self.update_rect,
size=self.update_rect)
示例10: create_drawings
# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Line [as 别名]
def create_drawings(self):
from kivy.graphics import Line, RenderContext
from kivy.graphics.texture import Texture
# very first time, create a texture for the shader
if not hasattr(SmoothLinePlot, '_texture'):
tex = Texture.create(size=(1, 64), colorfmt='rgb')
tex.add_reload_observer(SmoothLinePlot._smooth_reload_observer)
SmoothLinePlot._texture = tex
SmoothLinePlot._smooth_reload_observer(tex)
self._grc = RenderContext(fs=SmoothLinePlot.SMOOTH_FS,
use_parent_modelview=True,
use_parent_projection=True)
with self._grc:
self._gcolor = Color(*self.color)
self._gline = Line(points=[], cap='none', width=2.,
texture=SmoothLinePlot._texture)
return [self._grc]
示例11: __init__
# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Line [as 别名]
def __init__(self, **kwargs):
""" On this initializer the connection has to check whether the
connection is being made forward or backwards. """
super().__init__(**kwargs)
if self.start:
self.forward = True
# The value is repeated for correctness sake
self.bez_start, self.bez_end = [self.start.center] * 2
with self.canvas.before:
Color(*self.color)
self.lin = Line(bezier=self.bez_start * 4, width=1.5)
self._bind_pin(self.start)
else:
self.forward = False
self.bez_start, self.bez_end = [self.end.center] * 2
with self.canvas.before:
Color(*self.color)
self.lin = Line(bezier=self.bez_end * 4, width=1.5)
self._bind_pin(self.end)
self.warned = False
self.info = Factory.Info(pos=self.bez_start)
Window.add_widget(self.info)
示例12: on_touch_down
# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Line [as 别名]
def on_touch_down(self, touch):
# start collecting points in touch.ud
# create a line to display the points
userdata = touch.ud
with self.canvas:
Color(1, 1, 0)
d = 30.
Ellipse(pos=(touch.x - d / 2, touch.y - d / 2), size=(d, d))
userdata['line'] = Line(points=(touch.x, touch.y))
return True
示例13: get_graphics
# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Line [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
示例14: _geojson_part_geometry
# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Line [as 别名]
def _geojson_part_geometry(self, geometry, properties):
tp = geometry["type"]
graphics = []
if tp == "Polygon":
tess = Tesselator()
for c in geometry["coordinates"]:
xy = list(self._lonlat_to_xy(c))
xy = flatten(xy)
tess.add_contour(xy)
tess.tesselate(WINDING_ODD, TYPE_POLYGONS)
color = self._get_color_from(properties.get("color", "FF000088"))
graphics.append(Color(*color))
for vertices, indices in tess.meshes:
graphics.append(
Mesh(
vertices=vertices,
indices=indices,
mode="triangle_fan"))
elif tp == "LineString":
stroke = get_color_from_hex(properties.get("stroke", "#ffffff"))
stroke_width = dp(properties.get("stroke-width"))
xy = list(self._lonlat_to_xy(geometry["coordinates"]))
xy = flatten(xy)
graphics.append(Color(*stroke))
graphics.append(Line(points=xy, width=stroke_width))
return graphics
示例15: on_touch_down
# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Line [as 别名]
def on_touch_down(self, touch):
if Widget.on_touch_down(self, touch):
return
with self.canvas:
touch.ud['current_line'] = Line(
points=(touch.x, touch.y),
width=self.line_width)