📜  使用C语言中的图形编程创建Rainbow

📅  最后修改于: 2021-05-26 02:35:04             🧑  作者: Mango

在Turbo C图形中,我们使用graphics.h函数绘制不同的形状(如圆形,矩形等),以不同的格式(不同的字体和颜色)显示文本(任何消息)。通过使用graphics.h,我们可以制作程序,动画以及游戏。这些对于初学者可能很有用。

使用的功能:

  • delay(n): dos.h头文件中的函数负责将程序保留一段时间,具体取决于给定的值n。
  • setcolor(n): graphics.h头文件中的函数,用于设置指针(光标)的颜色。
  • arc(x,y,a1,a2,r): graphics.h头文件中的函数,该函数绘制一个以(x,y)为中心,以(a2-a1)为角度,r为半径的圆弧。

执行:

// A C program to make a rainbow. This program would only
// work in Turbo C compiler in DOS compatible machine
#include
#include
#include
  
// function for making of rainbow
void rainbow()
{
    // auto detection
    int gdriver = DETECT,gmode;
    int x, y, i;
  
    // initialize graphics mode(passed three arguments to
    // initgraph function)
    // &gdriver is the address of gdriver variable, &gmode is
    // the address of gmode and
    //  "C:\\Turboc3\\BGI" is the directory path where BGI files are stored
    initgraph(&gdriver,&gmode,"C:\\Turboc3\\BGI");
  
    x = getmaxx() / 2;//finding centre x-ordinate of screen
    y = getmaxy() / 2;//finding centre y-ordinate of screen
  
    for (i=30; i<200; i++)
    {
        // delay function under dos.h for holding the
        // function for some time
        delay(100);
  
        // selecting  color for making of rainbow
        setcolor(i/10);
  
        // making of arc with fixed centre and increasing radius
        arc(x, y, 0, 180, i-10);
    }
}
// driver program
int main()
{
    rainbow();
    return 0;
}

参考:http://www.xcnotes.com/graphics-in-c-language/draw-rainbow-in-c

想要从精选的最佳视频中学习和练习问题,请查看《基础知识到高级C的C基础课程》。