Coding

setviewport function in c

setviewport function in c - c programming - setviewport function is used to restrict drawing to a particular portion on the screen. For example setviewport

setviewport function sets the current viewport for graphics output.

Declaration :- void setviewport(int left, int top, int right, int bottom, int clip);

setviewport function is used to restrict drawing to a particular portion on the screen. For example setviewport(100 , 100, 200, 200, 1);
will restrict our drawing activity inside the rectangle(100,100, 200, 200).
left, top, right, bottom are the coordinates of main diagonal of rectangle in which we wish to restrict our drawing. Also note that the point (left, top) becomes the new origin.

C programming source code for setviewport

#include<graphics.h>
#include<conio.h>
 
main()
{
   int gd = DETECT, gm, midx, midy;
 
   initgraph(&gd, &gm, "C:\\TC\\BGI");
 
   midx = getmaxx()/2;
   midy = getmaxy()/2;
 
   setviewport(midx - 50, midy - 50, midx + 50, midy + 50, 1);
   circle(50, 50, 55);
 
   getch();
   closegraph();
   return 0;
}

 

READ  java program - Level Order Tree Traversal

About the author

Wikitechy Editor

Wikitechy Editor

Wikitechy Founder, Author, International Speaker, and Job Consultant. My role as the CEO of Wikitechy, I help businesses build their next generation digital platforms and help with their product innovation and growth strategy. I'm a frequent speaker at tech conferences and events.

X