This blog is under construction

Tuesday, 10 September 2013

ellipse example in C

Header file:
    graphics.h

Synopsis:
     void ellipse (int x, int y, int stangle, int endangle,
                      int xradius, int yradius);
     (x, y) - center of the ellipse
     stangle - starting angle
     endangle - ending angle
     xradius - radius of ellipse at x-axis
     yradius - radius of ellipse at y-axis

Description:
      ellipse() draws an ellipse with given center(x, y), radii and angle.


ellipse function in c graphics



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

  int main(void) {
        /* request auto detection */
        int graphicDriver = DETECT, graphicMode;
        int err, x, y, i, startAngle = 0, endAngle = 360;
        int radX = 280, radY = 230;

        /* initialize graphics, local variables */
        initgraph(&graphicDriver, &graphicMode,
                                        "C:/TURBOC3/BGI");

        /* read result of initialization */
        err = graphresult();
        if (err != grOk) {
                /* an error occurred */
                printf("Graphic Error: %s\n",
                                grapherrormsg(err));
                return 0;
        }

        /* mid position in x and y-axis */
        x = getmaxx() / 2;
        y = getmaxy() / 2;
        setcolor(getmaxcolor());

        for (i = 0; i < 9; i++) {
                /* draw ellipse */
                ellipse(x, y, startAngle, endAngle, radX, radY);
                radX = radX - 20;
                radY = radY - 20;
        }

        setcolor(9);
        setfillstyle(SOLID_FILL, 10);
        circle(x, y, 30);
        floodfill(x, y, 9);

        /* clean up */
        getch();
        closegraph();
        return 0;
  }




Output: (ellipse built-in function in c graphics.h)


No comments:

Post a Comment