C program to draw Eiffel Tower using computer graphics
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 draws a rectangle from left(l) to right(r) & from top(t) to bottom(b).
- line(a1, b1, a2, b2): A function from graphics.h header file which draws a line from (a1, b1) point to (a2, b2) point.
- 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 is the location of the ellipse. x_radius and y_radius decide the radius of the 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.
- The first step is to make the left side base of the tower. The left side base is totally built up with a line() function.
- On the left side of the base, construct a total of four lines. These lines are tiled from each other. Then join the left side of the lines with a tangent line and the right side with another tangent line. Also, do interior decoration by joining opposite sides of each base with a line. This full work has to be done by using a line() function.
- The same has to be done with the right side, similar to the one done on the left side. But the difference is that it is required to tilt bases on the opposite side.
- Then join two sides with a line() function.
- The next step is to make a half-circle by using an ellipse() function.
- Implement three rectangles by using a rectangle() function. All these rectangles will be used in decoration functions.
- Among the rectangles, one will be decorated with a continuous triangle which will be implemented by the line() function. These continuous triangle decorations will be done using a while loop.
- Another rectangle will be decorated with vertical lines which are separated by the same distance. These vertical lines are implemented by a line() function in another while loop.
- Steps followed on the lower base again have to be done here as well. The full method is totally the same here also. But here, we have implemented three bases instead of four.
- Join the two sides with a line() function.
- Implement two rectangles using the rectangle() function. Between them, the upper one is to be decorated by some vertical lines placed at the same distance from each other. These lines will be implemented by the line() function in a while loop.
- Make a while loop that will divide the height of the remaining tower and also create some decoration in it in a single while loop. This whole operation will be implemented by the line() function.
- Join the two sides with the line function. Create a rectangle using a rectangle() function on the upper side and a straight line using a line() function.
Below is the implementation of the above approach:
Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.