pygame is
Python
Simple DirectMedia Layer
 
 
pygame.org is
Site Swing
Wiki

TextureCoordinateArithmetic

      
Search:  
 
 
This class allows OpenGL texture coordinates to be easily scaled and translated Access the coordinates by index.
Index 0: left bottom
Index 1: left top
Index 2: right top
Index 3: right bottom


Be warned that __getitem__ operations are rather slow, so avoid using this class in an inner render loop.
class Coords(object):
    """
    A type for managing texture coordinates.
    Use * and / for scaling, + and - for translating.
    """
 
    def __init__(self, lrbt=(0.0,1.0,0.0,1.0)):
        self.lrbt = list(lrbt)
        
    def __repr__(self):
        return repr((self[0],self[1],self[2],self[3]))
        
    def __imul__(self, scalar):
        self.lrbt[:] = [i * scalar for i in self.lrbt]
        return self
        
    def __idiv__(self, scalar):
        self.lrbt[:] = [i / scalar for i in self.lrgb]
        return self
    
    def __iadd__(self, vec2):
        self.lrbt[0] += vec2[0]
        self.lrbt[1] += vec2[0]
        self.lrbt[2] += vec2[1]
        self.lrbt[3] += vec2[1]
        return self
        
    def __isub__(self, vec2):
        self.lrbt[0] -= vec2[0]
        self.lrbt[1] -= vec2[0]
        self.lrbt[2] -= vec2[1]
        self.lrbt[3] -= vec2[1]
        return self
 
    def __mul__(self, scalar):
        return Coords([i * scalar for i in self.lrbt])
 
    def __div__(self, scalar):
        return Coords([i / scalar for i in self.lrbt])
 
    def __add__(self, vec2):
        return Coords((self.lrbt[0]+vec2[0],
                       self.lrbt[1]+vec2[0],
                       self.lrbt[2]+vec2[1],
                       self.lrbt[3]+vec2[1]))
 
    def __sub__(self, vec2):
        return Coords((self.lrbt[0]-vec2[0],
                       self.lrbt[1]-vec2[0],
                       self.lrbt[2]-vec2[1],
                       self.lrbt[3]-vec2[1]))
        
    def __getitem__(self, i):
        if i == 0:
            return self.lrbt[0], self.lrbt[2]
        elif i == 1:
            return self.lrbt[0], self.lrbt[3]
        elif i == 2:
            return self.lrbt[1], self.lrbt[3]
        elif i == 3:
            return self.lrbt[1], self.lrbt[2]
        else:
            raise IndexError
spotlight

 
our projects
pygame.org welcomes all python game, art, music, sound, video and multimedia projects. If they use pygame or not.
 
recent releases
Oct 20, 2014

Oct 16, 2014

Oct 9, 2014

Oct 8, 2014

Oct 7, 2014

Oct 4, 2014

Oct 1, 2014

Sep 19, 2014

Sep 17, 2014

Sep 9, 2014

Sep 8, 2014

Sep 7, 2014

... more!
 
for pygame related questions, comments, and suggestions, please see help (lists, irc)