# Thread: how get multiple of 32?

1. ## how get multiple of 32?

i have these function for draw a line, using increment:
Code:
```void DDA(int x1, int y1, int x2, int y2, COLORREF Color, int SquareSize=32)
{
int dx = x2 - x1;
int dy = y2 - y1;
int x = x1;
int y = y1;

double theta = atan2(dy, dx);
double y_increment = SquareSize * tan(theta);
double x_increment = SquareSize;

if (y_increment > 1 || y_increment < -1) {
x_increment = SquareSize / fabs(y_increment);
}

HDC HDCConsole = GetWindowDC(GetConsoleWindow());
HPEN LineColor = CreatePen(0, 1, Color);
HPEN OldPen = (HPEN)SelectObject(HDCConsole, LineColor);

MoveToEx(HDCConsole, round(x1), round(y1), nullptr);
while (x <= x2)
{
x += x_increment;
y += y_increment;

LineTo(HDCConsole, round(x), round(y));
cout << x << "\n";
if(int(x) % SquareSize==0)
{
SetPixelV(HDCConsole,x,y,RGB(0,255,0));
SetPixelV(HDCConsole,x+1,y,RGB(0,255,0));
SetPixelV(HDCConsole,x+2,y,RGB(0,255,0));
cout << "hey";
}
}

SelectObject(HDCConsole, OldPen);
DeleteObject(LineColor);
}```
the value of 'x' is changed.. and, at some point, it must be multiple of 3... but why:
Code:
` if(int(x) % SquareSize==0)`
seems not correct, because isn't entered

2. ## Re: how get multiple of 32?

Big time funk going on there.

The problem might stem from the fact that you are adding a double (x_increment) to an int (x), so perhaps the resulting value of x isn't what you are expecting?

Or the problem could be that in the default case where SquareSize = 32, then if -1 <= y <= 1, then x_increment = 32, and if x isn't divisible by 32 to begin with, it also isn't going to be divisible by 32 after 32 is added to it.

No idea. Seems like the code or logic needs an overhaul, or you need to thoroughly explain what that code is supposed to be doing.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•