新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > 用鏈表實現的屏幕飄雪程序

        用鏈表實現的屏幕飄雪程序

        作者: 時間:2016-12-01 來源:網絡 收藏

        int luoxue(struct xhbiao *tou,struct xhbiao *wei)
        {
        struct xhbiao *p; //處理雪花的物理動作
        p=tou;
        for(;p!=NULL;)
        {
        p->xh.nexty=p->xh.y+p->xh.shudu; //下降
        p->xh.nextx=p->xh.x+FENG; //(風向風速)
        p=p->next;
        }
        return 0;
        }
        //雪堆更新到屏幕
        int xuehuagdi(struct xhbiao *tou,struct xhbiao *wei)
        {
        HDC hdc=GetDC(NULL);
        COLORREF color,color1;
        int R,G,B,RGB;
        struct xhbiao *p1; //顯示雪堆鏈表的數據
        p1=tou;
        for(;p1!=NULL;)
        {
        SetPixel(hdc,p1->xh.x,p1->xh.y,p1->xh.oldcolor);
        if((p1->xh.nexty<=MINY)&&(p1->xh.nextx>=0)&&(p1->xh.nextx<=MINX)) //超出屏幕邊界則刪除節點
        {
        color=GetPixel(hdc,p1->xh.nextx,p1->xh.nexty);
        if(color!=snowcolor) //如果雪點下一個顯示目標點與別的雪點重合則不處理等待維護函數刪除此節點
        {
        color1=GetPixel(hdc,p1->xh.nextx,(p1->xh.nexty-1));
        B=abs((color>>16)&0xff-(color1>>16)&0xff);
        G=abs((color>>8)&0xff-(color1>>8)&0xff);
        R=abs((color)&0xff-(color1)&0xff);
        RGB=(R+G+B)/3; //根據對比度判斷是否堆積雪花
        if(RGB<50){
        p1->xh.oldcolor=color;
        SetPixel(hdc,p1->xh.nextx,p1->xh.nexty,snowcolor);
        p1->xh.x=p1->xh.nextx;
        p1->xh.y=p1->xh.nexty;
        }else if(RGB>50){
        SetPixel(hdc,p1->xh.nextx,(p1->xh.nexty-1),snowcolor1);
        p1->xh.del=1;
        }
        }else if(color==snowcolor){
        p1->xh.del=1;
        }
        } else if((p1->xh.nexty>MINY)||(p1->xh.nextx<0)||(p1->xh.nextx>MINX)){
        p1->xh.del=1;
        SetPixel(hdc,p1->xh.x,p1->xh.y,p1->xh.oldcolor);
        }
        p1=p1->next;
        }
        ReleaseDC(NULL,hdc);
        return 0;
        }
        /////////////////////////////////////////////////////////////////////////////////
        int WINAPI WinMain (HINSTANCE hThisInstance,
        HINSTANCE hPrevInstance,
        LPSTR lpszArgument,
        int nFunsterStil)
        {
        srand(time(NULL));
        struct xhbiao *tou,*p,*wei; //tou為新建表的表頭wei為表尾p為新節點的指針
        tou=NULL;
        wei=NULL;
        FENG=0;
        int i,j,k;
        k=0;
        ////////////////////////////////////////////////////////////////////////////////
        MINY=1100;
        MINX=1300;
        link(&tou,&wei);
        for(i=0;i<=8;)
        {
        for(j=0;j<=k;j++)
        {
        linkCHA(&tou,&wei);
        }
        luoxue(tou,wei);
        xuehuagdi(tou,wei);
        linkWUI(&tou,&wei);
        Sleep(30);
        k=rand()%22;
        }
        return 0;
        }

        上一頁 1 2 下一頁

        關鍵詞: 鏈表幕飄雪程

        評論


        技術專區

        關閉
        主站蜘蛛池模板: 金坛市| 宁德市| 钦州市| 乌苏市| 赤水市| 萨嘎县| 新建县| 河北省| 句容市| 南平市| 江孜县| 潞西市| 珲春市| 林州市| 巧家县| 类乌齐县| 嫩江县| 芜湖县| 麦盖提县| 托里县| 株洲县| 萍乡市| 旬阳县| 正宁县| 合水县| 临沭县| 科尔| 抚州市| 五家渠市| 平顶山市| 舒兰市| 新野县| 蒲江县| 集贤县| 萍乡市| 齐河县| 来凤县| 自贡市| 谷城县| 会泽县| 泸水县|