Home » C programs » graphics.h header file functions

setviewport() function of graphics.h in C

In this article, we are going to learn about the setviewport() function of graphics.h header file and use it with different parameters.
Submitted by Manu Jemini, on March 21, 2018

This is a demonstration about how can we restrict someone to use a particular portion of the graphical plane. There is a function called setviewport() from the graphics.h, which allows us to make a rectangle on the plane where the program cannot draw anything.

This is particularly useful in making drawings and complex sketches in C. To use this function we have to pass five parameters which will define the- LEFT, TOP, RIGHT, BOTTOM and CLIP in the function,

This is all you have to do to make a call for this function, You can see that we have used the 50, 50 as the center of the circle which makes it draw outside the rectangle are but also restrict the part which comes inside the area.

graphics.h - setviewport() function in C

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

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

	//calling initgraph with parameters

	//Printing message for user
	outtextxy(50, 50 + 50, "Program to try setviewport in C graphics");

	//declaring variable;
	int middleofx, middleofy;

	//getting middle of x and y
	middleofx = getmaxx()/2;
	middleofy = getmaxy()/2;

	//setting viewport
	setviewport(middleofx - 50, middleofy - 50, middleofx + 50, middleofy + 50, 1);

	//creating circle
	circle(50, 50, 55);


	return 0;


graphics.h - setviewport() function of graphics.h 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.