In Computer Graphics, we use graphics.h which provide direct functions to draw different coordinate shapes(like circle, rectangle etc). By using these functions we can draw different objects like car, hut, trees etc. In this program, the task is to draw a Chess Board using the functions in graphics.
To run the program we have the include the below header file:
Approach: We will create a Chess Board with the help below functions:
- rectangle(left, top, right, bottom): A function from graphics.h header file which is used to draw a rectangle. Coordinates of the left top and right bottom corners are required to draw the rectangle. left specifies the X-coordinate of the top left corner, top specifies the Y-coordinate of the top left corner, right specifies the X-coordinate of the right bottom corner, bottom specifies the Y-coordinate of the right bottom corner.
- delay(): This function is present in library “dos.h” is used for holding the program output for a small period of time since processing is very fast so use it to see the result.
- setcolor(): A function from graphics.h header file which sets the color of the pointer (cursor). There are some predefined colors in computer graphics. Here n is the color number.
- setfillstyle(): A function from graphics.h header file which sets the current fill pattern and fill color.
- floodfill(): A function from graphics.h header file which is used to fill an enclosed area.
Below is the implementation of to draw Chess Board using graphics in C:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Minimum number of moves required to reach the destination by the king in a chess board
- Number of ways to place two queens on a N*N chess-board
- Draw a smiley face using Graphics in C language
- Draw Rectangle in C graphics
- Draw circle in C graphics
- Creating a Rainbow using Graphics Programming in C
- Sierpinski Triangle using Graphics
- Flood fill algorithm using C graphics
- Creating Butterfly themed Fractal in C++ Using Graphics
- How to create a Heart using C Graphics
- C Program to create a House using Graphics
- Draw Switzerland Flag Using Matlab
- Draw Seychelles Flag using MATLAB
- Draw Austria flag using Matlab
- Draw Bangladesh Flag Using Matlab
- Draw Thailand Flag Using MATLAB
- How to add "graphics.h" C/C++ library to gcc compiler in Linux
- bar() function in C graphics
- bar3d() function in C graphics
- Segments in Computer Graphics
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.