Programming and Graphics

(Kiana) #1

226 Introduction to C++ Programming and Graphics


*------------------------
plot2d
Plot a line with axes
-------------------------*/

#include<cmath>
#include "VOGLE/voglec++.h"
#include "drawmarker2d.h"
#include "drawline2d.h"
#include "drawaxes2d.h"

using namespace std;

int main()
{

//--- Define the data:

const int n=512;
float xd[n], yd[n];

for (int i=0; i<n; i++)
{
xd[i]=-0.3+4.0*(i-1.0)/n;
yd[i]=0.5+0.3*sin(35.0*xd[i])*exp(xd[i]);
}

//--- Define the plotting parameters:

float xmin=0.0, xmax=1.0; // plotting limits
float ymin=0.0, ymax=1.0; // plotting limits
int ntcx =10; // number of ticks on the x axis
int ntcy =10; // number of ticks on the y axis
int Ilabelax =1; // 1 to label axes; 0 for no labels
int axc = BLACK; // axis color
int lbc = RED; // label color
char labelx[] = "x-axis"; // x-axis label
char labely[] = "y-axis"; // y-axis label
char title1[] ="vogle graphics"; // first plot title
char title2[] ="Eric H Echidna"; // second plot title
char title3[] ="Beerware"; // third plot title

//--- Launch the graphics:

float xmarg = 0.2*(xmax-xmin); // plotting margin
float ymarg = 0.2*(ymax-ymin);

prefposition (500,100);
prefsize (500,500);
Free download pdf