用C语言怎样写五角星沿正弦曲线移动,个人基本不会C语言,求高手解答.

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/27 18:03:22
用C语言怎样写五角星沿正弦曲线移动,个人基本不会C语言,求高手解答.
xW{OV*WT&)$Q-$YM Es!.uHJ EemBR:헉׾Ž}8iIې|;^k[v}kΘ[6~CvZX0|0Oojj]}^7ݥ}mzۚqc)648pxSmyGƝ;3m֒×JD b9R,ML4HFQF'"xG4*bU&0IRa4H%ZrfT8ft]@~aNJ#HRAҚy0'HT$gӁx0 QI8Ǵ"H*x-%t `1$iziŹb~3@ "qG lR%%eO R^v7U2 ,:B{\PT3BN E.KyР"C6⹈5VD25*Y":#XVTY A9  T*`eɶ3_]Vl Et4dk}XlTAK6>kneGa,mœ jєl$I\"aŊK&-e6{t`N 1T39ځaKT ,.%24C7C6#ehgK%f ~f% K2O+wlom8 B$ H*hdСRV Yd8]s6N 9θ|yN(3}'V}.$C!~C0($gi% `eQ[,aqk3`Sݞ&ڴ\[DzLΘHwz9_=.}xp<`ڭ:[q Ƽf2v=E@UȱBo{UiUqBC͚?.Jbe~O)jkw'M;ox]0>i9h=KᾶUM+O aV%k#U,4|ŕE>Bxd \ƘBdZJU>_[~uz}rC^QQ1^9wك@_`%8%NDjE-FX~#Fָ"5˛wʫG{/O}0 oߪ=led~tKe:{vXiB% cY|LvsǏ~'*}}˶D&O- }v8cuo'|pGOy

用C语言怎样写五角星沿正弦曲线移动,个人基本不会C语言,求高手解答.
用C语言怎样写五角星沿正弦曲线移动,个人基本不会C语言,求高手解答.

用C语言怎样写五角星沿正弦曲线移动,个人基本不会C语言,求高手解答.
编译环境vc6.0,文件扩展名是cpp.
#include
#include
#include
long WINAPI WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam);
UINT SCREEN_WIDTH = 1000;
UINT SCREEN_HEIGHT = 600;
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
\x05TCHAR className[] = _T("serenesunny");
\x05TCHAR windowName[] = _T("五角星");
\x05WNDCLASS wndcls;
\x05wndcls.cbClsExtra = 0;
\x05wndcls.cbWndExtra = 0;
\x05wndcls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
\x05wndcls.hCursor = LoadCursor(hInstance,IDC_ARROW);
\x05wndcls.hIcon = LoadIcon(hInstance,IDI_APPLICATION);
\x05wndcls.hInstance = hInstance;
\x05wndcls.lpfnWndProc = WndProc;
\x05wndcls.lpszClassName = className;
\x05wndcls.lpszMenuName = 0;
\x05wndcls.style = CS_HREDRAW | CS_VREDRAW;
\x05RegisterClass(&wndcls);
\x05HWND hWnd = CreateWindow(className,windowName,WS_OVERLAPPEDWINDOW,0,
\x05\x050,SCREEN_WIDTH,SCREEN_HEIGHT,0,0,hInstance,0);
\x05ShowWindow(hWnd,SW_SHOWNORMAL);
\x05UpdateWindow(hWnd);
\x05MSG msg;
\x05while (GetMessage(&msg,hWnd,0,0))
\x05{
\x05\x05TranslateMessage(&msg);
\x05\x05DispatchMessage(&msg);
\x05}
\x05return msg.wParam;
}
#define Pi 3.1415926
double n = sin(3 * Pi / (double)10) / sin(Pi / (double)10); // 半径之比
int ti = 0; // 旋转变量
UINT index = 0;
UINT r[] = { (UINT)(n * 20),20 };
float theta[] = {(float)(- Pi / 2),(float)(Pi / (float)5 - Pi / 2)};
POINT points[10];
UINT centerx = 100;
UINT centery = SCREEN_HEIGHT / 2;
long WINAPI WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
\x05HDC hdc;
\x05PAINTSTRUCT ps;
\x05HBRUSH hBrush;
//\x05HPEN hPen;
\x05int i;
\x05int index;
\x05switch(message)
\x05{
\x05case WM_CREATE:
\x05case WM_PAINT:
\x05\x05hdc = BeginPaint(hWnd,&ps);
\x05\x05hBrush = CreateSolidBrush(0x00ffff);
\x05\x05SelectObject(hdc,hBrush);
\x05\x05centerx = 100 + ti;
\x05\x05centery = SCREEN_HEIGHT / 2 - (long)(200 * sin(Pi * ti / (double)300));
\x05\x05for (index = 0; index < 5; index++)
\x05\x05{
\x05\x05\x05for (i = 0; i < 2; i++)
\x05\x05\x05{
\x05\x05\x05\x05points[index * 2 + i].x = (long)(centerx + r[i] * cos(theta[i] + index * 2 * Pi / 5));
\x05\x05\x05\x05points[index * 2 + i].y = (long)(centery + r[i] * sin(theta[i] + index * 2 * Pi / 5));
\x05\x05\x05}\x05
\x05\x05}
\x05\x05Polygon(hdc,points,10); // 把五角星看成一个10边形,用多边形画法去画
\x05\x05DeleteObject(hBrush);
\x05\x05ti += 2;
\x05\x05ti = ti % 600;
\x05\x05Sleep(20);
\x05\x05InvalidateRect(hWnd,NULL,1);\x05//重绘窗口区域.
\x05\x05EndPaint(hWnd,&ps);
\x05\x05break;
\x05case WM_CLOSE:
\x05\x05DestroyWindow(hWnd);
\x05\x05break;
\x05case WM_DESTROY:
\x05\x05PostQuitMessage(0);
\x05\x05break;
\x05default:
\x05\x05return DefWindowProc(hWnd,message,wParam,lParam);
\x05}
\x05return 0;
}
如果出现错误:
LIBCD.lib(crt0.obj) :error LNK2001:unresolved external symbol _main
解决方法:
控制台项目要使用windows子系统,而不是console,设置:
[Project] --> [Settings] --> 选择"Link"属性页,
在Project Options中将/subsystem:console改成/subsystem:windows.