#include <iostream>
#include <graphics.h>
DWORD WINAPI drawCircle(LPVOID lpParam)
{
double pi = 3.1415926;
for (int i = 0; i < 800; i++)
{
int x = 200 + 100 * cos(i * pi / 400);
int y = 200 + 100 * sin(i * pi / 400);
putpixel(x, y, RED);
Sleep(10);
}
return 0;
}
DWORD WINAPI drawRectangle(LPVOID lpParam)
{
int x, y;
for (int i = 0; i < 800; i++)
{
if (i < 200)
{
x = 500 + i;
y = 100;
}
else if (i < 400)
{
x = 700;
y = 100 + (i - 200);
}
else if (i < 600)
{
x = 700 - (i - 400);
y = 300;
}
else
{
x = 500;
y = 300 - (i - 600);
}
putpixel(x, y, RED);
Sleep(10);
}
return 0;
}
int main()
{
initgraph(800, 400);
HANDLE hThread[2];
hThread[0] = CreateThread(NULL, 0, drawCircle, NULL, 0, NULL);
hThread[1] = CreateThread(NULL, 0, drawRectangle, NULL, 0, NULL);
WaitForMultipleObjects(2, hThread, TRUE, INFINITE); //等待子线程运行
system("pause");
closegraph(); // 关闭绘图窗口
return 0;
}
(*需要下载相关动画插件EasyX)?
|