#include<windows.h>
#include<graphics.h>
#include<conio.h>
#include<stdlib.h>
#include<time.h>
#define WIN_WIDTH 800
#define WIN_HIGH 600
void CALLBACK timerproc(HWND, UINT, UINT, DWORD){
setlinecolor(RGB(rand() % 256, rand() % 256, rand() % 256));
}
void main(){
HWND hwnd;
int x1, y1, x2, y2;
int mx1, mx2, my1, my2;
srand((int)time(0));
x1 = rand() % WIN_WIDTH;
y1 = rand() % WIN_HIGH;
x2 = rand() % WIN_WIDTH;
y2 = rand() % WIN_HIGH;
mx1 = rand() % 8 - 4;
my1 = rand() % 8 - 4;
mx2 = rand() % 8 - 4;
my2 = rand() % 8 - 4;
a.top = -1;
initgraph(WIN_WIDTH, WIN_HIGH);
setlinecolor(RED);
hwnd = GetHWnd();
SetTimer(hwnd, 1, 5000, timerproc);
MoveWindow(hwnd, 300, 20, WIN_WIDTH, WIN_HIGH, true);
while (1){
x1 += mx1;
x2 += mx2;
y1 += my1;
y2 += my2;
if (x1<0 || x1>WIN_WIDTH) { mx1 = -mx1; x1 += mx1; }
if (x2<0 || x2>WIN_WIDTH) { mx2 = -mx2; x2 += mx2; }
if (y1<0 || y1>WIN_HIGH) { my1 = -my1; y1 += my1; }
if (y2<0 || y2>WIN_HIGH) { my2 = -my2; y2 += mx2; }
line(x1,y1,x2,y2);
Sleep(10);
}
_getch();
}