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


Python Picture.set_pixel方法代码示例

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


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

示例1: __init__

# 需要导入模块: from picture import Picture [as 别名]
# 或者: from picture.Picture import set_pixel [as 别名]
class Drawing:
    def __init__(self, width, height):
        """
        Constructors for the Drawing class.

        Parameters:
        width: int, the width of the image in pixels
        height: int, the height of the image in pixels
        """
        self.width = width
        self.height = height
        self.picture = Picture(width, height)
        self.pixel_depths = [[float("-inf") for x in range(width)] for y in range(height)]
        self.matrix_stack = [TransformationMatrix.identity()]
        self.view_vector = None

    def _set_pixel(self, x, y, color, suppress_error=True, z_depth=float("-inf")):
        """
        Sets a pixel on the internal raster with reference to the original
        origin (ignoring the current TransformationMatrix).

        Parameters:
        x: int, the x coordinate of the pixel to set
        y: int, the y coordinate of the pixel to set
        color: Color, the color to set the pixel to
        suppress_error: bool (optional), when set to True, will suppress
        the error if the pixel is out of bounds
        z_depth: float (optional), the depth of the pixel, if this pixel is
        lower in depth than the current pixel, then it will not be drawn
        """
        # The coordinates are reversed because of the way lists of lists
        # work in Python.
        try:
            if z_depth >= self.pixel_depths[y][x]:
                self.pixel_depths[y][x] = z_depth
                self.picture.set_pixel(x, y, color)
        except IndexError, exception:
            if not suppress_error:
                raise exception
开发者ID:omgimanerd,项目名称:graphics,代码行数:41,代码来源:drawing.py


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