本文整理汇总了Python中canvas.Canvas.clear方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.clear方法的具体用法?Python Canvas.clear怎么用?Python Canvas.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类canvas.Canvas
的用法示例。
在下文中一共展示了Canvas.clear方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from canvas import Canvas [as 别名]
# 或者: from canvas.Canvas import clear [as 别名]
def run(self):
print 'RUNNING'
r = lambda: random.randint(0, 255)
while True:
Canvas.clear()
Canvas.draw_rect((0, 0), (200, 200), fill_style='#%02X%02X%02X' % (r(), r(), r()))
sleep(random.uniform(0.03, 1))
示例2: Window
# 需要导入模块: from canvas import Canvas [as 别名]
# 或者: from canvas.Canvas import clear [as 别名]
class Window(object):
def __init__(self, width: int, height: int, pixels: ndarray):
self.pixels = pixels
self.width = width
self.height = height
self.canvas = Canvas(width, height, pixels)
# setup key handlers
key_esc = 27
self.handlers = {
key_esc: self.exit
}
# self.v1 = Vertex(Vector(0, 0), Color.cyan())
# self.v2 = Vertex(Vector(300, 100), Color.red())
# self.v3 = Vertex(Vector(200, 300), Color.green())
model_path = "illidan.model"
texture_path = "illidan.texture"
self.mesh = Mesh(model_path, texture_path)
def clear(self):
self.canvas.clear()
pass
def update(self, dt):
pass
def draw(self):
# self.canvas.draw_triangle(self.v1, self.v2, self.v3)
self.canvas.draw_mesh(self.mesh)
def mouse_event(self, button, state, x, y):
print('mouse event', button, state, x, y)
# 0, left button
# 2, right button
# 0, state press
# 1, state release
def exit(self):
sys.exit(0)
def cmd404(self):
pass
def key_event(self, key, key_is_down):
print('key event', key, key_is_down)
cmd = self.handlers.get(key, self.cmd404)
cmd()
示例3: Window
# 需要导入模块: from canvas import Canvas [as 别名]
# 或者: from canvas.Canvas import clear [as 别名]
class Window(object):
def __init__(self, pixels, width, height):
self.pixels = pixels
self.width = width
self.height = height
self.canvas = Canvas(width, height, pixels)
# setup key handlers
key_esc = 27
self.handlers = {
key_esc: self.exit
}
self.v1 = Vertex(Vector(0, 0), Color.cyan())
self.v2 = Vertex(Vector(300, 100), Color.red())
self.v3 = Vertex(Vector(200, 300), Color.white())
self.v4 = Vertex(Vector(300, 0), Color.green())
def clear(self):
self.canvas.clear()
pass
def update(self, dt):
pass
def draw(self):
self.canvas.draw_triangle(self.v1, self.v2, self.v4)
self.canvas.draw_triangle(self.v1, self.v2, self.v3)
def mouse_event(self, button, state, x, y):
print('mouse event', button, state, x, y)
# 0, left button
# 2, right button
# 0, state press
# 1, state release
def exit(self):
sys.exit(0)
def cmd404(self):
pass
def key_event(self, key, key_is_down):
print('key event', key, key_is_down)
cmd = self.handlers.get(key, self.cmd404)
cmd()
示例4: iter
# 需要导入模块: from canvas import Canvas [as 别名]
# 或者: from canvas.Canvas import clear [as 别名]
class Display:
wire = None
brightness = BRIGHTNESS.FULL
canvas = None
visualizers = iter(all_visualizers)
cur_visual = None
def __init__(self, size, wire, brightness, visualizer):
assert brightness in [BRIGHTNESS.OFF, BRIGHTNESS.ONE, BRIGHTNESS.TWO, BRIGHTNESS.THREE, BRIGHTNESS.FULL]
self.wire = wire
self.canvas = Canvas(size)
self.set_brightness(brightness)
self.cur_visual = all_visualizers[visualizer]
# set the iterator to the value that matches the visualizer parameter
while True:
try:
if self.cur_visual == self.visualizers.next():
break
except:
self.visualizers = iter(all_visualizers)
pass
@classmethod
def dump_defaults(cls):
return {"brightness": BRIGHTNESS.FULL, "visualizer": 0}
def dump_settings(self):
return {"brightness": self.brightness, "visualizer": all_visualizers.index(self.cur_visual)}
def set_brightness(self, brightness, remember=True):
if brightness < BRIGHTNESS.OFF or brightness > BRIGHTNESS.FULL:
raise Exception, "Unknown brightness code %d" % brightness
if remember:
self.brightness = brightness
grfb = Grfb()
grfb.brightness = BRIGHTNESS.map[brightness]
self.wire.send(grfb.serialize())
def next_brightness(self):
if self.brightness - 1 < BRIGHTNESS.OFF:
self.set_brightness(BRIGHTNESS.FULL)
else:
self.set_brightness(self.brightness - 1)
def next_visualizer(self):
try:
visu = self.visualizers.next()
self.wire.send(visu.serialize())
self.cur_visual = visu
except:
self.visualizers = iter(all_visualizers)
self.next_visualizer()
def visualizer_on(self):
self.wire.send(self.cur_visual.serialize())
def visualizer_off(self):
self.wire.send(VisuNone().serialize())
def show(self, transition):
self.canvas.prepare_transmission()
grfe = Grfe()
grfe.transition = transition
grfe.bitmap = self.canvas.bitmap
self.wire.send(grfe.serialize())
def clear(self):
self.canvas.clear()
self.show(TRANSITION.NONE)