📜  在C图形中绘制椭圆

📅  最后修改于: 2021-05-28 05:17:53             🧑  作者: Mango

程序使用graphics.h头文件在C中绘制椭圆。
graphics.h库用于在程序中包含并促进图形操作。使用graphics.h函数的C图形可用于绘制不同的形状,以不同的字体显示文本,更改颜色等等。使用graphics.h的功能,您可以制作图形程序,动画,项目和游戏。您可以绘制圆,线,矩形,条形图和许多其他几何图形。您可以使用可用功能更改其颜色并填充它们。
例子:

输入:x = 250,y = 200,start_angle = 0,end_angle = 360,x_rad = 100,y_rad = 50输出: 输入:x = 250,y = 200,start_angle = 0,end_angle = 180,x_rad = 80,y_rad = 150输出:

说明:头文件graphics.h包含ellipse()函数,如下所述:

void ellipse(int x,int y,int start_angle,int end_angle,int x_radius,int y_radius)

在此函数, x,y是椭圆的位置。 x_radius和y_radius决定形式x和y的半径。
start_angle是角度的起点,而end_angle是角度的终点。角度值可以在0到360度之间变化。

// C Implementation for drawing ellipse
#include 
  
int main()
{
    // gm is Graphics mode which is a computer display
    // mode that generates image using pixels.
    // DETECT is a macro defined in "graphics.h" header file
    int gd = DETECT, gm;
  
    // location of ellipse
    int x = 250, y = 200;
  
    // here is the starting angle
    // and end angle
    int start_angle = 0;
    int end_angle = 360;
  
    // radius from x axis and y axis
    int x_rad = 100;
    int y_rad = 50;
  
    // initgraph initializes the graphics system
    // by loading a graphics driver from disk
    initgraph(&gd, &gm, "");
  
    // ellipse function
    ellipse(x, y, start_angle,
     end_angle, x_rad, y_rad);
  
    getch();
  
    // closegraph function closes the graphics
    // mode and deallocates all memory allocated
    // by graphics system .
    closegraph();
  
    return 0;
}

输出:

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