Exemplo n.º 1
0
    def transform ( self, xform ):
        """ Returns a new HLSATransform object representing the result of
            applying another HLSATransform specified by *xform* to this
            transform.
        """
        clamp = self.clamp

        return self.__class__(
            hue        = fmod( self.hue + xform.hue, 1.0 ),
            lightness  = clamp( self.lightness  + xform.lightness  ),
            saturation = clamp( self.saturation + xform.saturation ),
            alpha      = clamp( self.alpha      + xform.alpha      ),
        )
Exemplo n.º 2
0
    def paint ( self, g, x, y ):
        """ Paints the transition at the current time into the graphics context
            *g* at location (*x*,*y*), which defines the upper-left corner of
            where the images are drawn.
        """
        img       = self.image_0
        image_0   = img.bitmap
        image_1   = self.image_1.bitmap
        dx        = img.width
        dy        = img.height
        offset    = self.offset
        channel   = self.channel
        time      = self.time
        handler   = getattr( self, '_%s_%s' % ( self.direction, self.style ) )
        dxy       = ( dx, dy )[ self.direction in Vertical ]
        delay     = dt = 0.0
        if len( channel ) > 1:
            delay = self.delay
            dt    = delay / (len( channel ) - 1)

        time_base = 1.0 - delay

        for i, element in enumerate( channel ):
            t   = clamp( (time - (i * dt)) / time_base, 0.0, 1.0 )
            xy0 = int( round( t * dxy ) )
            for j in element:
                handler( g, image_0, image_1, i, x, y,
                         offset[ j ], offset[ j + 1 ], xy0, dxy )
Exemplo n.º 3
0
    def paint ( self, g, x, y ):
        """ Paints the transition at the current time into the graphics context
            *g* at location (*x*,*y*), which defines the upper-left corner of
            where the images are drawn.
        """
        image     = self.image_0
        time      = self.time
        style     = self.style
        g.opacity = 1.0
        g.pen     = None
        g.brush   = ( 0xFFFFFF, 0x000000 )[ style == 'black' ]
        solid     = False
        if style == 'normal':
            g.draw_bitmap( image.bitmap, x, y )
        else:
            if time < 0.5:
                g.draw_bitmap( image.bitmap, x, y )
                time *= 2.0
                solid = True
            else:
                g.draw_rectangle( x, y, image.width, image.height )
                time = 2.0 * (time - 0.5)

        image     = self.image_1.bitmap
        offset_x  = self.offset_x
        offset_y  = self.offset_y
        elements  = self.elements
        delay     = dt = 0.0
        if len( elements ) > 1:
            delay = self.delay
            dt    = delay / (len( elements ) - 1)

        time_base = 1.0 - delay
        for i, element in enumerate( elements ):
            row, column = element
            g.opacity   = clamp( (time - (i * dt)) / time_base, 0.0, 1.0 )
            x0 = offset_x[ column ]
            y0 = offset_y[ row ]
            dx = offset_x[ column + 1 ] - x0
            dy = offset_y[ row    + 1 ] - y0
            if solid:
                g.draw_rectangle( x + x0, y + y0, dx, dy )
            else:
                g.blit( x + x0, y + y0, dx, dy, image, x0, y0, dx, dy )

        if self.show_grid:
            g.opacity = min( 1.0, 3.0 - (6.0 * abs( time - 0.5 )) )
            dx        = offset_x[-1]
            dy        = offset_y[-1]
            for x0 in offset_x:
                g.draw_line( x + x0, y, x + x0, y + dy )

            for y0 in offset_y:
                g.draw_line( x, y + y0, x + dx, y + y0 )
Exemplo n.º 4
0
 def clamp ( self, value ):
     """ Returns the specified *value* clamped between to the range -1.0 to
         1.0.
     """
     return clamp( value, -1.0, 1.0 )