本文整理汇总了Python中kivy.graphics.Color方法的典型用法代码示例。如果您正苦于以下问题:Python graphics.Color方法的具体用法?Python graphics.Color怎么用?Python graphics.Color使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kivy.graphics
的用法示例。
在下文中一共展示了graphics.Color方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_drawings
# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Color [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 Color [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 Color [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_rubberband
# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Color [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)
示例5: start
# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Color [as 别名]
def start(win, ctx):
# late import to avoid breaking module loading
from kivy.input.postproc import kivy_postproc_modules
kivy_postproc_modules['fps'] = StatsInput()
global _ctx
ctx.label = Label(text='FPS: 0.0')
ctx.inputstats = 0
ctx.stats = []
ctx.statsr = []
with win.canvas.after:
ctx.color = Color(1, 0, 0, .5)
ctx.rectangle = Rectangle(pos=(0, win.height - 25),
size=(win.width, 25))
ctx.color = Color(1, 1, 1)
ctx.rectangle = Rectangle(pos=(5, win.height - 20))
ctx.color = Color(1, 1, 1, .5)
for x in range(64):
ctx.stats.append(0)
ctx.statsr.append(
Rectangle(pos=(win.width - 64 * 4 + x * 4, win.height - 25),
size=(4, 0)))
Clock.schedule_interval(partial(update_fps, ctx), .5)
Clock.schedule_interval(partial(update_stats, ctx), 1 / 60.)
示例6: _touch_down
# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Color [as 别名]
def _touch_down(win, touch):
ud = touch.ud
touch.scale_for_screen(win.width, win.height)
with win.canvas.after:
ud['tr.color'] = Color(1, 1, 1, pointer_alpha)
iw, ih = pointer_image.size
ud['tr.rect'] = Rectangle(
pos=(
touch.x - (pointer_image.width / 2. * pointer_scale),
touch.y - (pointer_image.height / 2. * pointer_scale)),
size=(iw * pointer_scale, ih * pointer_scale),
texture=pointer_image.texture)
if not ud.get('tr.grab', False):
ud['tr.grab'] = True
touch.grab(win)
示例7: _mouse_move
# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Color [as 别名]
def _mouse_move(win, pos, *args):
global cursor_size
if hasattr(win, '_cursor'):
c = win._cursor
else:
with win.canvas.after:
img = Image(cursor_image)
Color(1, 1, 1, 1, mode='rgba')
size = (
cursor_size[0] or img.texture.size[0],
cursor_size[1] or img.texture.size[1]
)
print(size)
win._cursor = c = Rectangle(texture=img.texture,
size=size)
c.pos = pos[0] + cursor_offset[0], pos[1] - c.size[1] + cursor_offset[1]
示例8: init_gesture
# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Color [as 别名]
def init_gesture(self, touch):
'''Create a new gesture from touch, ie it's the first on
surface, or was not close enough to any existing gesture (yet)'''
col = self.color
if self.use_random_color is True:
col = hsv_to_rgb(random(), 1., 1.)
g = GestureContainer(touch, max_strokes=self.max_strokes,
line_width=self.line_width, color=col)
# Create the bounding box Rectangle for the gesture
if self.draw_bbox:
bb = g.bbox
with self.canvas:
Color(col[0], col[1], col[2], self.bbox_alpha, mode='rgba',
group=g.id)
g._bbrect = Rectangle(
group=g.id,
pos=(bb['minx'], bb['miny']),
size=(bb['maxx'] - bb['minx'],
bb['maxy'] - bb['miny']))
self._gestures.append(g)
return g
示例9: init_stroke
# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Color [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)
示例10: update_graphics
# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Color [as 别名]
def update_graphics(self, win, create=False):
global Color, Ellipse
de = self.ud.get('_drawelement', None)
if de is None and create:
if Color is None:
from kivy.graphics import Color, Ellipse
with win.canvas.after:
de = (
Color(.8, .2, .2, .7),
Ellipse(size=(20, 20), segments=15))
self.ud._drawelement = de
if de is not None:
self.push()
self.scale_for_screen(
win.system_size[0],
win.system_size[1],
rotation=win.rotation)
de[1].pos = self.x - 10, self.y - 10
self.pop()
示例11: create_drawings
# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Color [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]
示例12: on_touch_move
# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Color [as 别名]
def on_touch_move( self, touch ) :
if self._touched :
self._d = touch.pos
self._hover_size, self._hover_pos = self._get_hover()
if self.root_layout :
self._clear_canvas()
with self.root_layout.canvas :
kg.Color( *self.hover_color, **self._unique_group )
kg.Rectangle(
size=self._hover_size, \
pos=self._hover_pos, \
**self._unique_group
)
return True
示例13: __init__
# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Color [as 别名]
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()
示例14: start_cursor
# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Color [as 别名]
def start_cursor(self, x, y):
tx, ty = self.transform_to_wpos(x, y)
label = CoreLabel(text="{:1.2f},{:1.2f}".format(tx, ty))
label.refresh()
texture = label.texture
px, py = (x, y)
with self.ids.surface.canvas.after:
Color(0, 0, 1, mode='rgb', group='cursor_group')
self.crossx = [
Rectangle(pos=(px, 0), size=(1, self.height), group='cursor_group'),
Rectangle(pos=(0, py), size=(self.width, 1), group='cursor_group'),
Line(circle=(px, py, 20), group='cursor_group'),
Rectangle(texture=texture, pos=(px - texture.size[0] / 2, py - 40), size=texture.size, group='cursor_group')
]
示例15: get_graphics
# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Color [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