Birthday Gift (待修改)

 Turbo C 2.0是DoS时代优秀的C语言编程工具,但广大用户目前普遗使用的是Windows操作系统,如果想在Windows下调用C语言编写的图形动画程序.可能会出现许多错误,图形动画不能显现出来。因为C的图形图像处理如果在Windows的界面下做.不能准确定位。所以在Turbo C中用initgraph()函数直接进行图形初始化时,还必须完成以下几步:(假设Turbo C 2.0是安装在c:/TC目录下)


①在C:/TC子目录下输入命令:

BGIOBJ EGAVGA.BGI

此命令将驱动程序EGAVGA.BGI转换成EGAVGA.OBJ的目标文件.
因为在编译和链按时并没有将相应的驱动程序(*.BGI)装入到执行程序。

②将上述建立的OBJ文件加入到GRAPHICS.LIB库文件中,具体方法如下。
C:/TC子目录下输入命令:

TLIB c:/tc/lib/GRAPHICS.LIB+EGAVGA

 

/*  Birthday Gift  */

 

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<graphics.h>
#define PI 3.1415926


void Star ( int x, int y)      /* 画星星函数 */
{
    int i, a;
    int n= 5;
    int x1[5],  y1[5],  x2[5],  y2[5];
    setcolor(YELLOW);
    for(i = 0; i < 5; i++)
    {
        x1[i]= x + n * cos(i * 72 * PI / 180);
        y1[i]= y + n * sin(i * 72 * PI / 180);
        x2[i]= x + n / 2 * cos(i * 72 * PI / 180 + PI / 5);
        y2[i]= y + n / 2 * sin(i * 72 * PI / 180 + PI / 5);
    }
    for(i = 0; i < 5; i++)
    {
        a = i+ 1;
        if (a > 4 ) a= 0;
        line(x1[i], y1[i], x2[i], y2[i]); /* 两点间画直线 */
        line(x2[i], y2[i], x1[a], y1[a]);
    }
}


void PutStar()                /* 画繁星函数 */
{
    int seed = 1858;
    int i, dotx, doty, h, w, color, maxcolor;
    maxcolor = getmaxcolor();
    w = getmaxx();
    h = getmaxy();
    srand(seed);
    for( i = 0; i < 100; i++)
    {
        dotx = i + random(w - 1);
        doty = i + random(h - 1);
        color = random(maxcolor);
        setcolor(color);
        putpixel(dotx, doty, color);
        circle(dotx + 1, doty + 1, 1);
    }
    srand(seed);
}

void DrawStar()              /* 把星星和繁星放在天空 */
{
    int a[] = {70, 280, 230, 440, 140, 110, 180, 90, 500, 360};
    int b[] = {50, 27, 88, 99, 100, 37, 67, 98,60,78};
    int i;
    setfillstyle(1, 14);
    for( i = 0; i < 10; i++)
    {
        Star(a[i], b[i]);
        floodfill(a[i], b[i], YELLOW);
    }
    PutStar();
}

void StartFlower()           /* 烟花绽放函数 */
{
    int i = 0, j;
    int n = 60, n1 = 2;
    int x = 200, y = 200, size = 100;
    int cover = 0;
    int delay1 = 5000;
    int wid, hei;
    int px, py;
    int color = 9;
    while(!kbhit())
    {
        if(i < size)
        {
            for( j = 0; j < n; j++ )
            {
                px = x + i * cos(j * 360 / n * PI / 180);
                py = y + i * sin(j * 360 / n * PI / 180);
                putpixel(px, py, rand() % 16);
                putpixel(px - 1, py, color);
                putpixel(px, py + 1, color);
                putpixel(px + 1, py - 1, YELLOW);
                putpixel(px, py - 1, YELLOW);
                putpixel(px + 1, py, RED);
                putpixel(px + 1, py + 1, RED);
            }
        }

        if(i > size && cover < size)
        {
            setcolor(BLACK);
            circle(x, y, cover++);
            delay1 = 1000;
        }

        if( cover == size)
        {
            i = 0;
            x = 50 + rand() % 550;
            y = rand() % 400;
            cover = 0;
            color = rand() % 16;
            size = 50 + rand() % 250;
            delay1 = 10000;
            clearviewport();
            DrawStar();

        }

        i += n1;
        delay(delay1);
    }
}


void main()
{
    int i, j, k;
    int gdriver = DETECT, gmode;
    registerbgidriver(EGAVGA_driver);
    initgraph(&gdriver, &gmode, "");
    DrawStar();

    StartFlower();
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值