<s> """<STR_LIT>""" <EOL> __version__ = "<STR_LIT>" <EOL> __docformat__ = "<STR_LIT>" <EOL> import random <EOL> import pygame <EOL> from pygame . locals import * <EOL> from pygame . color import * <EOL> import pymunk <EOL> from pymunk import Vec2d <EOL> def to_pygame ( p ) : <EOL> """<STR_LIT>""" <EOL> return int ( p . x ) , int ( - p . y + <NUM_LIT> ) <EOL> pygame . init ( ) <EOL> screen = pygame . display . set_mode ( ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> clock = pygame . time . Clock ( ) <EOL> running = True <EOL> space = pymunk . Space ( <NUM_LIT:50> ) <EOL> space . gravity = ( <NUM_LIT:0.0> , - <NUM_LIT> ) <EOL> balls = [ ] <EOL> static_body = pymunk . Body ( ) <EOL> static_lines = [ pymunk . Segment ( static_body , ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) , <NUM_LIT:1.0> ) <EOL> , pymunk . Segment ( static_body , ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) , <NUM_LIT:1.0> ) <EOL> , pymunk . Segment ( static_body , ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) , <NUM_LIT:1.0> ) <EOL> , pymunk . Segment ( static_body , ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) , <NUM_LIT:1.0> ) <EOL> , pymunk . Segment ( static_body , ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) , <NUM_LIT:1.0> ) <EOL> ] <EOL> for line in static_lines : <EOL> line . elasticity = <NUM_LIT> <EOL> line . group = <NUM_LIT:1> <EOL> space . add ( static_lines ) <EOL> fp = [ ( <NUM_LIT:20> , - <NUM_LIT:20> ) , ( - <NUM_LIT> , <NUM_LIT:0> ) , ( <NUM_LIT:20> , <NUM_LIT:20> ) ] <EOL> mass = <NUM_LIT:100> <EOL> moment = pymunk . moment_for_poly ( mass , fp ) <EOL> r_flipper_body = pymunk . Body ( mass , moment ) <EOL> r_flipper_body . position = <NUM_LIT> , <NUM_LIT:100> <EOL> r_flipper_shape = pymunk . Poly ( r_flipper_body , fp ) <EOL> space . add ( r_flipper_body , r_flipper_shape ) <EOL> r_flipper_joint_body = pymunk . Body ( ) <EOL> r_flipper_joint_body . position = r_flipper_body . position <EOL> j = pymunk . PinJoint ( r_flipper_body , r_flipper_joint_body , ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> s = pymunk . DampedRotarySpring ( r_flipper_body , r_flipper_joint_body , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> space . add ( j , s ) <EOL> l_flipper_body = pymunk . Body ( mass , moment ) <EOL> l_flipper_body . position = <NUM_LIT> , <NUM_LIT:100> <EOL> l_flipper_shape = pymunk . Poly ( l_flipper_body , [ ( - x , y ) for x , y in fp ] ) <EOL> space . add ( l_flipper_body , l_flipper_shape ) <EOL> l_flipper_joint_body = pymunk . Body ( ) <EOL> l_flipper_joint_body . position = l_flipper_body . position <EOL> j = pymunk . PinJoint ( l_flipper_body , l_flipper_joint_body , ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> s = pymunk . DampedRotarySpring ( l_flipper_body , l_flipper_joint_body , - <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> space . add ( j , s ) <EOL> r_flipper_shape . group = l_flipper_shape . group = <NUM_LIT:1> <EOL> r_flipper_shape . elasticity = l_flipper_shape . elasticity = <NUM_LIT> <EOL> for p in [ ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) ] : <EOL> body = pymunk . Body ( ) <EOL> body . position = p <EOL> shape = pymunk . Circle ( body , <NUM_LIT:10> ) <EOL> shape . elasticity = <NUM_LIT> <EOL> space . add ( shape ) <EOL> balls . append ( shape ) <EOL> while running : <EOL> for event in pygame . event . get ( ) : <EOL> if event . type == QUIT : <EOL> running = False <EOL> elif event . type == KEYDOWN and event . key == K_ESCAPE : <EOL> running = False <EOL> elif event . type == KEYDOWN and event . key == K_p : <EOL> pygame . image . save ( screen , "<STR_LIT>" ) <EOL> elif event . type == KEYDOWN and event . key == K_j : <EOL> r_flipper_body . apply_impulse ( Vec2d . unit ( ) * <NUM_LIT> , ( - <NUM_LIT:100> , <NUM_LIT:0> ) ) <EOL> elif event . type == KEYDOWN and event . key == K_f : <EOL> l_flipper_body . apply_impulse ( Vec2d . unit ( ) * - <NUM_LIT> , ( - <NUM_LIT:100> , <NUM_LIT:0> ) ) <EOL> elif event . type == KEYDOWN and event . key == K_b : <EOL> mass = <NUM_LIT:1> <EOL> radius = <NUM_LIT> <EOL> inertia = pymunk . moment_for_circle ( mass , <NUM_LIT:0> , radius , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> body = pymunk . Body ( mass , inertia ) <EOL> x = random . randint ( <NUM_LIT> , <NUM_LIT> ) <EOL> body . position = x , <NUM_LIT> <EOL> shape = pymunk . Circle ( body , radius , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> shape . elasticity = <NUM_LIT> <EOL> space . add ( body , shape ) <EOL> balls . append ( shape ) <EOL> screen . fill ( THECOLORS [ "<STR_LIT>" ] ) <EOL> for ball in balls : <EOL> p = to_pygame ( ball . body . position ) <EOL> pygame . draw . circle ( screen , THECOLORS [ "<STR_LIT>" ] , p , int ( ball . radius ) , <NUM_LIT:2> ) <EOL> for line in static_lines : <EOL> body = line . body <EOL> pv1 = body . position + line . a . rotated ( body . angle ) <EOL> pv2 = body . position + line . b . rotated ( body . angle ) <EOL> p1 = to_pygame ( pv1 ) <EOL> p2 = to_pygame ( pv2 ) <EOL> pygame . draw . lines ( screen , THECOLORS [ "<STR_LIT>" ] , False , [ p1 , p2 ] ) <EOL> r_flipper_body . position = <NUM_LIT> , <NUM_LIT:100> <EOL> l_flipper_body . position = <NUM_LIT> , <NUM_LIT:100> <EOL> r_flipper_body . velocity = l_flipper_body . velcoty = <NUM_LIT:0> , <NUM_LIT:0> <EOL> for f in [ r_flipper_shape , l_flipper_shape ] : <EOL> ps = f . get_vertices ( ) <EOL> ps . append ( ps [ <NUM_LIT:0> ] ) <EOL> ps = map ( to_pygame , ps ) <EOL> color = THECOLORS [ "<STR_LIT>" ] <EOL> pygame . draw . lines ( screen , color , False , ps ) <EOL> dt = <NUM_LIT:1.0> / <NUM_LIT> / <NUM_LIT> <EOL> for x in range ( <NUM_LIT:5> ) : <EOL> space . step ( dt ) <EOL> pygame . display . flip ( ) <EOL> clock . tick ( <NUM_LIT:50> ) <EOL> pygame . display . set_caption ( "<STR_LIT>" + str ( clock . get_fps ( ) ) ) </s>
