新聞中心

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

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

        作者: 時間:2016-12-01 來源:網絡 收藏
        #include
        #include
        #include
        #define D 1 //雪花下降速度
        COLORREF snowcolor=0x2711EE; //雪花顏色
        COLORREF snowcolor1=0x0000FF; //積雪顏色
        int FENG; //風向風速值
        int MINX; //屏幕X坐標最大值
        int MINY; //屏幕Y坐標最大值
        ////////////////////////////////////////////////////////////////////////////////
        //獲取屏幕分辨率
        int getXY(int *MINX,int *MINY)
        {
        HDC hdc=GetDC(NULL);
        int t=1;
        int x=600;
        int y=600;
        for(;t;)
        {
        if(GetPixel(hdc,x,100)==CLR_INVALID) t=0;
        x++;
        }
        t=1;
        for(;t;)
        {
        if(GetPixel(hdc,100,y)==CLR_INVALID) t=0;
        y++;
        }
        *MINX=x;
        *MINY=y;
        ReleaseDC(NULL, hdc);
        return 0;
        }
        //雪花點屬性結構體
        struct xue {
        int x; //雪花的當前坐標點
        int y;
        COLORREF oldcolor; //當前雪花點的原始顏色值
        int del; //是否刪除該節點標志值不等于0則刪除此節點
        int nextx; //將要移動到的坐標點
        int nexty;
        int shudu; //下降速度
        };
        //雪花布局鏈表標準節點
        struct xhbiao { //此結構體用于創建雪花的布局鏈表
        struct xue xh;
        struct xhbiao *next; //后繼
        struct xhbiao *quet; //前驅
        };
        //初始化單點雪花
        int huaxue (struct xue *xuehua) //函數功能是初始化一個新的雪花點
        {
        HDC hdc=GetDC(NULL);
        xuehua->y=0;
        xuehua->x=(int)(rand()%MINX);
        xuehua->oldcolor=GetPixel(hdc,xuehua->x,xuehua->y);
        xuehua->shudu=(int)((rand()%10)*D+1);
        xuehua->del=0;
        ReleaseDC(NULL,hdc);
        return 0;
        }
        //創建鏈表
        int link(struct xhbiao **tou,struct xhbiao **wei)
        {
        struct xhbiao *p;
        p=(struct xhbiao*)malloc(sizeof(struct xhbiao));
        huaxue(&p->xh);
        p->next=NULL;
        p->quet=NULL;
        (*tou)=p;
        (*wei)=p;
        return 0;
        }
        //插入節點
        int linkCHA(struct xhbiao **tou,struct xhbiao **wei)
        {
        if((*tou)!=NULL)
        {
        struct xhbiao *p;
        p=(struct xhbiao*)malloc(sizeof(struct xhbiao));
        huaxue(&p->xh);
        p->next=NULL;
        p->quet=(*wei);
        (*wei)->next=p;
        (*wei)=p;
        }
        return 0;
        }
        //刪除節點
        int linkDEL(struct xhbiao *del)
        {
        del->quet->next=del->next;
        del->next->quet=del->quet;
        free(del);
        return 0;
        }
        //維護雪堆鏈表清除需要刪除的雪粒節點
        int linkWUI(struct xhbiao **tou,struct xhbiao **wei)
        {
        struct xhbiao *p;
        p=(*tou);
        for(;p!=NULL;)
        {

        if(p->xh.del!=0)
        {
        if(p==(*tou))
        {
        (*tou)=p->next;
        p->next->quet=NULL;
        free(p);
        }else if(p==(*wei))
        {
        (*wei)=p->quet;
        p->quet->next=NULL;
        free(p);
        }else {
        linkDEL(p);
        }
        }
        p=p->next;
        }
        return 0;
        }
        //物理信息處理

        上一頁 1 2 下一頁

        關鍵詞: 鏈表幕飄雪程

        評論


        技術專區

        關閉
        主站蜘蛛池模板: 柯坪县| 邓州市| 扶沟县| 兴国县| 奉化市| 弥渡县| 宁国市| 临泉县| 安龙县| 兴海县| 深州市| 鱼台县| 郁南县| 平南县| 朝阳区| 密云县| 报价| 景东| 商南县| 中山市| 大埔县| 连城县| 温泉县| 江口县| 安溪县| 房产| 湘乡市| 双城市| 沙田区| 亳州市| 西乌| 会同县| 开化县| 孝昌县| 麻栗坡县| 百色市| 陕西省| 大城县| 五华县| 利川市| 茶陵县|