setaspectratio

setaspectratio用于设置当前缩放因子

函数名:setaspectratio

功能:

函数原型:舟拜杠寻void setaspectratio(

float xasp,

float yasp

);

参数:xasp:x方向上的缩放因子。例如绘制耻夜奔宽度为100的矩形,实耻束立樱际绘制宽度为100*xasp。

yasp:y方向上的缩放因子。夜洒拒例如绘制高度为100的矩形,实际绘制高度为100*yasp。
  

#include <页旬墓graphics.h>

#include <stdlib.h>

#include <stdio.h>

#include <conio.h>

int main(void)

{

/* request auto detection */

int gdriver = DETECT, gmode, errorcode;

int xasp, yasp, midx, midy;

/* initialize graphics and local variables */

initgraph(&gdriver, &gmode, "元浆");

/* read result of initialization */

errorcode = graphresult();

if (errorcode != grOk) /* an error occurred */

{

printf("Graphics error: %s\n", grapherrormsg(errorcode));

printf("Press any key to halt:");

getch();

exit(1); /* terminate with an error code */

}

midx = getmaxx() / 2;

midy = getmaxy() / 2;

setcolor(getmaxcolor());

/* get current aspect ratio settings */

getaspectratio(&愚垫奔xasp, &yasp);

/* draw normal circle */

circle(midx, midy, 100);

getch();

/* claer the screen */

cleardevice();

/* adjust the aspect for a wide circle */

setaspectratio(xasp/2, yasp);

circle(midx, midy, 100);

getch();

/* adjust the aspect for a narrow circle */

cleardevice();

setaspectratio(xasp, yasp/2);

circle(midx, midy, 100);

/* clean up */

getch();

closegraph();

return 0;

}

相关词汇