Skip to content
Related Articles

Related Articles

Improve Article
C program to design a carrom board using graphics
  • Last Updated : 06 Apr, 2021

In this article, we will discuss how to draw a Carrom Board using Graphics.

Approach:

  • Create the outline of the board using the rectangle() function.
  • Create another smaller rectangle inside the bigger one using the rectangle() function.
  • Create a total of four circles at each corner which will be the pockets of the carrom board by using the circle() function.
  • Color the circles created in the above step with a dark gray color by using two functions setfillstyle() and floodfill() function.
  • All the other parts of the Board will be colored brown using the same functions.
  • Create another circle by using the circle() function that represents the central circle of the board.
  • Color all the remaining circles with a red color by using the same two functions setfillstyle() and floodfill().

Below is the implementation of the above approach:

C




// C program to draw the Carrom Board
// using graphics
  
#include <conio.h>
#include <graphics.h>
#include <stdio.h>
  
// Driver Code
void main()
{
    // Initialize of gdriver with
    // DETECT macros
    int gd = DETECT, gm;
    initgraph(&gd, &gm, "C:\\"
                        "turboc3\\bgi");
    rectangle(200, 100, 600, 500);
  
    // Draw the outer Rectangle
    rectangle(220, 120, 580, 480);
  
    // Draw the inner Rectangle
    circle(240, 140, 20);
  
    // Upper Left Hole
    circle(560, 140, 20);
  
    // Upper Right Hole
    circle(240, 460, 20);
  
    // Lower Left Hole
    circle(560, 460, 20);
  
    // Lower Right Hole
    setfillstyle(SOLID_FILL, BROWN);
    floodfill(300, 170, 15);
    line(300, 170, 500, 170);
  
    // Upper Striker Range Line(Upper)
    line(300, 184, 500, 184);
  
    // Upper Striker Range Line(Lower)
    circle(300, 177, 7);
  
    // Circle Upper Stricker(Left)
    circle(500, 177, 7);
  
    // Circle Upper Stricker(Right)
    line(300, 430, 500, 430);
  
    // Lower Striker Range Line(Upper)
    line(300, 416, 500, 416);
  
    // Lower Striker Range Line(Lower)
    circle(300, 423, 7);
  
    // Circle Lower Stricker(Left)
    circle(500, 423, 7);
  
    // Circle Lower Stricker(Right)
    line(270, 200, 270, 400);
  
    // Left Striker Range Line(Left)
    line(284, 200, 284, 400);
  
    // Left Striker Range Line(Right)
    circle(277, 200, 7);
  
    // Circle Left Stricker(Upper)
    circle(277, 400, 7);
  
    // Circle Left Stricker(Down)
    line(530, 200, 530, 400);
  
    // Right Striker Range Line(Left)
    line(516, 200, 516, 400);
  
    // Right Striker Range Line(Right)
    circle(523, 200, 7);
  
    // Circle Right Stricker(Upper)
    circle(523, 400, 7);
  
    // Circle Right Stricker(Lower)
    line(270, 170, 350, 250);
  
    // Upper Left Tangent Line
    line(530, 170, 450, 250);
  
    // Upper Right Tangent Line
    line(270, 430, 350, 350);
  
    // Lower Left Tangent Line
    line(530, 430, 450, 350);
  
    // Lower Right Tangent Line
    circle(400, 300, 40);
  
    // Central Circle
    circle(400, 300, 15);
  
    // Mini Central Circle
    setfillstyle(SOLID_FILL, RED);
  
    // All Circle Red Coloring
    floodfill(303, 180, 15);
    floodfill(497, 180, 15);
    floodfill(303, 420, 15);
    floodfill(497, 420, 15);
    floodfill(280, 203, 15);
    floodfill(280, 403, 15);
    floodfill(520, 203, 15);
    floodfill(520, 403, 15);
    floodfill(405, 305, 15);
  
    setfillstyle(SOLID_FILL, DARKGRAY);
    floodfill(243, 143, 15);
    floodfill(563, 143, 15);
    floodfill(243, 463, 15);
    floodfill(563, 463, 15);
  
    // Collectively coloring all
    // the shapes created above
    getch();
  
    // Close the initialized gdriver
    closegraph();
}

Output:

Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.



My Personal Notes arrow_drop_up
Recommended Articles
Page :