I was making a program for displaying a sine graph in C, here is a small part of program
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static int cxClient, cyClient;
HDC hdc;
int i;
PAINTSTRUCT ps;
POINT apt[NUM];
switch (message)
{
case WM_SIZE:
cXClient = LOWORD(lParam);
cyClient = HIWORD(lParam);
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
MoveToEx(hdc, 0, cyClient / 2, 0);
LineTo(hdc, cxClient, cyClient / 2);
for (i = 0; i < NUM; i++)
{
apt[i].x = i * cxClient / NUM;
apt[i].y = (int) (height / 2 * (1 - sin(TWOPI * i / NUM)));
}
Polyline(hdc, apt, NUM);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
where NUM is set to 1000 and cxClient is the width of client area iin low word and cyClient is height of client area in high word,TWOPI is defined globally as (2*3.1459)
My problem with the program is
1.I cannot understand the line apt[i].x and apt[i].y (including the sine form).
2.When I defined TWOPI as #define TWOPI (2*(22/7)) instead of(#define TWOPI (2*3.1459)) then the graph was square shaped , but both things are same ,instead this is more accurate so why did this happened.
These things are not explained in the book so I am asking you.