This blog is under construction

Tuesday 10 September 2013

circle example in C

Header file:
    graphics.h

Synopsis:
     void circle (int x, int y, int rad);
     (x, y) - center of the circle
     rad - radius of the circle

Description:
      circle() draws a circle with (x, y) as center and rad as radius.


circle function in c graphics



  #include <graphics.h>
  #include <stdlib.h>
  #include <stdio.h>
  #include <conio.h>
  #include <dos.h>
  int main(void) {
        /* request auto detection */
        int graphicDriver = DETECT, graphicMode;
        int err, i, j = 1, x, y, radius = 200;

        /* initialize graphics and 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;

        for (i = radius; i > 0; i = i - 5) {
                setcolor(j);
                setfillstyle(SOLID_FILL, j);
                /* draw the circle */
                circle(x, y, i);
                floodfill(x, y, j);
                if (j < 15) {
                        j = j + 1;
                } else {
                        j = 1;
                }
                /* sleep for 250 milliseconds */
                delay(250);
        }

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




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


No comments:

Post a Comment