-
Notifications
You must be signed in to change notification settings - Fork 4
/
bouncingcircles.cpp
46 lines (42 loc) · 999 Bytes
/
bouncingcircles.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <windows.h>
int main(){
int w = GetSystemMetrics(0), h = GetSystemMetrics(1);
int signX = 1;
int signY = 1;
int signX1 = 1;
int signY1 = 1;
int incrementor = 10;
int x = 10;
int y = 10;
while(1){
HDC hdc = GetDC(0);
x += incrementor * signX;
y += incrementor * signY;
int top_x = 0 + x;
int top_y = 0 + y;
int bottom_x = 100 + x;
int bottom_y = 100 + y;
HBRUSH brush = CreateSolidBrush(RGB(rand() % 255, rand() % 255, rand() % 255));
SelectObject(hdc, brush);
Ellipse(hdc, top_x, top_y, bottom_x, bottom_y);
if (y >= GetSystemMetrics(SM_CYSCREEN))
{
signY = -1;
}
if (x >= GetSystemMetrics(SM_CXSCREEN))
{
signX = -1;
}
if (y == 0)
{
signY = 1;
}
if (x == 0)
{
signX = 1;
}
Sleep(10);
DeleteObject(brush);
ReleaseDC(0, hdc);
}
}