正文

用C绘制正弦函数图2007-03-20 10:19:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/lingdlz/24116.html

分享到:

/*  好久没上博客了,最近在学 STL 和 MFC 他们让我有点手忙脚乱尤其是 MFC ,以前用 C 写界面发好几个小时写出来的也不能令人满意,而用 MFC 发不到一分钟就可以弄出一个大家都熟悉的东西。C 不是用来弄界面的,C是用来写高效程序,是用来写 MFC搞不出来的东西的,我应该这样想。学了一年多的面向过程方法现在忽然要转到面向对象真的有点不自然。本来不想再搞C,一心一意用面向对象解决问题,这学期开了计算机图形学,于是我又弄TC了。象放不下旧情人,我真的放不下C,喜欢她的灵活,喜欢她的指针,外面都是招 JAVA / C++ / C# / .NET …… 一大堆令人眼发撩乱的东西,也许C的时代过去了,不过我放不下,我仍将继续学C,学C更高级的东西,甚至学点汇编,搞混合编程。不为饭碗,不问将来 ,只因为自己喜欢……  欢迎加入 编程爱好者群 : 28011342             AUTHOR : 江南孤峰      以下程序在 TC 下编译,在屏幕上绘制正弦曲线*/#include <stdio.h>#include <math.h>#include <conio.h>#include <graphics.h> void DrawCoordinate(void){    char text[6];  outtextxy(50,50,"Draw math function sin as followed : "); line(100,100,100,380); line(99,100,99,380); sprintf(text,"%c",24); /* 向上的箭头 */ outtextxy(96,100,text); strcpy(text,"y"); outtextxy(86,100,text);  line(5,240,560,240); sprintf(text,"%c",26); /* 向右的箭头 */ outtextxy(560,237,text); strcpy(text,"x"); outtextxy(550,246,text); outtextxy(200,400,"QQ:403324669  Email:lingdlz@163.com");} int main(){ int  gdriver=DETECT,gmode; int  xstart,xend,x,y,color = 0; double d;  printf("Please input start x and end x:"); scanf("%d %d",&xstart,&xend); initgraph(&gdriver, &gmode,""); DrawCoordinate(); /* 绘制坐标系 */ for(x = xstart; x < xend; x ++){  d = sin((double)x/50 - 2.0);  y = 240 - (int)(d*100);  putpixel(x,y,color);  color = (color >= 15 ? 0 : (color+1)); } getch(); closegraph(); return 0;}

阅读(5569) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册