Open In App

C program to draw Eiffel Tower using computer graphics

Last Updated : 13 Jul, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

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.

Function Used:

  • 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.

Approach:

  • 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:

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");
  
    // Declared Variables
    int a = 390, b = 390, c = 700;
  
    // Left Side
    // Lower Base
    line(300, 1000, 450, 1000);
  
    // Inside Decoration
    line(300, 1000, 480, 940);
    line(450, 1000, 330, 940);
  
    // 1st Base
    line(330, 940, 480, 940);
  
    // Inside Decoration
    line(330, 940, 510, 880);
    line(480, 940, 360, 880);
  
    // 2nd Base
    line(360, 880, 510, 880);
  
    // Inside Decoration
    line(360, 880, 540, 820);
    line(390, 820, 510, 880);
  
    // 3rd Base
    line(390, 820, 540, 820);
  
    // Left Tangent
    line(300, 1000, 390, 820);
  
    // Right Tangent
    line(450, 1000, 540, 820);
  
    // Joining Line
    line(390, 820, 810, 820);
  
    // Half Circle
    ellipse(600, 900, 15, 165, 90, 80);
  
    // Right Side
    // Lower Base
    line(750, 1000, 900, 1000);
  
    // Inside Decoration
    line(750, 1000, 870, 940);
    line(720, 940, 900, 1000);
  
    // 1st Base
    line(720, 940, 870, 940);
  
    // Inside Decoration
    line(720, 940, 840, 880);
    line(870, 940, 690, 880);
  
    // 2nd Base
    line(690, 880, 840, 880);
  
    // Inside Decoration
    line(690, 880, 810, 820);
    line(840, 880, 660, 820);
  
    // 3rd Base
    line(660, 820, 810, 820);
  
    // Left Tangent
    line(750, 1000, 660, 820);
  
    // Right Tangent
    line(900, 1000, 810, 820);
  
    // Rectangles For Decoration
    rectangle(390, 800, 810, 820);
    rectangle(380, 780, 820, 800);
    rectangle(390, 760, 810, 780);
  
    // Triangle Decoration
    while (a <= 790) {
        line(a, 820, a + 10, 800);
        line(a + 10, 800, a + 20, 820);
        a = a + 20;
    }
  
    // Vertical Line Decoration
    while (b <= 810) {
        line(b, 760, b, 780);
        b = b + 20;
    }
  
    // Left Side
    // Upper Base
    line(410, 760, 530, 760);
  
    // Inside Decoration
    line(410, 760, 560, 700);
    line(530, 760, 440, 700);
  
    // 1st Base
    line(440, 700, 560, 700);
  
    // Inside Decoration
    line(440, 700, 590, 640);
    line(560, 700, 470, 640);
  
    // 2nd base
    line(470, 640, 590, 640);
  
    // Left Tangent
    line(410, 760, 470, 640);
  
    // Right Tangent
    line(540, 760, 590, 640);
  
    // Right Side
    // Upper Base
    line(670, 760, 790, 760);
  
    // Inside Decoration
    line(670, 760, 760, 700);
    line(790, 760, 640, 700);
  
    // 1st Base
    line(640, 700, 760, 700);
  
    // Inside Decoration
    line(640, 700, 730, 640);
    line(760, 700, 610, 640);
  
    // 2nd Base
    line(610, 640, 730, 640);
  
    // Left Tangent
    line(670, 760, 610, 640);
  
    // Right Tangent
    line(790, 760, 730, 640);
  
    // Joining Line
    line(470, 640, 730, 640);
  
    // Rectangle For Decoration
    rectangle(460, 620, 740, 640);
    rectangle(470, 600, 730, 620);
  
    // Redeclaring Variable
    b = 470;
  
    // Vertical Line Decoration
    while (b <= 730) {
        line(b, 600, b, 620);
        b = b + 10;
    }
  
    // Redeclaring Variable
    a = 600;
    b = 500;
  
    // Middle Line
    line(600, 600, 600, 140);
  
    // Upper Most Decoration
    while (b >= 240) {
        if (b == c)
            break;
        else {
            line(b, a, c, a);
            line(b, a, c - 10, a - 40);
            line(b + 10, a - 40, c, a);
            a = a - 40;
            b = b + 10;
            c = c - 10;
        }
    }
  
    // Tangent Lines
    line(500, 600, 590, 240);
    line(700, 600, 610, 240);
    rectangle(590, 200, 610, 240);
  
    // Holding The Screen For A While
    getch();
  
    // Close the initialized gdriver
    closegraph();
}


Output:

Eiffel Tower



Similar Reads

Animation of Tower Of Hanoi using computer graphics in C/C++
The task is to design the Tower of Hanoi using computer graphics in C/C++. Tower Of Hanoi: It is a mathematical problem where there are three towers and N numbers of disks. The problem is to move all the disks from the first tower to the third tower with the following rules: Only one disk can be moved at a time and cannot move two or more than two
7 min read
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. Function Used: rectangle(l, t, r, b): A function from graphics.h header file which is used to dr
6 min read
C program to draw a cricket ground using computer graphics
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
2 min read
C program to draw a football ground using computer graphics
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.T
2 min read
C++ program to draw a traffic light simulation using computer graphics
In computers, graphics.h can be used to provide direct functions to draw different coordinates, like circles, rectangles, etc. Using these shapes, different objects can be drawn. This article focuses on how to make a traffic light simulation in Turbo C++. Functions Used: delay(n): It is used to hold the same screen for N milliseconds. As the execut
3 min read
C program to draw a solar system using computer graphics
Prerequisite: Graphics.h, include graphics.h in CodeBlocks Required header files: #include &lt;stdio.h&gt;#include &lt;conio.h&gt;#include &lt;graphics.h&gt;#include &lt;dos.h&gt;#include &lt;math.h&gt; Functions used: getmaxx(): It returns the maximum X coordinate for current graphics mode and driver.setcolor(): It is used to set the current drawi
5 min read
Draw a moving car using computer graphics programming in C
In computer graphics, use graphics.h which provide direct functions to draw different coordinate shapes (like circle, rectangle etc). By using these functions we can draw different objects like car, hut, trees, etc. In this program, we will draw a moving car using line and circles. Functions used in program: delay(n): This function is used for hold
4 min read
Draw a moving cycle using computer graphics programming in C/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 the functions in the header graphics.h, programs, animations, and different games can also be made. In this article, let's discuss how to draw a moving cycle
3 min read
C program to draw the Olympics Logo using graphics
In this article, we will discuss how to design the Olympics Logo using Graphics. Approach:Draw five circles according to positions in the logo using the function circle().To achieve the outline effect, draw 5 smaller circles over it.There is a black circle as well in the logo and to prevent it from blending in, change the background color.Color all
2 min read
C program to draw the Taj Mahal using graphics
In Turbo C graphics the graphics.h functions are used to draw different shapes(like a circle, rectangle, etc), display text(any message) in different formats (different fonts and colors). By using graphics.h programs, animations, and also games can be designed. These can be useful for beginners. Function Used: arc(x, y, start_ang, end_ang, r): A fu
6 min read