C graphics using graphics.h functions or WinBGIM (Windows 7) can be used to draw different shapes, display text in different fonts, change colors and many more. Using functions of graphics.h in turbo c compiler you can make graphics programs, animations, projects and games. You can draw circles, lines, rectangles, bars and many other geometrical figures. You can change their colors using the available functions and fill them. Following is a list of functions of graphics.h header file. Every function is discussed with the arguments it needs, its description, possible errors while using that function and a sample c graphics program with its output.

C graphics functions

  • arc
  • bar
  • bar3d
  • circle
  • cleardevice
  • closegraph
  • drawpoly
  • ellipse
  • fillellipse
  • fillpoly
  • floodfill
  • getarccords
  • getbkcolor
  • getcolor
  • getdrivername
  • getimage
  • getmaxcolor
  • getmaxx
  • getmaxy
  • getpixel
  • getx
  • gety
  • graphdefaults
  • grapherrormsg
  • imagesize
  • line
  • lineto
  • linerel
  • moveto
  • moverel
  • outtext
  • outtextxy
  • pieslice
  • putimage
  • putpixel
  • rectangle
  • sector
  • setbkcolor
  • setcolor
  • setfillstyle
  • setlinestyle
  • settextstyle
  • setviewport
  • textheight
  • textwidth
[ad type=”banner”]

C graphics programs

  • Draw shapes
  • Bar chart
  • Pie chart
  • 3d bar chart
  • Smiling face animation
  • captcha
  • Circles in circles
  • Countdown
  • Paint program in c
  • Press me button game
  • Web browser program
  • Traffic Light Simulation
  • Mouse pointer restricted in circle
[ad type=”banner”]

C graphics examples

1.Drawing concentric circles

[pastacode lang=”c” manual=”%23include%20%3Cgraphics.h%3E%0A%20%0Aint%20main()%0A%7B%20%0A%20%20%20int%20gd%20%3D%20DETECT%2C%20gm%3B%0A%20%20%20int%20x%20%3D%20320%2C%20y%20%3D%20240%2C%20radius%3B%0A%20%0A%20%20%20initgraph(%26gd%2C%20%26gm%2C%20%22C%3A%5C%5CTC%5C%5CBGI%22)%3B%0A%20%0A%20%20%20for%20(%20radius%20%3D%2025%3B%20radius%20%3C%3D%20125%20%3B%20radius%20%3D%20radius%20%2B%2020)%0A%20%20%20%20%20%20circle(x%2C%20y%2C%20radius)%3B%0A%20%0A%20%20%20getch()%3B%0A%20%20%20closegraph()%3B%0A%20%20%20return%200%3B%0A%7D” message=”” highlight=”” provider=”manual”/] [ad type=”banner”]

2.C graphics program moving car

[pastacode lang=”c” manual=”%23include%20%3Cgraphics.h%3E%0A%23include%20%3Cdos.h%3E%0A%20%0Aint%20main()%0A%7B%0A%20%20%20int%20i%2C%20j%20%3D%200%2C%20gd%20%3D%20DETECT%2C%20gm%3B%0A%20%0A%20%20%20initgraph(%26gd%2C%26gm%2C%22C%3A%5C%5CTC%5C%5CBGI%22)%3B%0A%20%0A%20%20%20settextstyle(DEFAULT_FONT%2CHORIZ_DIR%2C2)%3B%0A%20%20%20outtextxy(25%2C240%2C%22Press%20any%20key%20to%20view%20the%20moving%20car%22)%3B%0A%20%0A%20%20%20getch()%3B%0A%20%0A%20%20%20for(%20i%20%3D%200%20%3B%20i%20%3C%3D%20420%20%3B%20i%20%3D%20i%20%2B%2010%2C%20j%2B%2B%20)%0A%20%20%20%7B%0A%20%20%20%20%20%20rectangle(50%2Bi%2C275%2C150%2Bi%2C400)%3B%0A%20%20%20%20%20%20rectangle(150%2Bi%2C350%2C200%2Bi%2C400)%3B%0A%20%20%20%20%20%20circle(75%2Bi%2C410%2C10)%3B%0A%20%20%20%20%20%20circle(175%2Bi%2C410%2C10)%3B%0A%20%20%20%20%20%20setcolor(j)%3B%0A%20%20%20%20%20%20delay(100)%3B%0A%20%0A%20%20%20%20%20%20if(%20i%20%3D%3D%20420%20)%0A%20%20%20%20%20%20%20%20%20break%3B%0A%20%20%20%20%20%20if%20(%20j%20%3D%3D%2015%20)%0A%20%20%20%20%20%20%20%20%20j%20%3D%202%3B%0A%20%0A%20%20%20%20%20%20cleardevice()%3B%20%2F%2F%20clear%20screen%0A%20%20%20%7D%0A%20%0A%20%20%20getch()%3B%0A%20%20%20closegraph()%3B%0A%20%20%20return%200%3B%0A%7D” message=”” highlight=”” provider=”manual”/] [ad type=”banner”]

Categorized in: