| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 381 人关注过本帖
标题:新手上路之小球弹框框
只看楼主 加入收藏
小小少侠
Rank: 2
等 级:论坛游民
帖 子:19
专家分:12
注 册:2015-3-6
结帖率:25%
收藏
 问题点数:0 回复次数:1 
新手上路之小球弹框框
# include <graphics.h>
# include <conio.h>
# include <stdlib.h>
# include <math.h>
# include <stdio.h>
int main()
{
    int k;//k-表示运动路径
    int x0, y0;//(x0,y0)当前路径的始发点
    int x1, y1;//(x1,y1)当前路径的终止点
    int x00,y00;//(x00,y00)上一路径的始发点
    int x11,y11;//(x11,y11)一一路径的终止点
    int b;//x轴上的截距
    int kk;
    int x, y;//画圆用
    for (k=1;k<=100;k++)
    {
        if (k%2==0)  
            kk = -1;
        else  
            kk = 1;
        /*-----------------*/
        //将上一步的起始点保存到x00,y00,x11,y11里
        if (k==1)
        {
            x00 = 50;y00 = 50;
            x11 = 60;y11 = 60;
        }
        else
        {
            x00 = x0;y00 = y0;
            x11 = x1;y11 = y1;
        }
        /*-----------------*/
        //k==2时,将上一路径的终点
        //作为当前路径的起点
        if (k==1)
        {
            x0 = 50;y0 = 50;
        }
        else
        {
            x0 = x1;y0 = y1;
        }
        /*-----------------*/
        //判断当前步前进方向
        if (x11>x00)
        {
            /*-----------------*/
            //50<x1<589当前路径走向右边
            if (x11>50 && x11<589) goto a11;
            //x1==589当前路径走向左边
            if (x11==589) goto a12;
            /*-----------------*/
        }
        if (x11<x00)
        {
            /*-----------------*/
            //50<x1<589当前路径走向左边
            if (x11>50 && x11<589) goto a12;
            //x1==0当前路径走向右边
            if (x11==0) goto a11;
        }
        /*-----------------*/
a11:;//当前步走向右边,求当前步的接触点
        b = y0-kk*x0;//先通过y=kk*x+b求b
        x1 = 589;//令x1=589
        y1 = kk*x1+b;//求y1
        if (y1>=429)
        {
            y1 = 429;x1 = (y1-b)/kk;
        }
        if (y1>50 && y1<429)
        {
            x1 = 589;y1 = kk*x1+b;
        }
        if (y1<=50)
        {
            y1 = 50;x1 = (y1-b)/kk;
        }
        goto a13;
a12:;//当前步走向左边
        b = y0-kk*x0;
        x1 = 50;
        y1 = kk*x1+b;
        if (y1>=429)
        {
            y1 = 429;x1 = (y1-b)/kk;
        }
        if (y1>50 && y1<429)
        {
            x1 = 50;y1 = kk*x1+b;
        }
        if (y1<=50)
        {
            y1 = 50;x1 = (y1-b)/kk;
        }
a13:;//至此求得了当前路径的起始点(x0,y0)和终点(x1,y1)
        initgraph(640,480);
        if (x1>x0)
        {
            
            for (x=x0;x<=x1;x+=1)
            {
                b = y0 - kk*x0;
                y = kk*x+b;
                //画图
                setlinecolor(GREEN);
                setfillcolor(GREEN);
                fillcircle(x,y,50);
                //延时
                Sleep(1);
                //擦图
                setlinecolor(BLACK);
                setfillcolor(BLACK);
                fillcircle(x,y,50);
            }
        }
        if (x1<x0)
        {
            for (x=x0;x>=x1;x-=1)
            {
                b = y0 - kk*x0;
                y = kk*x+b;
                //画图
                setlinecolor(GREEN);
                setfillcolor(GREEN);
                fillcircle(x,y,50);
                //延时
                Sleep(1);
                //擦图
                setlinecolor(BLACK);
                setfillcolor(BLACK);
                fillcircle(x,y,50);
            }
        }
        //printf("路径:%d ",k);
        //printf("起点:%d %d ",x0,y0);
        //printf("终点:%d %d ",x1,y1);
        //printf("\n");
    }
    system("pause");
    return 0;
}
希望对新手有帮助
搜索更多相关主题的帖子: 新手上路 include 
2015-04-17 10:10
小小少侠
Rank: 2
等 级:论坛游民
帖 子:19
专家分:12
注 册:2015-3-6
收藏
得分:0 
2015-04-17 10:13
快速回复:新手上路之小球弹框框
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016927 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved