Home » C programs » graphics.h header file functions

Fill color using putpixel() function of graphics.h in C

In this article, we are going to learn about the putpixel() function of graphics.h header file in C programming language, and use it to filling color inside different areas.
Submitted by Manu Jemini, on March 24, 2018

To put a pixel on the screen at a particular position, calling the putixel() function is a good way. This function takes three parameters as the position of the pixel and also the color of the pixel.

In the example below, we implemented three for loops which will make three squares of different colors, because we have decided the boundaries of the squares as lower and upper limit of the loop.

Every loop has different upper limit and lower limit, with different pixel colors. So, it will look like three different squares of different color, even though these are just pixels.

If we change the limits of loops the squares will also change and we can also change the color of the pixel and color of the square will change.

graphics.h - putpixel() function in C

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

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

	//calling initgraph

	//Printing message for user
	outtextxy(20, 20 + 20, "Program to fill color in different areas using putpixel in C graphics");

	//initilizing the type of variables

	int i,j;

	//loop for first area
			putpixel(j, i, RED);

	//loop of second area
			putpixel(j, i, GREEN);

	//loop of third area
			putpixel(j, i, BLUE);


	return 0;


graphics.h - putpixel() function  in C

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

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

© https://www.includehelp.com some rights reserved.