如何在c语言的图形模式中输出数学图形
编程:画出从0—360度角的sin值的变化(在c语言的图形模式下)
如何在c语言的图形模式中输出数学图形
编程:画出从0—360度角的sin值的变化(在c语言的图形模式下)
怎么看的人不少,回的人一个都没啊啊???
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <math.h>
#define PAI 3.1415926
void main()
{
int gdriver=DETECT,gmode,i;
char str1[]="x",str2[]="y",str3[]="0",c=227;
float x1,y1,m,x2,y2;
registerbgidriver(EGAVGA_driver);
initgraph( &gdriver, &gmode,"");
setbkcolor(0);
setcolor(15);
line(150,180,150,360);
line(100,300,400,300);
line(150,180,145,190);
line(150,180,155,190);
line(400,300,390,305);
line(400,300,390,295);
settextstyle(1,0,10);
setcolor(2);
outtextxy(390,310,str1);
outtextxy(130,190,str2);
outtextxy(130,310,str3);
x1=150;
y1=300;
setcolor(4);
for(i=0;i<=360;i++)
{
m=i/360.0*(2*PAI);
x2=150+m*30;
y2=300-sin(m)*30; /*坐标值都放大30倍,不然图太小*/
line(x1,y1,x2,y2);
x1=x2;
y1=y2;
}
setlinestyle(1,0,1);
setcolor(2);
for(i=1;i<=4;i++)
{
m=PAI*i/2;
x2=150+m*30;
y2=300-sin(m)*30;
if(i%2!=0)
line(x2,y2,x2,300);
if(i==1)
outtextxy(x2-7,310,"90");
else if(i==3)
outtextxy(x2-9,290,"270");
else if(i==2)
outtextxy(x2-15,310,"180");
else
outtextxy(x2-10,290,"360");
}
getch();
closegraph();
}
[此贴子已经被作者于2006-2-17 4:25:18编辑过]
我也来发发!这个是我今天晚上做的......做得不好别见怪...
/* ====================== Program Description ====================== */
/* Program Name : sin.cpp */
/* Program Purpose : Imitate The Sine Curve */
/* Environment : TC3.0 */
/* Operating System : Windows XP */
/* Written By Lydolphin. */
/* ================================================================= */
/* ----------------------------------------------------------------- */
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
#include <math.h>
/* ----------------------------------------------------------------- */
#define PATH "D:\\Software\\Programs\\TC3.0\\BGI"
#define PI 3.141592
/* ----------------------------------------------------------------- */
void printXY() ;/* 打印x, y坐标 */
/* ----------------------------------------------------------------- */
void main()
{
int gdriver=DETECT, gmode ;
registerbgidriver(EGAVGA_driver) ;
initgraph(&gdriver, &gmode, PATH) ;
printXY() ;
double y ;
for(int i=0 ; i<=360 ; i++)
{
y=75*sin( (PI/180)*i) ;
putpixel(170+i, 240-y, 15) ;
}
getch() ;
closegraph() ;
}
/* ----------------------------------------------------------------- */
void printXY()
{
int y[6], x[6] ;
y[0]=167 ;
y[1]=44 ;
y[2]=170 ;
y[3]=40 ;
y[4]=173 ;
y[5]=44 ;
x[0]=616 ;
x[1]=237 ;
x[2]=620 ;
x[3]=240 ;
x[4]=616 ;
x[5]=243 ;
drawpoly(3, y) ;
line(170, 40, 170, 440) ;
drawpoly(3, x) ;
line(20, 240, 620, 240) ;
circle(95, 240, 75) ;
}
/* ----------------------------------------------------------------- */
不是不回而是你的问题已经得到很的解决了