本文整理汇总了Python中canvas.Canvas.draw方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.draw方法的具体用法?Python Canvas.draw怎么用?Python Canvas.draw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类canvas.Canvas
的用法示例。
在下文中一共展示了Canvas.draw方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LabArm
# 需要导入模块: from canvas import Canvas [as 别名]
# 或者: from canvas.Canvas import draw [as 别名]
class LabArm():
def __init__(self):
pygame.init()
self.imgs = Images()
self.canvas = Canvas()
self.netw = Network()
self.fonts = Fonts()
self.events = PCEvents()
self.buttons = Buttons()
self.screen = pygame.display.set_mode(SCREEN_SIZE)
def run(self):
while True:
self.events.handle(self.screen, self.netw)
self.canvas.draw(self.screen)
self.buttons.draw(self.screen)
self.fonts.draw(self.screen)
self.netw.draw(self.screen)
pygame.display.flip()
示例2: __init__
# 需要导入模块: from canvas import Canvas [as 别名]
# 或者: from canvas.Canvas import draw [as 别名]
class CobraSketch:
'''Main Class'''
def __init__(self):
self.width = 800
self.height = 600
self.window = window.Window(self.width-1, self.height-1)
self.window.register_event_type('on_update')
pyglet.clock.schedule(self.update)
self.canvas = Canvas(self.width, self.height, "Filename", "Path")
#Create event handlers
self.on_mouse_drag = self.window.event(self.on_mouse_drag)
self.on_draw = self.window.event(self.on_draw)
self.on_mouse_press = self.window.event(self.on_mouse_press)
self.on_mouse_release = self.window.event(self.on_mouse_release)
#Import theme
self.cobalt = kytten.Theme(os.path.join(os.getcwd(), 'theme'), override={
"font_size": 10
})
self.bg_group = pyglet.graphics.OrderedGroup(0)
self.fg_group = pyglet.graphics.OrderedGroup(500)
#Create GUI
self.mainDialog()
self.layerDialog()
# # # # # # # # # # # # # #
# File Manipulation Follows
#
def open(self, file):
'''Determines whether the file is a CobraSketch file or a bitmap
and acts accordingly to load that file into the program.'''
fileName = file.split('.')
fileType = fileName[len(fileName)-1]
if fileType.lower() == 'png':
self.canvas.load(self._loadPNG(file))
else:
print(fileType, ' not supported.')
def save(self, file):
'''Accepts a file location and saves either a bitmap or
Cobrasketch file.'''
fileName = file.split('.')
fileType = fileName[len(fileName)-1]
if fileType.lower() == 'png':
self._savePNG(file, self.canvas.export())
else:
print(fileType, ' not supported.')
def _loadPNG(self, file):
'''Returns an array containing the pixel data for a PNG'''
png = pyglet.image.load(file)
data = png.get_data('RGB', png.width*3)
return [int.from_bytes(data[i:i+1],'little') for i in range(0,len(data), 1)]
def _savePNG(self, file, pixels):
'''Saves the current program state to a file'''
#print("loading blank")
out = pyglet.image.load('theme/blank.png')
#print("blank loaded")
pixels = [item for sublist in [[x, x, x] for x in pixels] for item in sublist]
#print("pixels pixled")
frame = bytes(pixels)
out.set_data('RGB', out.width*3, frame)
out.save(file)
def _importImage(self, file):
'''Loads a bitmap into the canvas'''
def _exportImage(self, file):
'''Saves the canvas to a bitmap'''
# # # # # # # # # # # # #
# Event Handlers Follow
#
def on_mouse_drag(self, x, y, dx, dy, button, modifiers):
if button == mouse.LEFT:
if(x > 0 and y > 1 and x < self.width and y < self.height-1):
self.canvas.addPoint(x,y)
def on_mouse_press(self, x, y, button, modifiers):
'''Event handler for mouse pressing.'''
def on_mouse_release(self, x, y, button, modifiers):
'''Event handler for mouse release.'''
self.canvas.endLine(x, y)
def on_draw(self):
self.window.clear()
self.canvas.draw()
# # # # # # # # # # # # #
#.........这里部分代码省略.........
示例3: CliParser
# 需要导入模块: from canvas import Canvas [as 别名]
# 或者: from canvas.Canvas import draw [as 别名]
from matrix import Matrix
import math, sys
if __name__ == '__main__':
cli_parser = CliParser()
#cli_parser.debug()
args = cli_parser.args
ps_reader = PsReader(args.filename)
primitives = ps_reader.read()
transforms = [
Matrix().scale(scale_x=args.scaling_factor, scale_y=args.scaling_factor),
Matrix().rotate_ccw(degrees=args.ccw_rotation),
Matrix().translate(x=args.translate_x, y=args.translate_y),
]
world = [args.x_min, args.x_max, args.y_min, args.y_max]
canvas = Canvas(world)
canvas.set_color("#000000")
primitives = [primitive.t(transforms).clip(world) for primitive in primitives]
primitives = [p for p in primitives if p is not None]
for primitive in primitives:
canvas.draw(primitive)
print canvas.as_pixmap()
示例4: Orthographic
# 需要导入模块: from canvas import Canvas [as 别名]
# 或者: from canvas.Canvas import draw [as 别名]
elif proj_type == "parallel":
projection = Orthographic(view_ref_c, proj_ref_p)
else:
raise RuntimeError("not implemented projection: %s" % projection)
canvas = Canvas([args.vrc_u_min, args.vrc_u_max, args.vrc_v_min, args.vrc_v_max], OUTPUT_RESOLUTION)
# working?
scale_x = float(args.vp_x_max - args.vp_x_min) / (2.0)
scale_y = float(args.vp_y_max - args.vp_y_min) / (2.0)
viewport_transforms = [
Matrix(3, 3).translate(x=1.0, y=1.0),
Matrix(3, 3).scale(scale_x=scale_x, scale_y=scale_y),
Matrix(3, 3).translate(x=args.vp_x_min, y=args.vp_y_min),
]
transforms = camera.get_view_transforms()
for face in smf_reader.faces():
# canonical view, then project
face = face.t(transforms).t(projection.matrix())
if not face.clip(clip_vol):
continue
polygon = projection.project(face)
clipped_polygon = polygon.clip([args.vrc_u_min, args.vrc_u_max, args.vrc_v_min, args.vrc_v_max])
viewport_polygon = polygon.t(viewport_transforms)
canvas.draw(viewport_polygon)
canvas.set_color("#000000")
print canvas.as_pixmap()