<s> from math import sin , cos , pi <EOL> import pg <EOL> import random <EOL> class LegoMan ( object ) : <EOL> def __init__ ( self ) : <EOL> self . x = ( random . random ( ) - <NUM_LIT:0.5> ) * <NUM_LIT:50> <EOL> self . z = ( random . random ( ) - <NUM_LIT:0.5> ) * <NUM_LIT:50> <EOL> self . a = random . random ( ) * pi * <NUM_LIT:2> <EOL> def update ( self , t , dt ) : <EOL> if random . random ( ) < <NUM_LIT> : <EOL> self . a += random . randint ( - <NUM_LIT:1> , <NUM_LIT:1> ) * pi / <NUM_LIT:8> <EOL> dx = cos ( self . a ) <EOL> dz = sin ( self . a ) <EOL> self . x += dx * dt <EOL> self . z += dz * dt <EOL> class Window ( pg . Window ) : <EOL> def setup ( self ) : <EOL> self . wasd = pg . WASD ( self , speed = <NUM_LIT:10> ) <EOL> self . wasd . look_at ( ( <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:30> ) , ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> self . context = pg . Context ( pg . DirectionalLightProgram ( ) ) <EOL> self . mesh = pg . OBJ ( '<STR_LIT>' ) . center ( ) . smooth_normals ( ) <EOL> self . men = [ LegoMan ( ) for _ in xrange ( <NUM_LIT:50> ) ] <EOL> def update ( self , t , dt ) : <EOL> self . wasd . y = <NUM_LIT> <EOL> self . clear ( ) <EOL> for man in self . men : <EOL> man . update ( t , dt ) <EOL> a = man . a + pi / <NUM_LIT:2> <EOL> matrix = pg . Matrix ( ) . rotate ( ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) , a ) . translate ( ( - man . x , <NUM_LIT:0> , - man . z ) ) <EOL> inverse = pg . Matrix ( ) . rotate ( ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) , - a ) <EOL> self . context . light_direction = inverse * pg . normalize ( ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> self . context . camera_position = matrix . inverse ( ) * self . wasd . position <EOL> matrix = self . wasd . get_matrix ( matrix ) <EOL> matrix = matrix . perspective ( <NUM_LIT> , self . aspect , <NUM_LIT:0.1> , <NUM_LIT:1000> ) <EOL> self . context . matrix = matrix <EOL> self . mesh . draw ( self . context ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> pg . run ( Window ) </s>
