-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSnakes_without_head.cpp
More file actions
372 lines (294 loc) · 9.56 KB
/
Snakes_without_head.cpp
File metadata and controls
372 lines (294 loc) · 9.56 KB
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
#include <Windows.h>
#include <assert.h>
#include <objidl.h>
#include <gdiplus.h>
#include <gdiplusgraphics.h>
using namespace Gdiplus;
#pragma comment (lib,"Gdiplus.lib")
#pragma comment(lib, "kernel32.lib")
#pragma comment(lib, "gdi32.lib")
#pragma comment(lib, "user32.lib")
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
WCHAR szTitle[MAX_LOADSTRING]; // The title bar text
WCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
static RECT rcTarget;
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
VOID OnPaint(HDC hdc)
{
Graphics graphics(hdc);
//Snake Body
Point points[] = { Point(100, 50),
Point(150, 150),
Point(100, 250),
Point(150, 350),
Point(100, 450),
Point(150, 550)
};
Point points1[] = {Point(115, 50),
Point(165, 150),
Point(115, 250),
Point(165, 350),
Point(115, 450),
Point(150, 550)
};
//Snake Eye
Point points2[] = { Point(100, 60),
Point(100, 60),
Point(100, 60),
Point(100, 60),
Point(100, 60)
};
Point points3[] = { Point(375, 175),
Point(400, 200),
Point(380, 280),
Point(450, 340),
Point(430, 420)
};
Point points4[] = { Point(385, 164),
Point(415, 200),
Point(395, 280),
Point(465, 340),
Point(430, 420)
};
Point points5[] = { Point(800, 120),
Point(750, 200),
Point(800, 280),
Point(750, 360),
Point(800, 440),
Point(750, 520),
Point(800, 600)
};
Point points6[] = { Point(815, 120),
Point(765, 200),
Point(810, 280),
Point(765, 360),
Point(810, 440),
Point(765, 520),
Point(800, 600)
};
Point points7[] = { Point(400, 400),
Point(350, 480),
Point(380, 500),
Point(290, 550),
Point(350, 600),
Point(270, 650),
};
Point points8[] = { Point(410, 400),
Point(360, 480),
Point(390, 500),
Point(300, 550),
Point(360, 600),
Point(270, 650),
};
Point points9[] = { Point(170, 300),
Point(220, 360),
Point(170, 390),
Point(220, 430),
Point(200, 450),
Point(270, 500),
};
Point points10[] = { Point(185, 300),
Point(235, 360),
Point(185, 390),
Point(235, 430),
Point(215, 450),
Point(270, 500),
};
Point points11[] = { Point(600, 350),
Point(540, 400),
Point(650, 450),
Point(540, 500),
Point(650, 550),
Point(500, 600),
};
Point points12[] = { Point(615, 350),
Point(555, 400),
Point(665, 450),
Point(555, 500),
Point(665, 550),
Point(500, 600),
};
Pen pen(Color(255, 0, 0, 255));
// graphics.DrawCurve(&pen, points, 5, 0.0f);
// graphics.DrawCurve(&pen, points, 5, 0.06);
// Snake Body
graphics.DrawCurve(&pen, points, 6, 0.7f);
graphics.DrawCurve(&pen, points1, 6, 0.7f);
graphics.DrawCurve(&pen, points3, 5, 0.5f);
graphics.DrawCurve(&pen, points4, 5, 0.8f);
graphics.DrawCurve(&pen, points5, 7, 0.8f);
graphics.DrawCurve(&pen, points6, 7, 0.8f);
graphics.DrawCurve(&pen, points7, 6, 0.8f);
graphics.DrawCurve(&pen, points8, 6, 0.8f);
graphics.DrawCurve(&pen, points9, 6, 0.8f);
graphics.DrawCurve(&pen, points10, 6, 0.8f);
graphics.DrawCurve(&pen, points11, 6, 0.8f);
graphics.DrawCurve(&pen, points12, 6, 0.8f);
//Snake Eye
graphics.DrawLine(&pen, 100, 40, 101, 44);
graphics.DrawLine(&pen, 70, 50, 50, 55);
graphics.DrawLine(&pen, 70, 50, 50, 40);
graphics.DrawLine(&pen, 345, 176, 365, 168);
graphics.DrawLine(&pen, 345, 168, 365, 168);
}
VOID DrawArc3(HDC hdc)
{
Graphics graphics(hdc);
// Set up the arc.
Pen pen(Color(255, 0, 0, 255));
REAL x = 750;
REAL y = 120;
REAL width = 30.0f;
REAL height = 30.0f;
REAL startAngle = 150.0f;
REAL sweepAngle = 250.0f;
// Draw the arc.
graphics.DrawArc(&pen, x, y, width, height, startAngle, sweepAngle);
}
VOID DrawArc2(HDC hdc)
{
Graphics graphics(hdc);
// Set up the arc.
Pen pen(Color(255, 0, 0, 255));
REAL x = 360;
REAL y = 162;
REAL width = 38.0f;
REAL height = 15.0f;
REAL startAngle = 115.0f;
REAL sweepAngle = 190.0f;
// Draw the arc.
graphics.DrawArc(&pen, x, y, width, height, startAngle, sweepAngle);
}
VOID DrawArc1(HDC hdc)
{
Graphics graphics(hdc);
// Set up the arc.
Pen pen(Color(255, 0, 0, 255));
REAL x = 65;
REAL y = 37;
REAL width = 80.0f;
REAL height = 20.0f;
REAL startAngle = 115.0f;
REAL sweepAngle = 190.0f;
// Draw the arc.
graphics.DrawArc(&pen, x, y, width, height, startAngle, sweepAngle);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
static TCHAR szClassName[] = TEXT("The Standard Window");
static TCHAR szWindowName[] = TEXT("Sangameshwar window!");
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
HWND hWnd = NULL;
HBRUSH hBrush = NULL;
HCURSOR hCursor = NULL;
HICON hIcon = NULL;
HICON hIconSm = NULL;
WNDCLASSEX wndEx;
MSG msg;
ZeroMemory(&wndEx, sizeof(WNDCLASSEX));
ZeroMemory(&msg, sizeof(MSG));
hBrush = (HBRUSH)GetStockObject(WHITE_BRUSH);
assert(hBrush);
hCursor = LoadCursor(NULL, IDC_ARROW);
assert(hCursor);
hIcon = LoadIcon(NULL, IDI_APPLICATION);
assert(hIcon);
hIconSm = LoadIcon(NULL, IDI_APPLICATION);
assert(hIconSm);
wndEx.cbSize = sizeof(WNDCLASSEX);
wndEx.cbClsExtra = 0;
wndEx.cbWndExtra = 0;
wndEx.hbrBackground = hBrush;
wndEx.hCursor = hCursor;
wndEx.hIcon = hIcon;
wndEx.hIconSm = hIconSm;
wndEx.hInstance = hInstance;
wndEx.lpfnWndProc = WndProc;
wndEx.lpszClassName = szClassName;
wndEx.lpszMenuName = NULL;
wndEx.style = CS_HREDRAW | CS_VREDRAW;
ATOM bRet = RegisterClassEx(&wndEx);
assert(bRet);
hWnd = CreateWindowEx(WS_EX_APPWINDOW, szClassName, szWindowName,
WS_OVERLAPPED | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
assert(hWnd != NULL);
ShowWindow(hWnd, nShowCmd);
UpdateWindow(hWnd);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
// -> Operating. wndEx.lpfnWndProc(lpMsg->hWnd, lpMsg->uMsg, lpMsg->wParam, lpMsg->lParam);
}
return (msg.wParam);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_COMMAND:
{
int wmId = LOWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case 104:
DialogBox(hInst, MAKEINTRESOURCE(103), hWnd, About);
break;
case 105:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
OnPaint(hdc);
// DrawArc1(hdc);
DrawArc2(hdc);
// DrawArc3(hdc);
Ellipse(ps.hdc, rcTarget.left, rcTarget.top,
rcTarget.right, rcTarget.bottom);
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;
}