📄 waves.c
字号:
//**************************************
//INCLUDE files for :Plotting sine, cosine and tangential waveforms
//**************************************
#include<math.h>
#include<stdlib.h>
#include<graphics.h>
#include<conio.h>
//**************************************
// Name: Plotting sine, cosine and tangential waveforms
// Description:This program is part of a larger project; one which involves plotting the curve for any given eqyuation. If someone wants to develop that program jointly with me, or has any useful tip concerning it please email me.
Meanwhile check out this program...
// By: Shahab Faruqi
//
//
// Inputs:None
//
// Returns:None
//
//Assumes:None
//
//Side Effects:None
//This code is copyrighted and has limited warranties.
//Please see http://www.Planet-Source-Code.com/xq/ASP/txtCodeId.2547/lngWId.3/qx/vb/scripts/ShowCode.htm
//for details.
//**************************************
/*
Author: Shahab Faruqi
Dated: 17 September 2001
Description: This program calculates sine, cosine and tangent waveforms.
You can adjust the frequency and amplitude of the waves by
changing the 2 arguments to sinewave(), cosinewave() and
tanwave() functions.
NOTE: Your graphics library must be installed. All *.bgi and
*.chr files must be located in the c:\tc\bgi directory. If
they are situated elsewhere change the location in the
initgraph() function.
Copyright: Public Domain
*/
#include<math.h>
#include<stdlib.h>
#include<graphics.h>
#include<conio.h>
double x=0,sinx,cosx,tanx,multi;
int ay,ax,newx=0,ox,oy,maxx,maxy,midy;
void sinewave(int,int);
void cosinewave(int,int);
void tanwave(int,int);
int distance(double,double);
int distance_tan(double,double);
void sinewave(int xmult,int ymult)
{
x=0;
newx=0;
ox=oy=0;
maxx=getmaxx();
midy=getmaxy()/2;
while(newx<maxx)
{
while(1)
{
if(x>3.142)
break;
sinx=sin(x);
multi=sinx*ymult;
ay=multi;
ax=newx+x*xmult;
moveto(ox,midy-oy);
lineto(ax,midy-ay);
x+=0.01;
ox=ax;
oy=ay;
}
newx=ax;
x=0;
while(1)
{
if(x>3.142)
break;
sinx=sin(x);
multi=sinx*ymult;
ay=multi;
ax=newx+x*xmult;
moveto(ox,midy+oy);
lineto(ax,midy+ay);
x+=0.01;
ox=ax;
oy=ay;
}
newx=ax;
x=0;
}
}
void cosinewave(int xmult,int ymult)
{
x=0;
newx=0;
ox=oy=0;
maxx=getmaxx();
midy=getmaxy()/2;
while(newx<maxx)
{
while(1)
{
if(x>3.14000)
break;
cosx=cos(x);
multi=cosx*ymult;
ay=multi;
ax=newx+x*xmult;
moveto(ox,midy-oy);
if(distance(ax,midy-ay)==0)
lineto(ax,midy-ay);
x+=0.01;
ox=ax;
oy=ay;
}
newx=ax;
x=0;
while(1)
{
if(x>3.1420)
break;
cosx=cos(x);
multi=cosx*ymult;
ay=multi;
ax=newx+x*xmult;
moveto(ox,midy+oy);
if(distance(ax,midy+ay)==0)
lineto(ax,midy+ay);
x+=0.01;
ox=ax;
oy=ay;
}
newx=ax;
x=0;
}
}
void tanwave(int xmult,int ymult)
{
x=0;
newx=0;
ox=oy=0;
maxx=getmaxx();
midy=getmaxy()/2;
while(newx<maxx)
{
while(1)
{
if(x>3.14000)
break;
tanx=tan(x);
multi=tanx*ymult;
ay=multi;
ax=newx+x*xmult;
moveto(ox,midy-oy);
if(distance_tan(ax,midy-ay)==0)
lineto(ax,midy-ay);
x+=0.01;
ox=ax;
oy=ay;
}
newx=ax;
x=0;
while(1)
{
if(x>3.1420)
break;
tanx=tan(x);
multi=tanx*ymult;
ay=multi;
ax=newx+x*xmult;
moveto(ox,midy+oy);
if(distance_tan(ax,midy+ay)==0)
lineto(ax,midy+ay);
x+=0.01;
ox=ax;
oy=ay;
}
newx=ax;
x=0;
}
}
int distance(double x,double y)
{
int xx=getx(),yy=gety();
double r;
x-=xx;
y-=yy;
x*=x;
y*=y;
r=sqrt(x+y);
if(r>1.0)return 1;
else return 0;
}
int distance_tan(double x,double y)
{
int xx=getx(),yy=gety();
double r;
x-=xx;
y-=yy;
x*=x;
y*=y;
r=sqrt(x+y);
if(r>100.0)return 1;
else return 0;
}
void main()
{
int a=DETECT,b;
initgraph(&a,&b,"c:\\tc\\bgi");
setlinestyle(0,0,1);
setcolor(14);
line(1,0,1,getmaxy());
line(1,getmaxy()/2,getmaxx(),getmaxy()/2);
sinewave(30,100);/*Change the arguments to change the frequency and
amplitude of the wave respectively*/
getch();
cleardevice();
line(1,0,1,getmaxy());
line(1,getmaxy()/2,getmaxx(),getmaxy()/2);
cosinewave(30,100);/*Change the arguments to change the frequency and
amplitude of the wave respectively*/
getch();
cleardevice();
line(1,0,1,getmaxy());
line(1,getmaxy()/2,getmaxx(),getmaxy()/2);
tanwave(30,100);/*Change the arguments to change the frequency and
amplitude of the wave respectively*/
getch();
closegraph();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -