模拟手工画图
MYSGHT
/* 模拟手工画图 MYSGHT.C 程序设计:谢春 1997.4.10.*/
#include"graphics.h" /*调用图形库函数*/
#include"math.h" /*调用数学函数*/
#include"stdio.h" /*调用标准I/O函数*/
#define PI 3.141596 /*宏定义PI字符串*/
main() /*主函数*/
{
float i,x,y; /*定义单精度浮点型变量i,x,y*/
int gdriver=DETECT,gmode,a=1; /*定义整型变量gdriver,gmode*/
initgraph(&gdriver,&gmode,"c:\\tc"); /*定义变量后,初始化图形系统*/
cleardevice();
setbkcolor(a); /*背景颜色*/
printf("\n");
printf(" C 语言图形函数\n");
printf("\n");
printf(" 背景颜色 setbkcolor(int color);\n");
printf(" 画笔颜色 setcolor(int color);\n");
printf(" 画像素点 putpexel(x,y,color);\n");
printf(" 直线函数 line(x1,y1,x2,y2)\n");
printf(" 矩形函数 rectangle(xl,yt,xr,yb)\n");
printf(" 圆弧函数 arc(x,y,as,ae,r)\n");
printf(" 圆形函数 circle(x,y,r)\n");
printf(" 椭圆函数 ellipse(x,y,as,ae,rx,ry)\n");
printf("\n");
printf(" 按任意键开始演示\n");
setcolor(2);
setlinestyle(0,0,3);
rectangle(4,4,635,475); /*绘制矩形框*/
getch();
cleardevice();
printf(" 模拟手工画图\n");
printf(" 函数曲线图形\n");
setcolor(3);
setlinestyle(0,0,3);
rectangle(4,4,635,475); /*绘制图纸边框*/
putpixel(320,240,15); /*绘制中心圆点*/
for (i=0;i<=2*PI;i+=PI/99999)
{
putpixel(40*i,170-21*i*sin(1.6*i),2); /*绘制山峰*/
putpixel(40.3*i,170-22*i*sin(1.6*i),3);
putpixel(40.6*i,170-23*i*sin(1.6*i),10);
}
for (i=0;i<=2*PI;i+=PI/99999) /*绘制花朵*/
{
putpixel(118-15*cos(4*i)*cos(i),160-15*cos(4*i)*sin(i),14);
putpixel(118-25*cos(4*i)*cos(i),160-25*cos(4*i)*sin(i),13);
putpixel(118-35*cos(4*i)*cos(i),160-35*cos(4*i)*sin(i),10);
}
for (i=0;i<=PI;i+=PI/99999)
{
putpixel(320-315*cos(i),360-95*sin(i),11); /*绘制拱桥*/
putpixel(320-315*cos(i),360-96*sin(i),11); /*绘制拱桥*/
putpixel(320-315*cos(i),360-97*sin(i),11); /*绘制拱桥*/
}
for (a=70;a<=570;a+=50)
{
for (i=0;i<=PI;i+=PI/9999)
{
putpixel(a-25*cos(i),360-40*sin(i),11); /*绘制桥孔*/
}
}
for (x=0;x<=640;x+=0.001)
{
putpixel(x,380,9); /*绘制水面线*/
}
for (x=40;x<=600;x+=0.001)
{
putpixel(x,405,9); /*绘制水面线*/
}
for (x=80;x<=560;x+=0.001)
{
putpixel(x,430,9); /*绘制水面线*/
}
for (x=120;x<=520;x+=0.001)
{
putpixel(x,455,9); /*绘制水面线*/
}
setlinestyle(0,0,1);
setfillstyle(1,12);
fillellipse(320,60,25,25); /*绘制太阳*/
for (x=280;x>=250;x-=0.0001)
{
putpixel(x,60,12); /*绘制阳光线*/
}
for (x=360;x>=390;x+=0.0001)
{
putpixel(x,60,12); /*绘制阳光线*/
}
for (y=24;y>=12;y-=0.0001)
{
putpixel(320,y,12); /*绘制阳光线*/
}
for (y=96;y<=108;y+=0.0001)
{
putpixel(320,y,12); /*绘制阳光线*/
}
setlinestyle(3,0,1);
setcolor(12);
for (i=0;i<=2*PI;i+=PI/12) /*绘制阳光线*/
{
line(320+40*cos(i),60-36*sin(i),320+70*cos(i),60-48*sin(i));
for (x=0;x<=55555;x+=0.1)
{
y=y+x; /*延时控制*/
}
}
setcolor(3);
setlinestyle(0,0,1);
rectangle(460,100,620,200); /*绘制地图框(矩形)*/
setcolor(11);
setlinestyle(0,0,3);
ellipse(540,150,0,360,77,48); /*绘制地球(椭圆)*/
setcolor(10);
setlinestyle(0,0,1);
circle(540,150,46); /*绘制经线(圆形)*/
ellipse(540,100,210,330,45,16); /*绘制北极圈(椭圆弧)*/
ellipse(540,200,30,150,45,16); /*绘制南极圈(椭圆弧)*/
setcolor(14);
setlinestyle(3,0,1);
line(460,150,620,150); /*绘制赤道(水平线)*/
line(540,100,540,200); /*绘制经线(垂直线)*/
setcolor(11);
setlinestyle(0,0,1);
for (i=0;i<=2*PI;i+=PI/300)
{
putpixel(590-35*cos(i),50-35*sin(i),11); /*绘制0.1秒刻度*/
}
setcolor(14);
setlinestyle(0,0,1);
circle(590,50,2); /*绘制中心轴*/
setcolor(13);
setlinestyle(0,0,3);
for (i=0;i<=2*PI;i+=PI/6) /*绘制小时刻度*/
{
line(590+25*sin(i),50-25*cos(i),590+30*sin(i),50-30*cos(i));
for (x=0;x<=5555;x+=0.001)
{
y=y+x; /*延时控制*/
}
}
getch();
closegraph();
}