""" GDRAW Demonstration: Bouncing Ball with User Controlled Paddle.""" ## Use with command "python -i bounce.py", where this file is called bounce.py, ## OR try uncommenting the last line of this file. ## This code is a direct translation of the original STK (scheme) code. ## Copyright 2005 Boley from gdraw import * from gc import collect ## this is optional ball=fill_oval(110,110,120,120,'red') box=draw_rectangle(100,100,400,400) paddle=fill_rectangle(90,100,100,150,'black') velocity=[7,11] move_p=[False] def center(coords): return [(coords[0]+coords[2])/2,(coords[1]+coords[3])/2] def get_new_pos(): ## compute next ball position, checking for wall bounce old_pos=get_coords(ball) pos_paddle=get_coords(paddle) pos_box=get_coords(box) new_pos=[old_pos[0]+velocity[0], old_pos[1]+velocity[1],\ old_pos[2]+velocity[0], old_pos[3]+velocity[1]] if new_pos[0]