
百图 【程序1】 题目:西图,学用circle画圆形. 1.程序分析: 2程序源代码: /wcircle*/ 年include”graphics.h main( [int driver,node,1: float j=l,k=l; driver=VGA:node=WGAHI: initgraph(Adriver,&node,"") setbkcolor (YELLOW) for(i-0:i(-25:it+) setcolor(8): circ1e310.250.k): k-k+j出 =+0.3 / 【程序2】 愿目:画图,学用1ie画直线, 1.程序分析: 2程序潭代码 #include graphics.h" main() [int driver.node,i: float x0.y0,yl,xl;
画图 【程序 1】 题目:画图,学用 circle 画圆形。 1.程序分析: 2.程序源代码: /*circle*/ #include "graphics.h" main() {int driver,mode,i; float j=1,k=1; driver=VGA;mode=VGAHI; initgraph(&driver,&mode,""); setbkcolor(YELLOW); for(i=0;i<=25;i++) { setcolor(8); circle(310,250,k); k=k+j; j=j+0.3; } } 【程序 2】 题目:画图,学用 line 画直线。 1.程序分析: 2.程序源代码: #include "graphics.h" main() {int driver,mode,i; float x0,y0,y1,x1;

float j=12,k: driver"VGA;node=VGAHI: initgraph (driver,&mode,""): setbkcolor (GREEN) 0-263:0-263:y1-275:x1-275: for(1=0:1(=18:1++) setcolor(5): 1ine(x0,y0,x0,y1): 0=x0-5: 0-y0-5 x1=x1+5 y1=y1+5 jj+10: 0=263:y1=275:0=263 for(1=0:1(=20:1++) setcolor(5): line(x0.y0.x0.yl) 0=x0+5: 0-y0+5: y1=y1-5: 1 【程序3】 题目:商图,学用rectangle商方形。 1.程序分析:利用for循环控制100-9的个数,每个量分解出个位,十位,百位. 2程序源代码: +include”graphics..h
float j=12,k; driver=VGA;mode=VGAHI; initgraph(&driver,&mode,""); setbkcolor(GREEN); x0=263;y0=263;y1=275;x1=275; for(i=0;i<=18;i++) { setcolor(5); line(x0,y0,x0,y1); x0=x0-5; y0=y0-5; x1=x1+5; y1=y1+5; j=j+10; } x0=263;y1=275;y0=263; for(i=0;i<=20;i++) { setcolor(5); line(x0,y0,x0,y1); x0=x0+5; y0=y0+5; y1=y1-5; } } 【程序 3】 题目:画图,学用 rectangle 画方形。 1.程序分析:利用 for 循环控制 100-999 个数,每个数分解出个位,十位,百位。 2.程序源代码: #include "graphics.h

main( [int x0.y0,yl,xl,driver,node,i: driverVGA:node"VGAHI: initgraph级driver,Anode,"门: setbkcolor (YELLO) 0-263:0-263:y1-275:x1-275: for(i=0:1=18:i4+) setcolor(1): rectangle(x0.y0,xI.yl): 0=x0-5: 0-y0-5: x1-x1+5: y1=y1+5: 1 settextstyle(DEFAULT_FONT.BORIZ_DIR,2): outtextxy(150,40,"How beautiful it is!): 1inc(130,60.480,600: setcolor(2): circ1e28,29,137): 【程序4】 愿目:面图,综合例子。 1.程序分析: 2程序源代码 年define PAl314l5g25 年define B0.&0g ÷include“aphics..h #include”math.h msin()
main() {int x0,y0,y1,x1,driver,mode,i; driver=VGA;mode=VGAHI; initgraph(&driver,&mode,""); setbkcolor(YELLOW); x0=263;y0=263;y1=275;x1=275; for(i=0;i<=18;i++) { setcolor(1); rectangle(x0,y0,x1,y1); x0=x0-5; y0=y0-5; x1=x1+5; y1=y1+5; } settextstyle(DEFAULT_FONT,HORIZ_DIR,2); outtextxy(150,40,"How beautiful it is!"); line(130,60,480,60); setcolor(2); circle(269,269,137); } 【程序 4】 题目:画图,综合例子。 1.程序分析: 2.程序源代码: # define PAI 3.1415926 # define B 0.809 # include "graphics.h" #include "math.h" main()

int i.j.k,x0,y0,x.y.driver,mode: float a: driver=CGA:node=CGACD: initgragh(&driver,&node,"") setcolor(3): setbkcolor (GREEN): x0-150:0-100: cirele(xo,y0,10): circle(x0.y0.20): circle(x0,y0.50): for(1=0:i18:i+ a-(2P41/16)i: x=cell(x0+48*cos(a)): y=ceil(y0+48*sin(a)*B) setcolor (2):line(x0,y0,x.y): setcolor(3):circle(x0.y0.60): /Make 0 tine normal size letters * settextstyle(DEFAULT_FONT.BORIZ_DIR,0): outtextxy(10.170."press a key) zetch(): setfillstyle (HATCH_FILL,YELLOW): f1 oodfi11(202.100,HTE): getch(): fark=0:k(=500:k+) setcolor(3): far(i=0:1<=16:1+)
{ int i,j,k,x0,y0,x,y,driver,mode; float a; driver=CGA;mode=CGAC0; initgraph(&driver,&mode,""); setcolor(3); setbkcolor(GREEN); x0=150;y0=100; circle(x0,y0,10); circle(x0,y0,20); circle(x0,y0,50); for(i=0;i<16;i++) { a=(2*PAI/16)*i; x=ceil(x0+48*cos(a)); y=ceil(y0+48*sin(a)*B); setcolor(2); line(x0,y0,x,y);} setcolor(3);circle(x0,y0,60); /* Make 0 time normal size letters */ settextstyle(DEFAULT_FONT,HORIZ_DIR,0); outtextxy(10,170,"press a key"); getch(); setfillstyle(HATCH_FILL,YELLOW); floodfill(202,100,WHITE); getch(); for(k=0;k<=500;k++) { setcolor(3); for(i=0;i<=16;i++) {

a=2*PAI/16)*1+(2*AI/180)k: xmceil(x0+48*cos(a)) y=ceil(y0+48+sin(a)*B) setcolor(2):line(x0,y0,x.y): for(j=1:JK=0:+) a=2*PAI/16)◆i+(2PAI/180)*k-1: x=℃ei1(x0+48*e0sa): y=ceil(y0+48*sin(a)*B): line(x0.y0.x.y) 1 restorecrtmode(): 【程序5】 题目:蓝图,筹合例子, 1.程序分析: 2程序源代码 年include"graphics.h” #define LEFT 0 define TOP 0 #define RIGHIT 639 define BOTTOM 479 sdefine LINES 400 年define MAXC0R15 main() int driver,node,error: int xl.y1日
a=(2*PAI/16)*i+(2*PAI/180)*k; x=ceil(x0+48*cos(a)); y=ceil(y0+48+sin(a)*B); setcolor(2); line(x0,y0,x,y); } for(j=1;j<=50;j++) { a=(2*PAI/16)*i+(2*PAI/180)*k-1; x=ceil(x0+48*cos(a)); y=ceil(y0+48*sin(a)*B); line(x0,y0,x,y); } } restorecrtmode(); } 【程序 5】 题目:画图,综合例子。 1.程序分析: 2.程序源代码: #include "graphics.h" #define LEFT 0 #define TOP 0 #define RIGHT 639 #define BOTTOM 479 #define LINES 400 #define MAXCOLOR 15 main() { int driver,mode,error; int x1,y1;

int x2.y2: int dxl,dyl,dx2.dy2.i=1: int count-0; int color-0: driver=VGA: pode"VGAHI: initgraph(&driver,&node,""): x1=x2=y1=y2=10 dxl-dy1-2; d2-dy2-3: while(!kbhit() line (xl,yl.x2.y2) x1+1:y1+ey1: x2+=d2:y2+d2: if(xI-RIGHT) dxl--dxl; if(y1-BOTTOM) dyl=-dyl; if(x2K=LEFTx2>=RIGHT) dx2-dx2; if(y2K=TOPly2>=B0TTOM) dy2--dy2; if(++count>LINES) setcolor(color): color=(color>=MACOLOR)20:+tcolar; 1 closegraph():
int x2,y2; int dx1,dy1,dx2,dy2,i=1; int count=0; int color=0; driver=VGA; mode=VGAHI; initgraph(&driver,&mode,""); x1=x2=y1=y2=10; dx1=dy1=2; dx2=dy2=3; while(!kbhit()) { line(x1,y1,x2,y2); x1+=dx1;y1+=dy1; x2+=dx2;y2+dy2; if(x1=RIGHT) dx1=-dx1; if(y1=BOTTOM) dy1=-dy1; if(x2=RIGHT) dx2=-dx2; if(y2=BOTTOM) dy2=-dy2; if(++count>LINES) { setcolor(color); color=(color>=MAXCOLOR)?0:++color; } } closegraph();

【程序6】 题目,学习putpixel面点。 1.程序分析: 2程序源代码: #include stdio.h" 年include"graphics..h” main() int i,j.driver"VGA.node-VGAHI; initgraph(&driver,&mode,""): setbkcolor (YELLW) far(i-50:i-230:it-20) for(j=50:jK=230:j+) putpixel(i,j.1): for(0=0:jK=220:j+=200 for(i-50:i-230:i+) putpixel(i,j.1): 【程序7】 题目,香桶圆el1ise 1.程序分析: 2程序源代码: #include "stdio.h" 年inelude"graphics.h sinclude "conio.h" min()
} 【程序 6】 题目:学习 putpixel 画点。 1.程序分析: 2.程序源代码: #include "stdio.h" #include "graphics.h" main() { int i,j,driver=VGA,mode=VGAHI; initgraph(&driver,&mode,""); setbkcolor(YELLOW); for(i=50;i<=230;i+=20) for(j=50;j<=230;j++) putpixel(i,j,1); for(j=50;j<=230;j+=20) for(i=50;i<=230;i++) putpixel(i,j,1); } 【程序 7】 题目:画椭圆 ellipse 1.程序分析: 2.程序源代码: #include "stdio.h" #include "graphics.h" #include "conio.h" main() {

int x=360,y=160,driver=VGA.mode=VGAHI: int num-20,i; int top,bottom: initgragh(&driver,&node,""): top-y-30: bottom=y-30; for(i=0:i[ ellipse(250,250,0.360.top,bottom) top-=5: bot10+=5 zetch(: 1 【程序8】 恶目:利用ellipse and rectangle面图. 1,程序分析: 2程序源代码: =include”stdio.h" #include "graphics.h" #include "conio.h" nain() int driver"VGA,mode"VGAHI; int i,num=15,top=50: int left-20,right=50: initgraph(&driver,&mode,""): for(i=0:i[ e11ipse250.250,0.360.right.1eft): e111pse250,250,0,380,20,t03):
int x=360,y=160,driver=VGA,mode=VGAHI; int num=20,i; int top,bottom; initgraph(&driver,&mode,""); top=y-30; bottom=y-30; for(i=0;i{ ellipse(250,250,0,360,top,bottom); top-=5; bottom+=5; } getch(); } 【程序 8】 题目:利用 ellipse and rectangle 画图。 1.程序分析: 2.程序源代码: #include "stdio.h" #include "graphics.h" #include "conio.h" main() { int driver=VGA,mode=VGAHI; int i,num=15,top=50; int left=20,right=50; initgraph(&driver,&mode,""); for(i=0;i{ ellipse(250,250,0,360,right,left); ellipse(250,250,0,360,20,top);

rectangle20-2i,20-2*i,10m(i+2).10*(i+2): right+=5: leftt5: topt=10: 1 getch(: 1 【程序9】 题目:一个最优美的图案, 1,程序分析: 2程序源代码: 年include”graphics..h” 年include”math.h" 年include "'dos.h 年include"conio.h include "stdlib.h" =include“stdio.h° 年include"stdarg..h #define MAXPTS 15 #define PI 3.1415926 struct PTS int x.Y: : double AspectRatio=0.85: void LineToDeno(void) struct viewporttype vp: struct PTS points [MAUPTS]: int i,j.h,v.xcenter,ycenter;
rectangle(20-2*i,20-2*i,10*(i+2),10*(i+2)); right+=5; left+=5; top+=10; } getch(); } 【程序 9】 题目:一个最优美的图案。 1.程序分析: 2.程序源代码: #include "graphics.h" #include "math.h" #include "dos.h" #include "conio.h" #include "stdlib.h" #include "stdio.h" #include "stdarg.h" #define MAXPTS 15 #define PI 3.1415926 struct PTS { int x,y; }; double AspectRatio=0.85; void LineToDemo(void) { struct viewporttype vp; struct PTS points[MAXPTS]; int i, j, h, w, xcenter, ycenter;

int radius,angle,step: double rads; printf("MoveTo LineTo Demonstration") xetviewsettings(&vp ) h=vp.botton vp.top: g=vn.right-vp,left日 xcenter "w/2:Deternine the center of circle/ ycenter h /2: radius=(h-30)/4 spectRatio多2): step=360/MPT5:/体etermine#of increrents◆/ angle =0:/Begin at xero degrees for i=0 frads (double)angle PI 180.0:/Convert angle to radians * points[i].x xcenter (int)(cos(rads)*radius ) points[i].y ycenter -(int)(sin(rads)*radius AspectRatio ) angle +step:/Move to next inerement * 1 circle(xcenter,ycemter,radius )/Draw bounding cirele * for i=0:ifor(j=i jnoweto(points[i].x.points[i].y):/Move to beginning of cord/ lineto(points[j].x.points[j].y):Draw the cord 11 main( Hint driver,node: driver=CGA:node=CGACO: initgraph(後driver,Aode,“): setcolor(3): setbkcolor (GEEN): LineToDemo(0:】
int radius, angle, step; double rads; printf(" MoveTo / LineTo Demonstration" ); getviewsettings( &vp ); h = vp.bottom - vp.top; w = vp.right - vp.left; xcenter = w / 2; /* Determine the center of circle */ ycenter = h / 2; radius = (h - 30) / (AspectRatio * 2); step = 360 / MAXPTS; /* Determine # of increments */ angle = 0; /* Begin at zero degrees */ for( i=0 ; irads = (double)angle * PI / 180.0; /* Convert angle to radians */ points[i].x = xcenter + (int)( cos(rads) * radius ); points[i].y = ycenter - (int)( sin(rads) * radius * AspectRatio ); angle += step; /* Move to next increment */ } circle( xcenter, ycenter, radius ); /* Draw bounding circle */ for( i=0 ; ifor( j=i ; jmoveto(points[i].x, points[i].y); /* Move to beginning of cord */ lineto(points[j].x, points[j].y); /* Draw the cord */ } } } main() {int driver,mode; driver=CGA;mode=CGAC0; initgraph(&driver,&mode,""); setcolor(3); setbkcolor(GREEN); LineToDemo();}