home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1996 February
/
PCWK0296.iso
/
sharewar
/
os2
/
grafika
/
splot
/
demo
/
linedraw.spt
< prev
next >
Wrap
Text File
|
1994-05-27
|
7KB
|
319 lines
/* This file illustrates how to generate a line drawing of apparatus */
/* It makes heavy use of gsave() and grestore() and axes transformations*/
/* to draw elements repeatedly in different locations and/or orientations */
/* This is just one way to do this. */
#include <splot.h>
main()
{
/* it turned out too big in the end so scale it back some */
scale(0.75,0.75);
/* draw Dewar */
tail();
gsave();
/* draw a slightly bigger tail around the first */
scale(1.25,1.05);
translate(-1.05,-0.5);
tail();
grestore();
/* draw lenses */
newpath();
set(LINECOLOUR,BROWN);
gsave();
translate(12.79,10.85);
rotate(90);
scale(2,2);
lens();
grestore();
gsave();
translate(11.09,6.21);
scale(0.5,0.5);
lens();
grestore();
/* draw the prism */
gsave();
translate(10.84,10.6);
prism();
grestore();
/* draw helium level */
set(LINECOLOUR,BLUE);
moveto(2.44,8.08);
curveto(3.13,7.66,3.82,8.68,4.13,7.96);
curveto(4.89,8.38,5.32,7.72,5.89,8.20);
curveto(6.58,7.72,7.08,8.74,7.77,8.08);
stroke();
/* draw 45 degree fold mirror */
set(LINECOLOUR,BLACK);
moveto(4.07,11.72);
lineto(5.64,10.15,5.44,9.95,3.64,11.72);
closepath();
/* draw diamnond anvil cell */
moveto(3.38,11.72);
lineto(6.82,11.72,6.82,17.07,7.33,17.07,7.33,17.73,2.88,17.73,2.88,17.07,3.38,17.07);
closepath();
moveto(3.82,17.72);
lineto(3.82,18,6.33,18,6.33,17.72);
stroke();
/* draw plate and screws */
moveto(2.88,18.0);
lineto(7.33,18.0,7.33,18.76,2.88,18.76);
closepath();
stroke();
gsave();
translate(3.38,18.76);
screw(1.5);
translate(3.45,0);
screw(1.5);
grestore();
/* draw heater */
gsave();
translate(7.0,13.03);
heater();
translate(-3.8,0);
heater();
grestore();
/* draw slits */
gsave();
translate(21.8,11.0);
slit();
grestore();
gsave();
scale(1,-1);
translate(21.8,-10.6);
slit();
grestore();
/* draw periscope */
moveto(22.82,10.45);
lineto(23.57,11.18);
rlineto(0,2, 0.75,0, 0,1.5, -2,0, 0,-1.5, 0.75,0, 0,-2, 0.5,0);
stroke();
/* draw arrows */
moveto(25.66,14.07);
arrowto(25.66,14.79);
moveto(25.66,14.07);
arrowto(25.66,13.35);
stroke();
/* draw screw drivers and light pipe */
moveto(4.76,18.76);
lineto(4.76,30.0);
moveto(5.45,18.76);
lineto(5.45,30.0);
stroke();
gsave();
translate(3.38,18.9);
driver();
translate(3.45,0);
driver();
grestore();
/* white out some of the lines at */
/* the top that turned out too long */
white_box(1.17,29.67,8.61,31.20);
newpath();
/* draw copper gasket */
gsave();
set(LINECOLOUR,GREEN);
set(LINEWIDTH,0.10);
moveto(4.57,13.7);
lineto(5.57,13.7);
stroke();
grestore();
/* draw dashed lines in diamond cell */
set(LINESTYLE,0.5,0.25);
moveto(3.82,17.72);
lineto(3.82,12.60,6.33,12.60,6.33,17.72);
moveto(3.82,14.8);
lineto(6.33,14.8);
moveto(4.76,14.8);
lineto(4.76,18.76);
moveto(5.45,14.8);
lineto(5.45,18.76);
moveto(4.76,12.6);
lineto(4.38,11.72);
moveto(5.45,12.6);
lineto(5.83,11.72);
stroke();
/* draw the sapphire anvils */
gsave();
translate(4.32,12.6);
anvil();
translate(1.5,2.2);
rotate(180);
anvil();
grestore();
stroke();
/* draw light paths */
set(LINECOLOUR,MAGENTA);
moveto(5.1,13.57);
lineto(5.1,10.85,11.09,10.85,11.09,0.06);
moveto(13.35,12.9);
lineto(4.7,11.22,5.1,13.51,5.45,10.43,13.35,8.74);
moveto(13.35,12.9);
lineto(21.73,10.85,13.35,8.74);
stroke();
/* add comments */
set(LINECOLOUR,BLACK);
set(LINESTYLE,0);
set(FONTWIDTH,1.0);
text(2.33,32.29,"High Pressure, Low Temperature Spectroscopy");
set(FONTWIDTH,0.6);
text(3.57,4.58,"Liquid He");
text(22.65,15.60,"CCD");
text(19.81,7.39,"Spectrometer");
text(" Slits");
text(9.5,16.7,"Sapphire Anvil Cell");
text(9.5,14,"Heater");
text(9.5,23.88,"Light Pipe");
text(9.5,27,"Screw Drivers");
/* draw lines to labelled parts */
set(LINEWIDTH,0.01);
moveto(4.76,5.46);
lineto(5.68,6.91);
moveto(9.19,13.99);
lineto(7.27,13.75);
moveto(9.27,16.64);
lineto(7.02,16.16);
moveto(9.27,23.96);
lineto(5.68,23.64);
moveto(9.27,27.02);
lineto(7.27,26.38);
moveto(9.27,27.02);
lineto(3.76,26.78);
stroke();
}
int anvil()
{
/* draw a sapphire anvil */
newpath();
moveto(0,0);
rlineto(0,0.5,0.5,0.5,0.5,0,0.5,-0.5,0,-0.5);
stroke();
}
int screw(double len)
{
int i,j;
/* draw a screw using a loop for */
/* the threads */
newpath();
moveto(0,0);
rlineto(0.25,0,0,0.25,-0.5,0,0,-0.25);
closepath();
moveto(0.15,0);
rlineto(0,-len,-0.3,0,0,len);
moveto(-0.15,0);
j = (int) (len / 0.2);
for (i=0;i < j;i++)
{
rmoveto(0.3,0);
rlineto(-0.30,-0.20);
}
stroke();
}
int heater()
{
int i;
/* draw a heater using a loop */
/* for the windings */
double y = 0;
newpath();
moveto(0,0);
for (i=0;i < 5;i++)
{
moveto(0.1,y);
arcn(0,y,0.1,360,0);
y = y + 0.4;
}
stroke();
}
int slit()
{
/* draw a spectrometer slit */
newpath();
moveto(0,0);
rlineto(0,1.5,0.25,0,0,-1.25);
closepath();
stroke();
}
int driver()
{
/* draw long screw drivers */
newpath();
moveto(0,0);
rlineto(0.15,0,0,0.25,0.1,0,0,10.8);
moveto(0,0);
rlineto(-0.15,0,0,0.25,-0.1,0,0,10.8);
stroke();
}
int white_box(double x1,double y1,double x2,double y2)
{
/* draw a white filled box for */
/* white out purposes. The parametrs */
/* passed in are the box corners */
newpath();
box(x1,y1,x2,y2);
gsave();
set(LINECOLOUR,WHITE);
fill();
grestore();
}
int lens()
{
/* draw a spherical lens using arcs */
newpath();
arcn(0,-4,4,110,70);
arcn(0,3.45,4,290,250);
closepath();
stroke();
}
int prism()
{
/* draw a prism */
newpath();
moveto(0,0.5);
rlineto(0,-0.5,0.5,0);
closepath();
stroke();
}
int tail()
{
/* draw the dewar tail */
set(LINECOLOUR,BLACK);
moveto(2.44,30);
lineto(2.44,6.33,7.77,6.33,7.77,30);
stroke();
/* draw windows */
set(LINECOLOUR,BROWN);
white_box(2.29,12.30,2.59,9.41);
stroke();
white_box(7.62,12.30,7.92,9.41);
stroke();
}