桌面下雪程序:#includewindows.h
創(chuàng)新互聯(lián)從2013年成立,先為橋西等服務(wù)建站,橋西等地企業(yè),進行企業(yè)商務(wù)咨詢服務(wù)。為橋西企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
#includetime.h
#includestdlib.h
#includeiostream.hconst int SnowNumber=500; //雪點數(shù)量struct SnowNode
{
POINT postion; //雪點位置
int iColor; //先前的顏色
int iSpeed; //下落速度
int iMove; //下落距離
int iStick; //粘貼度
};SnowNode SnowNodes[SnowNumber]; //雪點數(shù)組
int hTimer=0;
int CrWind=0;
int CrStep=0; //當(dāng)前循環(huán)步數(shù)(用于限速)
int ScreenWidth=0; //屏幕寬度
int ScreenHeight=0; //屏幕高度void GetScreenSize();
void CALLBACK TimerProc(HANDLE hWnd,UINT uMsg,UINT idEvent,DWORD dwTime);
void InitSnowNodes();
void MoveSnowNodes();int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
MSG msg; //標(biāo)準(zhǔn)windows消息
LARGE_INTEGER Frequency; //高性能定時器頻率
LARGE_INTEGER StartCt,EndCt;//高性能定時器計數(shù)
float ElapsedTime; //時間間隔
srand((unsigned)time(NULL));
GetScreenSize();
InitSnowNodes();
QueryPerformanceFrequency(Frequency);
hTimer=SetTimer(0,0,rand()%5*500,(TIMERPROC)TimerProc);
if(hTimer==0)
{
MessageBox(0,TEXT("創(chuàng)建定時器失敗"),TEXT("提示"),MB_OK|MB_ICONINFORMATION);
return -1;
}
RegisterHotKey(0,0,MOD_CONTROL,(int)'L');
while(1)
{
QueryPerformanceCounter(StartCt); //執(zhí)行運算前計數(shù)值
if(PeekMessage(msg,0,0,0,1))
{
switch(msg.message)
{
case WM_TIMER: TimerProc(0,0,0,0);
break; //預(yù)設(shè)風(fēng)向改變時間已到
case WM_HOTKEY: KillTimer(0,hTimer);//刪除隨機風(fēng)向定時 器
UnregisterHotKey(0,0);//刪除退出熱鍵
InvalidateRect(0,NULL,true);
exit(1);
break;
case WM_DISPLAYCHANGE:
GetScreenSize(); //重新取屏幕的尺寸
InitSnowNodes(); //初始化雪點的數(shù)組
break;
}
}
MoveSnowNodes();
QueryPerformanceCounter(EndCt);//執(zhí)行運算后的計數(shù)值
ElapsedTime=(EndCt.QuadPart-StartCt.QuadPart)/Frequency.QuadPart;
if((ElapsedTime0.0005))
Sleep(2); //簡單限速
else if(ElapsedTime0.0010)
Sleep(1);
else if(ElapsedTime0.0015)
Sleep(3);
}
//MessageBox(0,TEXT(“消息“),TEXT(“消息“),MB_OK|MB_ICONINFORMATION);
return 0;
}
void GetScreenSize()
{
ScreenWidth=GetSystemMetrics(SM_CXSCREEN);
ScreenHeight=GetSystemMetrics(SM_CYSCREEN);
return ;
}void CALLBACK TimerProc(HANDLE hWnd,UINT uMsg,UINT idEvent,DWORD dwTime)
{
// MessageBox(0,TEXT(“消息“),TEXT(“消息“),MB_OK|MB_ICONINFORMATION);
srand((unsigned)time(NULL));
if(hTimer==0)
{
MessageBox(0,TEXT("創(chuàng)建定時器失敗"),TEXT("提示"),MB_OK|MB_ICONINFORMATION);
return ;
}
SetTimer(0,hTimer,((rand()%27+4)*500),(TIMERPROC)TimerProc); //// 重設(shè)下次風(fēng)向改變時間
//修改風(fēng)向
if(CrWind!=0)
CrWind=0;
else
CrWind=rand()%3-1;
return ;
}void InitSnowNodes()
{
HDC hScreenDC=0;
int j=0;
hScreenDC=CreateDC("DISPLAY",NULL,NULL,NULL);
if(hScreenDC==NULL)
{
MessageBox(0,"獲取屏幕DC失敗!","信息",MB_OK|MB_ICONERROR);
return ;
}
srand((unsigned)time(NULL));
for(j=0;jSnowNumber;j++)
{
SnowNodes[j].postion.x=rand()%ScreenWidth;
SnowNodes[j].postion.y=rand()%ScreenHeight;
SnowNodes[j].iColor=GetPixel(hScreenDC,SnowNodes[j].postion.x,SnowNodes[j].postion.y);
SnowNodes[j].iSpeed=(rand()%5+1); //每次下落距離(1-5)
SnowNodes[j].iStick=(30-rand()%SnowNodes[j].iSpeed); //粘貼度(幾次循環(huán)作一次粘貼連判斷
// cout〈〈SnowNodes[j].postion.x〈〈“ Y:“〈〈SnowNodes[j].postion.y〈〈endl;
}
DeleteDC(hScreenDC);
}void MoveSnowNodes()
{
// MessageBox(0,TEXT(“消息“),TEXT(“消息“),MB_OK|MB_ICONINFORMATION);
HDC hScreenDC=0;
srand((unsigned)time(NULL));
int x=0,y=0,i=0;
hScreenDC=CreateDC("DISPLAY",NULL,NULL,NULL);
if(hScreenDC==NULL)
{
MessageBox(0,"獲取屏幕DC失敗!","信息",MB_OK|MB_ICONERROR);
return ;
}
// TextOut(hScreenDC,0,0,“雖然大檢查順順藤摸瓜克格勃呀加“,0);
for(i=0;iSnowNumber;i++)
{
//控制雪點下降速度
if((CrStep%SnowNodes[i].iSpeed)!=0)
continue;
//恢復(fù)上次被覆蓋點
if((GetPixel(hScreenDC,SnowNodes[i].postion.x,SnowNodes[i].postion.y))==0XFFFFFF)
SetPixel(hScreenDC,SnowNodes[i].postion.x,SnowNodes[i].postion.y,SnowNodes[i].iColor);
//根據(jù)幾向作隨機飄落
x=SnowNodes[i].postion.x+rand()%3+CrWind;
y=SnowNodes[i].postion.y+SnowNodes[i].iMove;
//積雪(停留)效果處理
if( ( (CrStep%SnowNodes[i].iStick)==0)
( (GetPixel(hScreenDC,x,y))!=(GetPixel(hScreenDC,x,y+1)))
( (GetPixel(hScreenDC,x-1,y))!=(GetPixel(hScreenDC,x-1,y+1)))
( (GetPixel(hScreenDC,x+1,y))!=GetPixel(hScreenDC,x+1,y+1))
)
{
//稍稍調(diào)整坐標(biāo)
if(GetPixel(hScreenDC,x,y-1)==GetPixel(hScreenDC,x,y-2))
{
y--;
}
else
{
if(GetPixel(hScreenDC,x,y-1)==GetPixel(hScreenDC,x,y-2))
y++;
x+=CrWind;
}
//畫三個雪花點
SetPixel(hScreenDC,x,y,0XFFFFFF);
SetPixel(hScreenDC,x+1,y+1,0XFFFFFF);
SetPixel(hScreenDC,x-1,y+1,0XFFFFFF);
//重生雪點
SnowNodes[i].postion.x=rand()%ScreenWidth;
SnowNodes[i].postion.y=rand()%10;
SnowNodes[i].iColor=GetPixel(hScreenDC,SnowNodes[i].postion.x,SnowNodes[i].postion.y);
}
else
{
if( (x0) || (xScreenWidth) || (yScreenHeight))
{
SnowNodes[i].postion.x=(rand()%10);
SnowNodes[i].postion.y=(rand()%ScreenWidth);
SnowNodes[i].iColor=GetPixel(hScreenDC,SnowNodes[i].postion.x,SnowNodes[i].postion.y);
}
else
{
//保存顏色并繪制雪點
SnowNodes[i].iColor=GetPixel(hScreenDC,x,y);
SetPixel(hScreenDC,x,y,0XFFFFFF);
//此時保存新雪點位置
SnowNodes[i].postion.x=x;
SnowNodes[i].postion.y=y;
}
}
}
DeleteDC(hScreenDC);
CrStep++;
}
用GDI繪圖吧,比較簡單。繪圖的思想是讓x以固定的值在區(qū)間內(nèi)持續(xù)增長,比如x=0.1,0.2,0.3.....,以計算出的y值來確定y坐標(biāo)。用線連接所有的點就行了。MoveTo(),LineTo()函數(shù)你用得著,具體情況請自行查看MSDN。
和數(shù)學(xué)上一樣啊 來個坐標(biāo)x,y 分別表示列和行 。在函數(shù)上就打印一個* 給個范圍,雙層循環(huán)加條件就可以了
一) 像素函數(shù)
putpiel() 畫像素點函數(shù)
getpixel()返回像素色函數(shù)
(二) 直線和線型函數(shù)
line() 畫線函數(shù)
lineto() 畫線函數(shù)
linerel() 相對畫線函數(shù)
setlinestyle() 設(shè)置線型函數(shù)
getlinesettings() 獲取線型設(shè)置函數(shù)
setwritemode() 設(shè)置畫線模式函數(shù)
(三)、多邊形函數(shù)
rectangle() 畫矩形函數(shù)
bar() 畫條函數(shù)
bar3d() 畫條塊函數(shù)
drawpoly() 畫多邊形函數(shù)
(四)、 圓、弧和曲線函數(shù)
getaspectratio()獲取縱橫比函數(shù)
circle()畫圓函數(shù)
arc() 畫圓弧函數(shù)
ellipse()畫橢圓弧函數(shù)
fillellipse() 畫橢圓區(qū)函數(shù)
pieslice() 畫扇區(qū)函數(shù)
sector() 畫橢圓扇區(qū)函數(shù)
getarccoords()獲取圓弧坐標(biāo)函數(shù)
(五)、 填充函數(shù)
setfillstyle() 設(shè)置填充圖樣和顏色函數(shù)
setfillpattern() 設(shè)置用戶圖樣函數(shù)
floodfill() 填充閉域函數(shù)
fillpoly() 填充多邊形函數(shù)
getfillsettings() 獲取填充設(shè)置函數(shù)
getfillpattern() 獲取用戶圖樣設(shè)置函數(shù)
(六)、圖像函數(shù)
imagesize() 圖像存儲大小函數(shù)
getimage() 保存圖像函數(shù)
putimage() 輸出圖像函數(shù)
當(dāng)前題目:好玩的函數(shù)圖像c語言 編程函數(shù)圖像
網(wǎng)站地址:http://vcdvsql.cn/article6/doiceog.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計、微信小程序、網(wǎng)站內(nèi)鏈、Google、做網(wǎng)站、商城網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)