home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1996 February
/
PCWK0296.iso
/
sharewar
/
os2
/
grafika
/
splot
/
demo
/
intcalc.spt
< prev
next >
Wrap
Text File
|
1994-06-05
|
4KB
|
152 lines
#include <splot.h>
/* This example file illustrates some of the internal math capabilities */
/* In this case x,y data points for several parabolas are calculated */
/* and then drawn. Also the photon uses the sine function to draw a wave. */
/* For the photon the data is not stored in an array, rather the calculated */
/* values are added to offsets given as parameters to the photon subroutine */
/* make space for the to be generated data */
double pdat[101][2];
main()
{
double x0,y0;
x0 = 10;
y0 = 5.5;
/* draw parabolas at x0,y0 to represent bands*/
siband(x0,y0);
/* draw circles to represent holes in the valence band */
arc(x0 - 0.5,y0 - 0.25,0.25,0,360);
stroke();
arc(x0 + 0.5,y0 - 0.25,0.25,0,360);
stroke();
/* draw electrons in the conduction band */
moveto(x0 + 4.25,y0 + 3.25);
rlineto(-0.5,0);
moveto(x0 - 4.25,y0 + 3.25);
rlineto(0.5,0);
stroke();
/* draw arrows to indicate optical transitions */
moveto(x0 + 3.5,y0 + 2.75);
arrowto(x0 + 1,y0 + 0.25);
moveto(x0 - 3.5,y0 + 2.75);
arrowto(x0 - 1,y0 + 0.25);
/* label the photon */
text(x0 + 5, y0,"h!w! = 2E_g_");
/* but bar through h */
moveto(x0 + 4.95,y0 + 0.16);
rlineto(0.3,0.3);
stroke();
/* draw bands again but higher up */
x0 = 10;
y0 = 19;
siband(x0,y0);
/* draw single hole */
arc(x0,y0 - 0.25,0.25,0,360);
stroke();
/* draw single electron */
moveto(x0 + 4.25,y0 + 3.25);
rlineto(-0.5,0);
stroke();
moveto(x0 + 3.5,y0 + 2.75);
arrowto(x0 + 0.5,y0 + 0.25);
/* label photon */
text(x0 + 5, y0,"h!w! = E_g_");
moveto(x0 + 4.95,y0 + 0.16);
rlineto(0.3,0.3);
stroke();
/* add titles */
text(10.0,25.15,"Infrared Luminescence",CENTER);
text(10.0,11.8,"Visible Luminescence",CENTER);
}
int siband(double x0,y0)
{
/* draws strained SiGe band structure */
/* as a set of parabolas */
parab(x0,y0,0.1,-0.1);
parab(x0,y0 - 1.0,0.05,-0.3);
parab(x0 - 4.0,y0 + 3.0,0.05,0.3);
parab(x0 + 4.0,y0 + 3.0,0.05,0.3);
/* draw axes */
moveto(x0,y0 - 4.0);
rlineto(0,0.3);
moveto(x0,y0 - 4.0);
rarrowto(6,0);
moveto(x0,y0 - 4.0);
rarrowto(-6,0);
stroke();
moveto(x0 - 7, y0);
rarrowto(0,3);
rarrowto(0,-3);
moveto(x0 - 7.25,y0);
rlineto(0.5,0);
moveto(x0 - 7.25,y0 + 3);
rlineto(0.5,0);
stroke();
/* draw a photon */
photon(x0 + 4.5,y0 + 1.5,0.3,0.3);
/* a k vector labels */
text(x0,y0 - 5,"0",CENTER);
text(x0 + 6,y0 - 5,"k");
text(x0 - 7.5,y0 + 1.5,"E_g_",RIGHT);
}
int parab(double x0,double y0,double dx,double a)
{
int i;
double x;
/* draws a parabola by generating */
/* a data array first */
for (i = 0; i <= 50;i++)
{
x = i * dx;
pdat[50 + i][1] = a * x * x + y0;
pdat[50 - i][1] = a * x * x + y0;
pdat[50 + i][0] = x0 + x;
pdat[50 - i][0] = x0 - x;
}
moveto(pdat[0][0],pdat[0][1]);
for (i = 0;i <= 100;i++)
{
lineto(pdat[i][0],pdat[i][1]);
}
stroke();
}
int photon(double x0,double y0,double xscale,double yscale)
{
double x,y;
int i;
/* draw a photon using the sine function */
moveto(x0,y0);
for (i = 0;i < 50;i++)
{
x = i * 0.255;
y = sin(x);
lineto(x * xscale + x0,y * yscale + y0);
}
set(FONTMULT,2);
rarrowto(2.5 * xscale,0);
set(FONTMULT,0.5);
stroke();
}