java能动的风车代码 java编写旋转风车程序

vc中实现所画风车的旋转,我用vc++6.0 cpp画了一个风车 怎么才能让它能旋转起来

//源程序,示例代码:

10年积累的网站制作、成都网站设计经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站制作后付款的网站建设流程,更有韶山免费网站建设让你可以放心的选择与我们合作。

// Instance_3_1_.cpp : Defines the entry point for the application.

//

/*************************************************************************

在窗口中画一个旋转的风车,风车中有三个叶片,颜色分别为红黄和蓝,

叶片外侧有一个外接圆。

*************************************************************************/

#include windows.h

#include math.h

// 回调函数声明

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);

// 初始化窗口类声明

BOOL InitWindowsClass(HINSTANCE hInstance, char *lpszClassName);

// 初始化窗口声明

BOOL InitWindows(HINSTANCE hInstance, int nCmdShow, char *lpszClassName, char *lpTitle);

WNDCLASS wndclass; // 定义一个窗口类

HWND hwnd;         // 定义一个窗口句柄

const double Pi = 3.1415926;

int nMaxNumber = 20; // 叶片循环一周中绘图的次数

int nNum = 0; // 记录当前的顺序

int WINAPI WinMain(HINSTANCE hInstance,

HINSTANCE hPrevInstance,

LPSTR     lpCmdLine,

int       nCmdShow)

{

MSG Msg;                      // 定义消息

char lpszClassName[] = "风车"; // 窗口的类名

char lpTitle[] = "基本绘图-旋转的风车";   // 窗口标题名

// 初始化窗口类

if (!InitWindowsClass(hInstance, lpszClassName))

{

return FALSE;

}

// 初始化窗口

if (!InitWindows(hInstance, nCmdShow, lpszClassName, lpTitle))

{

return FALSE;

}

//消息循环

while(GetMessage(Msg, NULL, 0, 0))

{

TranslateMessage(Msg);

DispatchMessage(Msg);

}

return Msg.wParam; // 程序终止时将信息返回系统

}

// 初始化窗口类定义

BOOL InitWindowsClass(HINSTANCE hInstance, char *lpszClassName)

{

//1、窗口类定义

wndclass.style = 0;             // 窗口类型为默认类型

wndclass.lpfnWndProc = WndProc; // 窗口处理函数为 WNDPROC

wndclass.cbClsExtra = 0;        // 窗口类无扩展

wndclass.cbWndExtra = 0;        // 窗口实例无扩展

wndclass.hInstance = hInstance; // 当前实例句柄

wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); // 窗口的最小化图标为默认图标

wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);   // 窗口采用箭头光标

wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); // 窗口采用白色背景

wndclass.lpszMenuName = NULL; // 窗口中无菜单

wndclass.lpszClassName = lpszClassName; //类名为 lpClassName

//2、注册窗口类

if (!RegisterClass(wndclass))

{ // 如果注册失败则发出警告声音

MessageBeep(0);

return FALSE;

}

return TRUE;

}

// 初始化窗口声明

BOOL InitWindows(HINSTANCE hInstance, int nCmdShow, char *lpszClassName, char *lpTitle)

{

//3、创建窗口

hwnd = CreateWindow(

lpszClassName, 

lpTitle, 

WS_OVERLAPPEDWINDOW,

CW_USEDEFAULT, 

0, 

600, 

450, 

NULL, 

NULL, 

hInstance, 

NULL

);

//4、显示窗口

ShowWindow(hwnd, nCmdShow);

UpdateWindow(hwnd);

return TRUE;

}

// 回调函数定义

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)

{

HDC         hDC;          // 定义设备环境句柄

HPEN        hPen;         // 定义画笔句柄

HBRUSH      hBrush;       // 定义画刷句柄

PAINTSTRUCT PtStr;        // 定义包含绘制信息的结构体变量

POINT       pCenterPoint; // 定义一个圆尽心点的坐标

int         nRadious = 50;// 定义圆的半径

double      fAngle;       // 叶片的直边与水平轴的夹角

switch(message)

{

case WM_PAINT:

{ // 处理绘图消息

hDC = BeginPaint(hwnd, PtStr);        // 得到设备句柄

SetMapMode(hDC, MM_ANISOTROPIC);       // 设置映像模式

SetWindowExtEx(hDC, 400, 300, NULL);   // 设置窗口区域(逻辑单位)

SetViewportExtEx(hDC, 600, 450, NULL); // 设置视口区域(物理单位)

SetViewportOrgEx(hDC, 300, 200, NULL); // 设置视口原点坐标为(300, 200)

// 绘制外圆

hPen = (HPEN)GetStockObject(BLACK_PEN);

SelectObject(hDC, hPen);

Ellipse(hDC, -100, -100, 100, 100);

// 绘制风车的叶片

// 1、画红色叶片

hBrush = CreateSolidBrush(RGB(255, 0, 0)); 

SelectObject(hDC, hBrush);

fAngle = 2 * Pi / nMaxNumber * nNum;

pCenterPoint.x = (int)(nRadious * cos(fAngle));

pCenterPoint.y = (int)(nRadious * sin(fAngle));

Pie(

hDC, 

pCenterPoint.x - nRadious, pCenterPoint.y - nRadious, 

pCenterPoint.x + nRadious, pCenterPoint.y + nRadious, 

(int)(pCenterPoint.x + nRadious * cos(fAngle)),

(int)(pCenterPoint.y + nRadious * sin(fAngle)), 

(int)(pCenterPoint.x + nRadious * cos(fAngle + Pi)), 

(int)(pCenterPoint.y + nRadious * sin(fAngle + Pi))

);

// 2、画天蓝色叶片

hBrush = CreateSolidBrush(RGB(255, 255, 0)); 

SelectObject(hDC, hBrush);

pCenterPoint.x = (int)(nRadious * cos(fAngle + 2 * Pi / 3));

pCenterPoint.y = (int)(nRadious * sin(fAngle + 2 * Pi / 3));

Pie(

hDC, 

pCenterPoint.x - nRadious, pCenterPoint.y - nRadious, 

pCenterPoint.x + nRadious, pCenterPoint.y + nRadious, 

(int)(pCenterPoint.x + nRadious * cos(fAngle + 2 * Pi / 3)), 

(int)(pCenterPoint.y + nRadious * sin(fAngle + 2 * Pi / 3)), 

(int)(pCenterPoint.x + nRadious * cos(fAngle + Pi + 2 * Pi / 3)),

(int)(pCenterPoint.y + nRadious * sin(fAngle + Pi + 2 * Pi / 3))

);

// 2、画黄色叶片

hBrush = CreateSolidBrush(RGB(0, 255, 255)); 

SelectObject(hDC, hBrush);

pCenterPoint.x = (int)(nRadious * cos(fAngle + 4 * Pi / 3));

pCenterPoint.y = (int)(nRadious * sin(fAngle + 4 * Pi / 3));

Pie(

hDC, 

pCenterPoint.x - nRadious, pCenterPoint.y - nRadious, 

pCenterPoint.x + nRadious, pCenterPoint.y + nRadious, 

(int)(pCenterPoint.x + nRadious * cos(fAngle + 4 * Pi / 3)), 

(int)(pCenterPoint.y + nRadious * sin(fAngle + 4 * Pi / 3)), 

(int)(pCenterPoint.x + nRadious * cos(fAngle + Pi + 4 * Pi / 3)),

(int)(pCenterPoint.y + nRadious * sin(fAngle + Pi + 4 * Pi / 3))

);

nNum++; // 当前充数增加1

Sleep(50); //等待0.1秒

InvalidateRect(hwnd, NULL, 1); // 重绘窗口区域

DeleteObject(hPen);

DeleteObject(hBrush);

EndPaint(hwnd, PtStr);

break;

}

case WM_DESTROY:

{

// 调用 PostQuitMessage 发出 WM_QUIT 消息

PostQuitMessage(0);

}

default:

{

return DefWindowProc(hwnd, message, wParam, lParam);

}

}

return 0;

}

直线风车组成的代码

1、首先要打开浏览器。

2、其次在浏览器上方搜索栏输入直线风车组成的代码。

3、最后点击搜索即可。

求)在c#windows应用程序里实现风车转动的(源代码)

你可以拖一个pictureBox1到你的窗体上,设置一个gif图片的路径即可

this.pictureBox1.ImageLocation = @"F:\Download\未命名.gif";

所以你需要找的就是一个篮球gif的图片,就这么简单

分享标题:java能动的风车代码 java编写旋转风车程序
网页链接:https://www.cdcxhl.com/article28/hjjdjp.html

成都网站建设公司_创新互联,为您提供App开发网站设计公司建站公司网站制作网站建设关键词优化

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

绵阳服务器托管