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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
| #include <windows.h>
#include <conio.h>
#include <iostream>
#include <time.h>
#include <math.h>
#include <WinDef.h>
#define IDR_CEPADMENU 101
#define IDM_NEW 40001
#define IDM_OPEN 40002
#define IDM_SAVE 40003
#define IDM_SAVEAS 40004
#define IDM_EXIT 40005
#define IDM_ABOUT 40006
#define IDM_UNDO 40007
#define IDM_CUT 40008
#define IDM_COPY 40009
#define IDM_PASTE 40010
#define IDM_CLEAR 40011
#define IDM_SELECTALL 40012
#define IDM_FIND 40013
#define IDM_FINDNEXT 40014
#define IDM_REPLACE 40015
#define WMAIN_CLASSNAME "WndClassTestMyName???"
#define WMAIN_CAPTION "WndCaption"
int g_height = 2000, g_width = 2000;
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
srand(time(NULL));
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
const int Nq = 20;
double x,y,x1[Nq],y1[Nq],r,Rad,fi,q[Nq],Ex,Ey,E=0,Q;
int i,j,N_Lines, rad, l, Lx, Ly, flag;
x1[0]=200;
y1[0]=300;
q[0]=1;
x1[1]=800;
y1[1]=300;
q[1]=-5;
rad=1;
l=1;
Lx=1500; //2000 - 30 sec calculation
Ly=1000;
/*Lx = g_width;
Ly = g_height*/;
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Разобрать выбор в меню:
switch (wmId)
{
case IDM_ABOUT:
//DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case WM_LBUTTONDOWN:
double xL,yL;
//HDC hDC;
//hDC=GetDC(hWnd);
xL=LOWORD(lParam); //узнаём координаты
yL=HIWORD(lParam);
x1[0]=xL;
y1[0]=yL;
InvalidateRect(hWnd, NULL, TRUE);
break;
case WM_RBUTTONDOWN:
double xR,yR;
//HDC hDC;
//hDC=GetDC(hWnd);
xR=LOWORD(lParam); //узнаём координаты
yR=HIWORD(lParam);
x1[1]=xR;
y1[1]=yR;
InvalidateRect(hWnd, NULL, TRUE);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: добавьте любой код отрисовки...
time_t start_time;
for (int j = 0; j < Nq; j++)
{
N_Lines=12*fabs(q[j]);
for (i=0; i<=N_Lines; i++)
{
fi=3.141568/6/fabs(q[j])*i;
x=x1[j] + rad*cos(fi);
y=y1[j] + rad*sin(fi);
MoveToEx(hdc, x,y,NULL);
while (x>=0 && x<=Lx && y>=0 && y<=Ly )
{
Ex = Ey = 0;
flag = 0;
for (int k = 0; k < Nq; k++)
{
r = sqrt((x-x1[k])*(x-x1[k])+(y-y1[k])*(y-y1[k]));
double z =0.5;
if ( ((x < x1[k]+1*z)&&(x > x1[k]- 1*z)) && ((y < y1[k]+1*z)&&(y > y1[k] - 1*z)) )
{
flag = 1;
break;
}
Ex+=q[k]*(x-x1[k])/r/r/r;
Ey+=q[k]*(y-y1[k])/r/r/r;
E=sqrt(Ex*Ex+Ey*Ey);
}
if (flag == 0)
{
int sign = 1;
if (q[j] < 0) sign = -1;
x=x+sign*l*Ex/E;
y=y+sign*l*Ey/E;
LineTo(hdc, x, y);
}
else break;
}
}
}
x= 0;
y= 0;
i = 0;
j = 0;
Q=0;
double Rad[10][10];
double P0[10][10];
while ( j < 10){
i=0;
y=0;
while ( i < 10)
{
double potential = 0;
for (int k = 0; k < Nq; k++)
{
r = sqrt((x-x1[k])*(x-x1[k])+(y-y1[k])*(y-y1[k]));
potential += q[k]/r;
Q +=q[k];
Rad[i][j] +=r;
}
P0[i][j] = potential;
y+=Ly/10;
i++;
}
x+=Lx/10;
j++;
}
for (int x = 0; x<= Lx; x++)
{
for (int y = 0; y<= Ly; y++)
{
double phi = 0;
for (int k = 0; k < Nq; k++)
{
r = sqrt((x-x1[k])*(x-x1[k])+(y-y1[k])*(y-y1[k]));
phi += q[k]/r;
}
// код условия рисования линии
i=0;
j=0;
while ( j < 10){
i=0;
while ( i < 10){
if ((phi > P0[i][j] - fabs((0.0000005*P0[i][j]))) && (phi < P0[i][j] +fabs((0.000005*P0[i][j]))))
SetPixel(hdc, x, y, 0x000066FF);
i++;
}
j++;
}
}
}
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// Обработчик сообщений для окна "О программе".
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}
int main(){
FreeConsole();
HINSTANCE hInstance=(HINSTANCE)GetModuleHandle(NULL);
HWND hWnd;
MSG msg;
WNDCLASS wc;
int width,height;
width = 1500;
height = 1000;
g_width = width;
g_height = height;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hIcon=LoadIcon(NULL,IDI_WINLOGO);
wc.hInstance=hInstance;
wc.lpfnWndProc=WndProc;
wc.style=CS_HREDRAW | CS_VREDRAW;
wc.lpszClassName=WMAIN_CLASSNAME;
wc.lpszMenuName=NULL;
if(!RegisterClass(&wc))
return 1;
hWnd=CreateWindow(WMAIN_CLASSNAME,WMAIN_CAPTION,/*WS_OVERLAPPEDWINDOW*/WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX | WS_VISIBLE,CW_USEDEFAULT,CW_USEDEFAULT,width,height,HWND_DESKTOP,NULL,hInstance,0);
if (!hWnd)
return 1;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
} |