当前位置: 首页>>代码示例>>Python>>正文


Python Canvas.set方法代码示例

本文整理汇总了Python中canvas.Canvas.set方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.set方法的具体用法?Python Canvas.set怎么用?Python Canvas.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在canvas.Canvas的用法示例。


在下文中一共展示了Canvas.set方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Filler

# 需要导入模块: from canvas import Canvas [as 别名]
# 或者: from canvas.Canvas import set [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()
开发者ID:mkjones,项目名称:allrgb,代码行数:50,代码来源:filler.py


注:本文中的canvas.Canvas.set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。