Design a car using pre-defined functions of graphics.h in C

In this article, we are going to learn about the pre-defined functions (rectangle() and circle()) of graphics.h header file in C programming language and use them to create a car design.
Submitted by Manu Jemini, on March 20, 2018

Drawing shapes is an important part of graphics in C. To make shapes, we got different function in graphics.h file. These functions are used to make different shapes which in turn make more complex shapes.

To make a car, we will need to make two rectangle and two circles. The position of the circle should be like that, that they will look like the wheels of the car.

The Rectangles should have there one side overlapped with each other and the bottom co-ordinates must be in line. You can decide the size of the rectangle by yourself.

rectangle() function takes four parameters, which will be used as the four co-ordinates of the rectangle. The circle() function takes three parameters which make the location of the center and the radius of the circle.

These functions are from the graphics.h file and it should be included in the program file.

graphics.h - Program to design a CAR in C

#include <graphics.h>
#include <conio.h>

int main() 
{
	//initilizing graphic driver and 
	//graphic mode variable
	int graphicdriver=DETECT,graphicmode;

	//calling initgraph function with 
	//certain parameters
	initgraph(&graphicdriver,&graphicmode,"c:\\turboc3\\bgi");

	//Printing message for user
	outtextxy(100, 100 + 100, "Program to draw a car with pre-defined functions in C graphics");

	//using pre-defined functions like rectangle and circle.

	rectangle(350,275,250,400);
	rectangle(350,350,400,400);
	circle(350,410,10);
	circle(275,410,10);

	getch();
	return 0;
}

Output

graphics.h - design a car program in C



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.