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


Python Transform.inverse方法代码示例

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


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

示例1: LedScreen

# 需要导入模块: from transform import Transform [as 别名]
# 或者: from transform.Transform import inverse [as 别名]
class LedScreen(abstractled.AbstractLed):
    """
The low-level LED wall screen.
    """

    def __init__(self, fname='/dev/ttyACM0', brate=1000000, dim=(12,10), gamma=2.2):
        """
Initialise a LedScreen object.

>>> screen = LedScreen()
        """
        if type(dim) not in (tuple, list) or len(dim) != 2:
            raise ValueError("Invalid dimension. Format is tuple(x,y)")
        abstractled.AbstractLed.__init__(self, dimension=dim, gamma=gamma)
        self.tty = uspp.SerialPort(fname, timeout=0)
        #self.tty = uspp.SerialPort(fname, speed=brate, timeout=0)
        os.environ['LEDWALL_TTY'] = fname
        os.system("stty -F $LEDWALL_TTY " + str(brate))

        self.transform = Transform(*dim)
        self.b = [(0,0,0)] * self.w * self.h

    def __setitem__(self, tup, val):
        abstractled.AbstractLed.__setitem__(self, tup, val)

        waiting = self.tty.inWaiting()
        if waiting > 0:
            _ = self.tty.read(waiting)

    def push(self):
        for x in xrange(self.w):
            for y in xrange(self.h):
                i = x + y * self.w
                self.b[self.transform.inverse( (x, y) )] = self.buf[i]

        self.tty.write( ''.join(chr(g)+chr(r)+chr(b) for r,g,b in self.b) + chr(254) )
开发者ID:elout,项目名称:lewd,代码行数:38,代码来源:led.py

示例2: LedScreen

# 需要导入模块: from transform import Transform [as 别名]
# 或者: from transform.Transform import inverse [as 别名]
class LedScreen(object):
    """
The low-level LED wall screen.
    """

    def __init__(self, fname='/dev/ttyACM0', brate=1000000, dim=(12,10), gamma=2.2):
        """
Initialise a LedScreen object.

>>> screen = LedScreen()
        """
        if type(dim) not in (tuple, list) or len(dim) != 2:
            raise ValueError("Invalid dimension. Format is tuple(x,y)")
        self.tty = uspp.SerialPort(fname, timeout=0)
        #self.tty = uspp.SerialPort(fname, speed=brate, timeout=0)
        os.environ['LEDWALL_TTY'] = fname
        os.system("stty -F $LEDWALL_TTY " + str(brate))
        self.w, self.h = dim
        self.buf = [(0, 0, 0)] * self.w * self.h
        self.transform = Transform(*dim)

        gamma = float(gamma)
        max_gamma = 255.**gamma
        self.gamma_map = [ int( (1 + 2 * x**gamma / (max_gamma/255.)) //2 ) for x in xrange(256) ]
        for i, v in enumerate(self.gamma_map):
            if v == 254:
                self.gamma_map[i] = 253

    def gamma_correct(self, colour):
        """
Returns gamma-corrected colour.
        """
        return tuple(self.gamma_map[c] for c in colour)

    def __setitem__(self, tup, val):
        """
Allows for easy frame access.
Use like:

>>> screen[(x, y)] = r, g, b
        """
        if type(tup) not in (tuple, list) or len(tup) != 2:
            raise ValueError("tup should be a tuple of length 2")

        if type(val) not in (tuple, list) or len(val) != 3:
            raise ValueError("val should be a tuple of length 3")

        if tup[0] not in range(0, self.w) or tup[1] not in range(0, self.h):
            raise ValueError("tup should be inside the grid:", (self.w, self.h))

        self.buf[self.transform.inverse(tup)] = self.gamma_correct(val)

        waiting = self.tty.inWaiting()
        if waiting > 0:
            _ = self.tty.read(waiting)

    def push(self):
        """
Push the current frame contents to the screen
        """
        self.tty.write( ''.join(chr(g)+chr(r)+chr(b) for r,g,b in self.buf) + chr(254) )

    def load_data(self, data):
        """
Load byte array to framebuffer. Does not send anything yet.
        """
        for i in xrange( min( len(data)/3, self.w*self.h ) ):
            x, y = i % self.w, i // self.w
            self[ (x, y) ] = tuple( ord(x) for x in data[i*3:(i+1)*3] )

    def push_data(self, data):
        """
Push byte array to the screen.
        """
        self.load_data(data)
        self.push()

    def load_frame(self, frame):
        """
Load three-dimensional array to framebuffer. Does not send anything yet.

>>> _ = (0,0,0)   # black
>>> X = (0,255,0) # green

>>> frame = [
...     [_,_,_,_,_,_,_,_,_,_,_,_,],
...     [_,_,_,X,_,_,_,_,_,X,_,_,],
...     [_,_,_,_,X,_,_,_,X,_,_,_,],
...     [_,_,_,X,X,X,X,X,X,X,_,_,],
...     [_,_,X,X,_,X,X,X,_,X,X,_,],
...     [_,X,X,X,X,X,X,X,X,X,X,X,],
...     [_,X,_,X,X,X,X,X,X,X,_,X,],
...     [_,X,_,X,_,_,_,_,_,X,_,X,],
...     [_,_,_,_,X,X,_,X,X,_,_,_,],
...     [_,_,_,_,_,_,_,_,_,_,_,_,],
... ],

>>> screen.load_frame(frame) # doesn't write yet
>>> screen.push()            # display
        """
#.........这里部分代码省略.........
开发者ID:v1kko,项目名称:lewd,代码行数:103,代码来源:led.py


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