This blog is under construction

Saturday 14 September 2013

setbkcolor example in c

Header file:
    graphics.h

Synopsis:
      void setbkcolor (int color);
     
Description:
     setbkcolor() sets the current background color.


setbkcolor function in c graphics



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

  int main(void) {
        /* request auto detection */
        int graphicDriver = DETECT, graphicMode;
        int err, i;

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

        /* read result of initialization */
        err = graphresult();

        if (err != grOk) {
                /* error occurred */
                printf("Graphic Error: %s\n",
                                grapherrormsg(err));
                getch();
                return 0;
        }

        /* sets the current drawing color */
        setcolor(10);

        /* text justification and styling */
        settextjustify(CENTER_TEXT, CENTER_TEXT);
        settextstyle(TRIPLEX_FONT, HORIZ_DIR, 20);

        /* write "Jai Hind!!" in the mid of the graphic screen */
        outtextxy(getmaxx() / 2, getmaxy() / 2, "Jai Hind!!");

        /* for centering text on the display */
        for (i = 1; i <= 15; i++) {
                setbkcolor(i);
                delay(700);
        }

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





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


No comments:

Post a Comment