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


Python Graphics.readPixel方法代码示例

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


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

示例1: PlasmaFirst

# 需要导入模块: from Tools.Graphics import Graphics [as 别名]
# 或者: from Tools.Graphics.Graphics import readPixel [as 别名]
class PlasmaFirst(object):
    def __init__(self, speed=20):
        self.graphics = Graphics(matrix_width, matrix_height)
        self.plasma = Graphics(matrix_width, matrix_height)
        
        self.x_range = xrange(0, matrix_width, 1)
        self.y_range = xrange(0, matrix_height, 1)

        self.interval = .1/speed #interval/speed is how many ticks a second.
        self.time = 0
        self.previousTick = 0

        self.generatePalette()
        self.generatePlasmaSurface()
    def generatePalette(self):
        self.palette = []
        for x in xrange(0, 256, 1):
            colorRGB = HSVtoRGB((x,255,255,))
            self.palette.append(colorRGB)
    def generatePlasmaSurface(self):
        for y in self.y_range:
            for x in self.x_range:
                #c = int(abs(256*sin((x+y+self.time)/3.0)))
                c = int(
                    128.0 + (128.0*sin((x+6)/2.4))
                    +128.0 + (128.0*cos(y/3.4))
                    )/2
                color = (c,)*3
                self.plasma.drawPixel(x,y,color)
        return list(self.plasma.getSurface())
    def process(self):
        if( (time.time()-self.previousTick) >= self.interval ):
            self.previousTick = time.time()
            self.time += 1
        paletteShift = self.time
        for y in self.y_range:
            for x in self.x_range:
                plasma_color = self.plasma.readPixel(x,y)
                color_shift = self.palette[paletteShift%256]
                r = (plasma_color[0]+color_shift[0])%256
                g = (plasma_color[1]+color_shift[1])%256
                b = (plasma_color[2]+color_shift[2])%256
                color = (r,g,b,)
                color = ColorRGBOps.darken(color, 50)
                self.graphics.drawPixel(x,y, color)
    def draw(self):
        pass
    def generate(self):
        self.graphics.fill(BLACK)
        self.process()
        self.draw()
        return self.graphics.getSurface()
开发者ID:ozel,项目名称:py-artnet,代码行数:54,代码来源:Plasma.py

示例2: PlasmaThird

# 需要导入模块: from Tools.Graphics import Graphics [as 别名]
# 或者: from Tools.Graphics.Graphics import readPixel [as 别名]
class PlasmaThird(object):
    def __init__(self, speed=10):
        self.graphics = Graphics(matrix_width, matrix_height)
        self.plasma = Graphics(matrix_width, matrix_height)

        self.x_range = xrange(0, matrix_width, 1)
        self.y_range = xrange(0, matrix_height, 1)

        self.speed = speed
        self.interval = speed
        self.time = random.randint(0,100)
        self.previousTick = 0

        self.angle = 0

        self.generatePalette()
        self.generatePlasmaSurface()
    def generatePalette(self):
        self.palette = []
        for x in xrange(0, (2**8), 1):
            r = int(128+256*sin(x)/20)
            g = int(128+256*sin(r)/100)
            b = int(128+256*sin(g)/50)
            colorRGB = (r,g,b)
            self.palette.append(colorRGB)
    def generatePlasmaSurface(self):
        self.angle = self.time
        x_offset = matrix_width*sin(radians(self.angle))+matrix_width
        y_offset = matrix_height*cos(radians(self.angle))+matrix_height
        for y in self.y_range:
            for x in self.x_range:
                c = int(
                     128+(128*sin((x+x_offset)/2.0))
                    +128+(128*sin((y+y_offset)/2.0))
                    +128+(128*sin(((x+x_offset)+(y+y_offset))/2.0))
                    +128+(128*sin(sqrt(float((x+x_offset)*(x+x_offset)+(y+y_offset)*(y+y_offset)))/2.0))
                    )/4
                color = (c,)*3
                self.plasma.drawPixel(x,y,color)
        return list(self.plasma.getSurface())
    def process(self):
        if((time.time()-self.previousTick) >= 1./self.interval):
            self.previousTick = time.time()
            self.time+=1
    def draw(self):
        paletteShift = self.time
        self.generatePlasmaSurface()
        for y in self.y_range:
            for x in self.x_range:
                plasma_color = self.plasma.readPixel(x,y)
                color_shift = self.palette[paletteShift%256]
                r = (plasma_color[0]+color_shift[0])%256
                g = (plasma_color[1]+color_shift[1])%256
                b = (plasma_color[2]+color_shift[2])%256
                color = (r,g,b,)
                #darken the color to create a better contrast
                color = ColorRGBOps.brighten(color, 20)
                self.graphics.drawPixel(x,y, color)
    def generate(self):
        self.graphics.fill(BLACK)
        self.process()
        self.draw()
        return self.graphics.getSurface()
开发者ID:ozel,项目名称:py-artnet,代码行数:65,代码来源:Plasma.py


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