在C中将椭圆绘制成矩形

时间:2012-11-26 17:03:29

标签: c graphics

以下C代码将绘制一个矩形。我知道如何绘制椭圆,但是如何在这个矩形中绘制一个椭圆?

#include<graphics.h>
#include<conio.h>

main()
{
   int gd = DETECT, gm;

   initgraph(&gd, &gm, "C:\\TC\\BGI");

   rectangle(100,100,200,200);

   getch();
   closegraph();
   return 0;
}

1 个答案:

答案 0 :(得分:1)

假设您使用ellipse中的graphics.h function,则可以执行以下操作:

 int left = 100;
 int right = 200;
 int top = 100;
 int bottom = 200;

 rectangle(left, top, right, bottom);

 int x = (left + right) / 2;  
 int y = (top + bottom) / 2;  
 int start = 0;
 int end = 360;
 int xrad = (right - left) / 2;
 int yrad = (bottom - top) / 2;

 ellipse(x, y, start, end, xrad, yrad);