简体   繁体   中英

Draw ellipse into rectangle in C

The following C code will draw a rectangle. I know how to draw the ellipse, but how can i draw an ellipse into this rectangle?

#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;
}

Asuming you're using the ellipse function from graphics.h , you could do the following:

 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM