本文整理汇总了Python中canvas.Canvas.save方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.save方法的具体用法?Python Canvas.save怎么用?Python Canvas.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类canvas.Canvas
的用法示例。
在下文中一共展示了Canvas.save方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Filler
# 需要导入模块: from canvas import Canvas [as 别名]
# 或者: from canvas.Canvas import save [as 别名]
class Filler(object):
def __init__(self, bits, starting_pixel_count):
self.colorset = Colorset(bits)
# This is technically only correct for an even number of bits, but
# it rounds down for an odd number of bits, and there are simply some colors
# that we never use. Shrug.
height = width = int(math.sqrt(self.colorset.size()))
self.canvas = Canvas(width, height)
self.starting_pixel_count = starting_pixel_count
self.add_starting_pixels()
self.start_time = time.time()
self.last_save_time = time.time()
self.time_color = 0.0
self.time_point = 0.0
def add_starting_pixels(self):
# Grab some random starting colors just by making a randomly-sorted
# list of all the colors and taking the first few.
# Not the most efficient, but doesn't really matter.
colors = [x for x in self.colorset.iterate()]
random.shuffle(colors)
height = width = self.canvas.height
self.starting_pixel_list = []
for i in xrange(self.starting_pixel_count):
starting_color = self.colorset.get_nearest(colors[i])
x = random.randint(0, width-1)
y = random.randint(0, height-1)
self.starting_pixel_list.append((x, y))
self.canvas.set(x, y, starting_color)
def write_image(self, i):
bits = self.colorset.bits
name = '/tmp/colors-%s.%d.%d.%d.png' % (self.__class__.__name__,
bits,
self.starting_pixel_count,
i)
avg_rate = i / (time.time() - self.start_time)
print (name,
time.time() - self.last_save_time,
int(avg_rate),
int(self.time_color),
int(self.time_point))
self.canvas.save(name)
self.last_save_time = time.time()