// Copyright (c) LeafCore
# Include <windows. h>
# Include <math. h>
# Include <time. h>
Lresult callback WindowProcedure (HWND, UINT, WPARAM, LPARAM );
Void draw (HDC );
Char szClassName [] = "LeafCore ";
Int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
Int nFunsterStil)
{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;
Wincl. hInstance = hThisInstance;
Wincl. lpszClassName = szClassName;
Wincl. lpfnWndProc = WindowProcedure;
Wincl. style = CS_DBLCLKS;
Wincl. cbSize = sizeof (WNDCLASSEX );
Wincl. hIcon = LoadIcon (NULL, IDI_APPLICATION );
Wincl. hIconSm = LoadIcon (NULL, IDI_APPLICATION );
Wincl. hCursor = LoadCursor (NULL, IDC_ARROW );
Wincl. lpszMenuName = NULL;
Wincl. cbClsExtra = 0;
Wincl. cbWndExtra = 0;
Wincl. hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH );
If (! RegisterClassEx (& wincl ))
Return 0;
Hwnd = createdomainwex (
0,
SzClassName,
"LeafCore ",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
1024,
768,
HWND_DESKTOP,
NULL,
HThisInstance,
NULL
);
ShowWindow (hwnd, nFunsterStil );
While (GetMessage (& messages, NULL, 0, 0 )){
TranslateMessage (& messages );
DispatchMessage (& messages );
}
Return messages. wParam;
}
Lresult callback WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
Switch (message ){
Case WM_PAINT:
Hdc = BeginPaint (hwnd, & ps );
HPEN green_pen = CreatePen (PS_SOLID, 1, RGB (0,127, 0 ));
HPEN old_pen = (HPEN) SelectObject (hdc, green_pen );
Draw (hdc );
SelectObject (hdc, old_pen );
DeleteObject (green_pen );
EndPaint (hwnd, & ps );
Break;
Case WM_DESTROY:
PostQuitMessage (0 );
Break;
Default:
Return DefWindowProc (hwnd, message, wParam, lParam );
}
Return 0;
}
Void draw (HDC hdc)
{
// Q quantity
Const int const_q= 1000;
Double q [const_q];
Double x, y;
// The maximum number in q
Double greatest;
// The minimum number in q
Double least;
// Initialize the random number generator
Srand (time (0 ));
// Generate q
For (int I = 0; I <const_q; I ++ ){
Q [I] = rand () % 300 + 100;
}
// Find the maximum and minimum numbers in q.
Greatest = q [0];
Least = q [0];
For (int I = 1; I <const_q; I ++ ){
If (greatest <q [I]) {
Greatest = q [I];
}
If (least> q [I]) {
Least = q [I];
}
}
// Draw a straight line representing the maximum number
MoveToEx (hdc,-100*4 + 450, (int)-greatest + 600, 0 );
LineTo (hdc, 100*4 + 450, (int)-greatest + 600 );
// Draw a straight line representing the minimum number
MoveToEx (hdc,-100*4 + 450, (int)-least + 600, 0 );
LineTo (hdc, 100*4 + 450, (int)-least + 600 );
// Draw x in sequence to get-100,-99 ,...... ,-1 point
For (int I =-100; I <0; I ++ ){
X = I;
Y = 0;
For (int j = 0; j <const_q; j ++ ){
Y + = pow (q [j], x );
}
Y/= const_q;
Y = pow (y, 1/x );
Ellipse (hdc, (int) x * 4 + 450-2, (int)-y + 600-2, (int) x * 4 + 450 + 2, (int) -y + 600 + 2 );
}
// Draw the point when x is 0.
Y = 1;
For (int I = 0; I <const_q; I ++ ){
Y * = pow (q [I], (double) 1/const_q );
}
Ellipse (hdc, (int) 450-4, (int)-y + 600-4, (int) 450 + 4, (int)-y + 600 + 4 );
// Draw x in sequence to get 1, 2 ,...... , 99 o'clock
For (int I = 1; I <100; I ++ ){
X = I;
Y = 0;
For (int j = 0; j <const_q; j ++ ){
Y + = pow (q [j], x );
}
Y/= const_q;
Y = pow (y, 1/x );
Ellipse (hdc, (int) x * 4 + 450-2, (int)-y + 600-2, (int) x * 4 + 450 + 2, (int) -y + 600 + 2 );
}
}