Skip to content
Related Articles

Related Articles

Improve Article
C program to draw a football ground using computer graphics
  • Last Updated : 04 May, 2021

In this article, we will discuss how to design a 2D football ground using computer graphics.

Approach:

  • At first, create a rectangle using the rectangle() function. This will act as the Ground Outline and draw two lines using the line() function.
  • For coloring the middle part of two lines with White using the setfillstyle() and floodfill() functions.
  • Then draw two circles using the circle() function and also color Middle part with White using setfillstyle() & floodfill() functions.
  • Draw a total of four rectangles using the rectangle() function on the left side.
  • Among them, two will act as the outer outline and two will act as the Inner outline.
  • Then color the middle parts of rectangles with white using the setfillstyle() & floodfill() functions.
  • Draw the two half circles using the arc() function and also color it with white color using setfillstyle() & floodfill() functions.
  • Perform all the above operations on the right side also.

Below is the implementation of the above approach:

C




// C program for the above approach
  
#include <conio.h>
#include <graphics.h>
#include <stdio.h>
  
// Driver Code
void main()
{
    int gd = DETECT, gm;
  
    // Initialize of gdriver with
    // DETECT macros
    initgraph(&gd, &gm, "C:\\turboc3\\bgi");
  
    // Ground Outline
    rectangle(100, 50, 1200, 550);
  
    // Coloring Green
    setfillstyle(SOLID_FILL, GREEN);
    floodfill(150, 150, 15);
  
    // Ground Middle Line
    line(650, 50, 650, 550);
    line(656, 50, 656, 550);
  
    // Coloring White
    setfillstyle(SOLID_FILL, WHITE);
    floodfill(652, 150, 15);
  
    // Mid Circles
    circle(653, 300, 60);
    circle(653, 300, 65);
    circle(653, 300, 10);
  
    // Outer Rectangle Left
    rectangle(100, 200, 250, 400);
    rectangle(100, 205, 245, 395);
  
    // Inner Rectangle Left
    rectangle(100, 230, 200, 370);
    rectangle(100, 235, 195, 365);
  
    // Arc Left Side
    arc(250, 300, 270, 90, 40);
    arc(250, 300, 270, 90, 35);
  
    // Outer Rectangle Right
    rectangle(1200, 200, 1050, 400);
    rectangle(1200, 205, 1055, 395);
  
    // Inner Rectangle Right
    rectangle(1200, 230, 1100, 370);
    rectangle(1200, 235, 1105, 365);
  
    // Arc Right Side
    arc(1051, 300, 90, 270, 40);
    arc(1051, 300, 90, 270, 35);
  
    // Coloring All White
    floodfill(714, 300, 15);
    floodfill(592, 300, 15);
    floodfill(657, 300, 15);
    floodfill(645, 300, 15);
    floodfill(247, 300, 15);
    floodfill(197, 300, 15);
    floodfill(287, 300, 15);
    floodfill(1053, 300, 15);
    floodfill(1103, 300, 15);
    floodfill(1013, 300, 15);
  
    // Holding Screen For a While
    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 :