Program to draw India Gate using computer graphics in C
In C graphics, the graphics.h functions are used to draw different shapes like circles, rectangles, etc, display text(any message) in a different format (different fonts and colors). By using graphics.h one can make programs, animations, and also games.
- rectangle(l, t, r, b): A function from graphics.h header file which is used to draw a rectangle from left(l) to right(r) and from top(t) to bottom(b).
- line(a1, b1, a2, b2): A function from graphics.h header file which is used to draw a line from (a1, b1) point to (a2, b2) point.
- circle( a, b, r): A function from graphics.h header file which is used to draw a circle with (a, b) as the center and r as a radius.
- outtextxy(int x, int y, char *string): A function from graphics.h header file by which one can print any statements where, x, y are the coordinates of the point and, the third argument contains the address of the string to be displayed.
- settextstyle(int font, int direction, int font_size): A function from graphics.h header file by which one can create the style of the printable text where the font argument specifies the font of the text. The direction can be HORIZ_DIR (Left to right) or VERT_DIR (Bottom to top).
- ellipse(int x, int y, int start_angle, int end_angle, int x_radius, int y_radius): A function from graphics.h header file where x, y are the location of the ellipse. x_radius and y_radius decide the radius of form x and y. start_angle is the starting point of the angle and end_angle is the ending point of the angle. The value of the angle can vary from 0 to 360 degrees.
- arc(x, y, start_ang, end_ang, r): A function from graphics.h header file which draws an arc with (x, y) as the center, start_ang is its starting angle and end_ang is its ending angle, and r as a radius.
Approach: Follow the steps below to solve this problem:
- First, define the baseline using the line() function.
- Call for the left() function to define and implement decorations on the left side of the India Gate. In the left() function, first, define a rectangle using the rectangle() function that will act as the lower base rectangle and that will be decorated using the line() function. Then implement another rectangle, which is the upper side rectangle, using the rectangle() function. Here, decorate it using a line() and circle() function.
- Call for the right() function to perform the same steps as discussed above for the left side with the changed coordinates.
- Call for the mid() function to implement decoration of the middle part. Here, implement some arcs by using the ellipse() function. Also, use the line() function to make some other decorations also.
- Call for the up() function. Here, implement some rectangles using the rectangle() function. Here, use the while loop to implement continuous lines with a line() function for decoration purposes. Here, implement some different sized rectangles for decorating purposes.
- In the up() function, one makes some decoration in a rectangle with a circle() and line() function. In the middle of the special rectangle which is built with a line() function, write ‘INDIA’ which is generally seen in the real one. Also, two arcs are implemented with the arc() function to make the upper decoration.
Below is the implementation of the above approach: