Home » C programs » graphics.h header file functions

Design a smiley face using graphics.h in C

In this article, we are going to learn about the setcolor (), floodfill(), setfillstyle() and fillellipse() functions of graphics header file and use them to design a smiley face design.
Submitted by Manu Jemini, on March 20, 2018

graphics.h library is frequently used to make graphics in c language. In Graphics making images is the common task. Therefore to know how to make smiley will be useful in the long run.

The First thing is to initiate a graph. This will allow us to make graphics. Second thing is to set the color to yellow. As we want our smiley to be in yellow color.

After that, with the help of circle() function create a circle by passing the parameters for a center with radius. This will allow us to make a circle at our desired location.

Third thing is to fill the circle with yellow color with the help of setfillstyle() and flooddill().

Fourth thing is to make four ellipses with the color black by calling the function fillellipse(). You can see the example below.


graphics.h - Program to design a smiley face 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

	//Printing message for user
	outtextxy(10, 10 + 10, "Program to draw a smiley face in C graphics");

	//setting color to yellow
	//creating circle and fill it with 
	//yellow color using floodfill.
	circle(300, 100, 40);
	setfillstyle(SOLID_FILL, YELLOW);
	floodfill(300, 100, YELLOW);

	//setting color to black
	setfillstyle(SOLID_FILL, BLACK);

	//using fill ellipse and ellipse for creating face.
	fillellipse(310, 85, 2, 6);
	fillellipse(290, 85, 2, 6);

	ellipse(300, 100, 205, 335, 20, 9);
	ellipse(300, 100, 205, 335, 20, 10);
	ellipse(300, 100, 205, 335, 20, 11);

	return 0;	


graphics.h - smiley face program in C


Comments and Discussions




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.