// Gaurang Sinha // gaurang85@rediffmail.com // gaurang.cjb.net -or- gaurang85.tripod.com #include #include #include #include #define ESC 0x1b #define PI 3.14159265358979323846 void dwSin(float,float); int s; int main() { int gd=DETECT,gm; float a,b; A: printf("\n\n Enter Wave Type :"); printf("\n 1. Sine Wave"); printf("\n 2. Cosine Wave"); printf("\n ::> "); scanf("%d",&s); if(s!=1&&s!=2)goto A; printf("\n\nEnter Frequency & Amplitude : "); scanf("%f%f",&a,&b); initgraph(&gd,&gm,"C:\\TC\\BGI"); setbkcolor(BLACK); setcolor(GREEN); //Drawing Outer Border line(1,1,1,469); line(1,469,639,469); line(639,469,639,1); line(639,1,1,1); setcolor(WHITE); //Drawing Axis line(0,240,640,240); //X Axis line(320,0,320,469); //Y Axis setcolor(RED); //Sine Wave Color dwSin(a,b); getch(); return 0; } void dwSin(float freq,float amp) { int i; long float var,val,tmp; freq=freq*1.13; //needs to be multiplied by 1.13 so that it'll fit on the screen for(i=0;i<=720;i++) { var=((i*PI)/180)*freq; //Calculating radians ... if(s==1) val=amp*sin(var); //Calculating corresponding sine/cosine value else if(s==2) val=amp*cos(var); val=(240-val); //This is an constant added so that it'll draw sine wave on X-Axis putpixel(i,val,RED); //Draws the corresponding pixel } }