Header file:
graphics.h
Synopsis:
void setviewport(int left, int top, int right, int bottom, int clip);
(left, top) - top left corner
(right, bottom) - bottom right corner
clip - If the clip value is non-zero, all drawings will be truncated to current view port
Description:
setviewport() sets a new view port for graphics output.
setviewport function in c graphics
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void) {
/* request auto detection */
int graphicDriver = DETECT, graphicMode;
int err, midx, midy;
/* initialize graphics and local variables */
initgraph(&graphicDriver, &graphicMode, "C:/TURBOC3/BGI");
/* read result of initialization */
err = graphresult();
if (err != grOk) {
/* an error occurred */
printf("Graphic Error: %s\n",
grapherrormsg(err));
getch();
return 0;
}
/* draws a rectangle using current drawing color */
setcolor(9);
setfillstyle(SLASH_FILL, 9);
rectangle(0, 0, 50, 50);
floodfill(1, 1, 9);
/* mid position in x and y axis */
midx = getmaxx() / 2;
midy = getmaxy() / 2;
/* create a smaller viewport */
setviewport(midx - 100, midy - 100,
midx + 100, midy + 100, 1);
/* draws a rectangle using current drawing color */
setcolor(11);
setfillstyle(BKSLASH_FILL, 11);
rectangle(0, 0, 50, 50);
floodfill(1, 1, 11);
/* clean up */
getch();
closegraph();
return 0;
}
Output: (setviewport built-in function in c graphics.h)
No comments:
Post a Comment