Listing of the file special.cpp for
drawing two sets of Gaussian Distributions
#include "StdAfx.h"
#include <math.h>
#include "special.h"
// Create a display with four Gaussians (without convenience functions)
int specialDraw(POINT *vp, int buf_size, int *np, char *cp)
{
int i, k;
int scale = 50; //(has to be >= 1/dx)
double x, y, dx = 0.02;
int n = (int)(2.5/dx); // 2.5 sigma
int m = 2*n+1;
if(buf_size < 4*m+4) return 0;
int xcenter = 400, ycenter = 100;
POINT *z = new POINT[m];
z[n].x = xcenter;
z[n].y = ycenter;
for(i = 1, x = dx; i<=n; i++, x += dx) {
y = exp(-x*x);
z[n+i].x = (int)(xcenter + x*scale+0.5);
z[n-i].x = (int)(xcenter - x*scale+0.5);
z[n+i].y = z[n-i].y = ycenter*2 - (int)(y*ycenter+0.5);
}
int xshift[4] = {0, 100, -60, 160}; // found by trial and error
int yshift[4] = {0, 0, 150, 150 }; // for nice looking display
for(k=0; k<4; k++) {
for(i=0; i<m; i++) {
vp[m*k+i].x = z[i].x + xshift[k];
vp[m*k+i].y = z[i].y + yshift[k];
}
np[k] = m; cp[k] = 'p';
}
int j = m*4;
vp[j+1].x = vp[j].x = xcenter+50; vp[j].y = 50; vp[j+1].y = 400;
np[4] = 2; cp[4] = 'p';
vp[j+3].x = vp[j+2].x = xcenter+20; vp[j+2].y = 50; vp[j+3].y = 400;
np[5] = 2; cp[5] = 'p';
delete[] z;
return 6;
}