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


Python Graphics.getSurfaceWidth方法代码示例

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


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

示例1: RandomLife

# 需要导入模块: from Tools.Graphics import Graphics [as 别名]
# 或者: from Tools.Graphics.Graphics import getSurfaceWidth [as 别名]
class RandomLife(object):
    def __init__(self):
        self.life = Life(matrix_width, matrix_height, 1, color=BLACK)
        self.graphics = Graphics(matrix_width, matrix_height)

    def pickRandomColor(self):
        color = random.randint(0, len(COLORS) - 1)
        # make sure that that color isn't black
        while(COLORS[color] == BLACK):
            color = random.randint(0, len(COLORS) - 1)
        return COLORS[color]

    def drawRandomColor(self):
        life_matrix = self.graphics.toMatrix(self.life.field,
                                             self.graphics.getSurfaceWidth())
        for y in self.graphics.heightRange:
            for x in self.graphics.widthRange:
                if life_matrix[y][x]:
                    color = self.pickRandomColor()
                    # give every lifing cell a random color
                    self.graphics.drawPixel(x, y, color)
                else:
                    self.graphics.drawPixel(x, y, BLACK)

    def draw(self):
        self.drawRandomColor()

    def generate(self):
        self.life.process()
        self.draw()
        return self.graphics.getSurface()
开发者ID:ozel,项目名称:py-artnet,代码行数:33,代码来源:PixelLife.py

示例2: BlueLife

# 需要导入模块: from Tools.Graphics import Graphics [as 别名]
# 或者: from Tools.Graphics.Graphics import getSurfaceWidth [as 别名]
class BlueLife(object):
    def __init__(self):
        self.life = Life(matrix_width, matrix_height, 1, color=BLUE)
        self.graphics = Graphics(matrix_width, matrix_height)

    def draw(self):
        life_matrix = self.graphics.toMatrix(self.life.field, self.graphics.getSurfaceWidth())
        for y in self.graphics.heightRange:
            for x in self.graphics.widthRange:
                if life_matrix[y][x]:
                    color = BLUE
                else:
                    color = BLACK
                self.graphics.drawPixel(x, y, color)

    def generate(self):
        self.life.process()
        self.draw()
        return self.graphics.getSurface()
开发者ID:ozel,项目名称:py-artnet,代码行数:21,代码来源:PixelLife.py


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