コード例 #1
0
ファイル: grid.py プロジェクト: DweebsUnited/LightingSim
class Grid:
    # Class to rasterize a Field down into a big grid of squares

    def __init__( self, wide, high ):
        # Basic, keep a background field, and a 2d array of values

        self.f = Field( )

        self.w = wide
        self.h = high

        self.vals = [ [ 0 for i in range( self.w ) ] for j in range( self.h ) ]

        # Pre-compute all the box values
        self.step( 0.0 )

    def reset( self ):
        # Basic, reset the underlying field

        self.f.reset( )

    def step( self,perc ):
        # Again basic, step the field, then compute all the box values

        self.f.step( perc )

        self.compute( )

    def compute( self ):

        for y in range( self.h ):

            for x in range( self.w ):

                # Map the x and y to the center of the box, get a value from the field
                self.vals[ y ][ x ] = self.f.getVal( float( x ) / ( self.w - 1 ), float( y ) / ( self.h - 1 ) )

    def getVal( self, x, y ):
        # Basic as it gets

        return self.vals[ y ][ x ]