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
	initgraph(&graphicdriver,&graphicmode,"c:\\turboc3\\bgi");

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

	//setting color to yellow
	setcolor(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
	setcolor(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);


	getch();
	return 0;	
}

Output

graphics.h - smiley face program in C



Comments and Discussions!

Load comments ↻





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