#include "library.h" const int width = 800, height = 600; const int padw = 10, padh = 100, padspd = 10; const double dt = 5.0; const double pi = acos(-1.0); double deg_to_rad(double d) { return d / 180.0 * pi; } void main() { make_window(width, height); set_pen_width(5); while (true) { fill_rectangle(0, 0, width, height, color::white); double bx = random_in_range(0, .9*width); double by = random_in_range(0, height); double angle = random_in_range(0, 360000) / 1000.0; const double speed = 1.0; double vx = speed * sin(deg_to_rad(angle)); double vy = speed * cos(deg_to_rad(angle)); int pady = height / 2; draw_point(bx, by); while (true) { fill_rectangle(width - padw, pady, padw, padh, color::blue); bx += dt*vx; by += dt*vy; const int key = wait_for_key_typed(0.01); if (key == -90) { fill_rectangle(width - padw, pady, padw, padh, color::white); pady -= padspd; if (pady < 0) pady = 0; } if (key == -88) { fill_rectangle(width - padw, pady, padw, padh, color::white); pady += padspd; if (pady > height - padh) pady = height - padh; } draw_to(bx, by); if (bx >= width) { if (by >= pady && by <= pady + padh) vx = -vx; else break; } else if (bx <= 0) vx = -vx; if (by <= 0) vy = -vy; else if (by >= height) vy = -vy; } wait(4.0); } }