In this article, we will discuss how to draw a 2D cricket ground is being designed using computer graphics.
Approach:
- Draw a circle using the circle() function. This will act as the Ground Outline.
- Color the above circle with green using the setfillstyle() and floodfill() functions.
- Then to implement 30 yards Outline using the ellipse() function.
- Then implement two Rectangles using the rectangle() function. Between them, one is the outer rectangle and another is the inner rectangle.
- Color the inner rectangle will brown color using the setfillstyle() and floodfill() functions.
- Divide the inner rectangle using the two rectangle() function. Between them, one is the upper stump Line and another is the lower stump line.
- Use two lines to increase the stump line using the line() function.
Below is the program for 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
circle(700, 350, 300);
// Coloring Green
setfillstyle(SOLID_FILL, GREEN);
floodfill(402, 350, 15);
// 30 Yards Outline
ellipse(700, 350, 0, 360, 150, 200);
// Pitch Outer Line
rectangle(675, 265, 725, 435);
// Pitch Inner Line
rectangle(690, 265, 710, 435);
// Coloring Pitch Brown
setfillstyle(SOLID_FILL, BROWN);
floodfill(695, 300, 15);
// Upper Stump Line
rectangle(690, 265, 710, 280);
line(680, 280, 720, 280);
// Lower Stump Line
rectangle(690, 435, 710, 420);
line(680, 420, 720, 420);
// Hold Screen For A While
getch();
// Close the initialized gdriver
closegraph();
} |
Output: