在画了很多圈后,我想要一个圆圈之间的手柄碰撞,但我不知道该怎么做。我希望圆圈的颜色是随机的。我使用函数RGB(),但它不起作用。请帮我 ! 。谢谢。
我的代码
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
HBRUSH brush;
HBRUSH hBrush;
HPEN hPen;
static int dX[10] , dY[10] ;
static int x[10], y[10], oldX[10], oldY[10];
switch (message)
{
case WM_CREATE:
SetTimer(hWnd, 1, 3, NULL);
Beep(750, 300);
for (int i = 0; i < 10; i++){
dX[i] = rand() % 15 + 0;
dY[i] = rand() % 15 + 0;
x[i] = rand() % 15 + 0;
y[i] = rand() % 15 + 0;
oldX[i] = x[i];
oldY[i] = y[i];
}
break;
case WM_TIMER:
hdc = GetDC(hWnd);
brush = (HBRUSH)SelectObject(hdc, GetStockObject(WHITE_BRUSH));
RECT temp[10];
RECT rect;
GetClientRect(hWnd, &rect);
brush = (HBRUSH)SelectObject(hdc, GetStockObject(RGB(rand() % 255 + 0, rand() % 255 + 0, rand() % 255 + 0)));
for (int i = 0; i <10; i++){
temp[i].left = oldX[i];
temp[i].top = oldY[i];
temp[i].right = oldX[i] + 30;
temp[i].bottom = oldY[i] + 30;
FillRect(hdc, &temp[i], brush);
Ellipse(hdc, x[i], y[i], 30 + x[i], 30 + y[i]);
oldX[i] = x[i];
oldY[i] = y[i];
x[i] += dX[i];
y[i] += dY[i];
if (x[i] + 30 > rect.right || x[i] < 0)
{
dX[i] = -dX[i];
}
if (y[i] + 30 > rect.bottom || y[i] < 0)
{
dY[i] = -dY[i];
}
}
SelectObject(hdc, brush);
ReleaseDC(hWnd, hdc);
break;
我的照片在这里演示。