/*
[Environment]
Ubuntu 14.04
[Installation of pgplot]
sudo apt-get update
sudo apt-get install pgplot5
[compile this file]
gcc -o sin-wave -Wall sin-wave.c -lcpgplot -lpgplot -lm -L/usr/X11R6/lib
Thanks to
http://akita-nct.jp/yamamoto/comp/graph/pgplot/pgplot.html
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "cpgplot.h"
#define XMAX 360
#define TMAX 1080
//============================================================
// main
//============================================================
int main(void){
int i,n; ;
float wave[XMAX+1],x[XMAX+1];
int xwin;
if((xwin = cpgopen("/xserv")) <= 0)exit(1);
cpgask(0);
cpgpage();
cpgvstd();
cpgpap(5.0, 0.7);
cpgenv(-0.1, 1.1, -1.1 , 1.1, 0, 0);
cpgscf(2);
cpgsch(1.2);
for(i=0; i<=XMAX; i++) x[i]=i/360.0;
for(n=0; n<=TMAX; n++){
for(i=0; i<=XMAX; i++){
wave[i]=sin(i*M_PI/180.0)*cos(n*M_PI/180.0);
}
cpgbbuf();
cpgeras();
cpgsci(1);
cpglab("Position", "Amplitude", "standing wave");
cpgbox("bcnst", 0.0, 0, "bcnst", 0.0, 0);
cpgsci(2);
cpgline(XMAX+1, x, wave);
cpgebuf();
}
cpgclos();
return 0;
}