[net.startrek] A plot

kyrimis@tilt.FUN (Kriton Kyrimis) (03/27/85)

It seems that this kind of things is quite popular, so here is the result
of one night's hacking on my micro, converted to C and plot(3). The original
version included the "NCC-1701" logo on the warp nacelle, but since I can't
figure out how to write text at an angle on UNIX, this has been left out.
If you know how to do it, please mail to me, and I'll repost. (Please don't
say something like "read the bitmap from one of the fonts and write your
own routine to write slanting letters" - I know this can be done, but don't
want to do it. If YOU have already done that, however...). Below is the C
source to the program, along with a makefile to compile it and draw the
picture (make draw). There is also a file with some hints on converting the
program to other graphics devices.
			I hope you like it.
			Kriton Kyrimis (princeton!tilt!kyrimis)

-----------------------------------CUT HERE-----------------------------------
#!/bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #!/bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	ent.c
#	makefile
#	conversion
# This archive created: Wed Mar 27 11:42:23 1985
export PATH; PATH=/bin:$PATH
echo shar: extracting "'ent.c'" '(2427 characters)'
if test -f 'ent.c'
then
	echo shar: over-writing existing file "'ent.c'"
fi
cat << \SHAR_EOF > 'ent.c'
/* ent.c - make a drawing of the Enterprise on a Versatec printer/plotter
 * Kriton Kyrimis - 3/26/85
 */
#include <math.h>

#define PI 3.14159265358

main()
{
  openpl();
  space(0,0,2048,2048);
  el(914,682,352,110,333,15,-119);
  el(910,718,373,130,218,15,-24);
  el(914,682,143,44,243,15,-34);
  el(919,661,118,34,261,15,-45);
  el(922,635,86,23,312,15,-71);
  el(922,625,52,13,221,15,-25);
  el(921,614,32,7,360,15,-60);
  el(922,604,18,13,180,15,-183);
  mv(810,627); dr(747,480);
  mv(652,544); dr(606,392);
  el(780,380,340,209,30,36,60);
  mv(747,480); dr(523,344);
  mv(480,318); dr(433,290);
  mv(773,340); dr(501,235);
  el(462,215,44,44,85,0,30);
  el(498,287,68,68,30,0,176);
  mv(564,369); dr(595,491);
  dr(454,414); mv(415,389); dr(376,371);
  mv(611,554); dr(444,460); dr(439,465);
  dr(418,451); mv(386,431); dr(358,410);
  el(424,415,65,65,40,0,180);
  mv(362,398); dr(334,381); dr(337,376);
  dr(353,386); dr(360,371); dr(366,376);
  dr(371,366); dr(376,371);
  mv(523,344); dr(366,501);
  mv(480,318); dr(334,486); dr(88,340);
  mv(52,413); dr(125,460); dr(136,454);
  dr(407,632); mv(456,562); dr(366,501);
  el(434,601,41,39,360,120,0);
  mv(434,601); dr(401,581);
  mv(434,601); dr(444,560);
  mv(434,601); dr(472,597);
  mv(434,601); dr(463,624);
  mv(434,601); dr(413,636);
  el(130,411,78,78,56,0,180);
  mv(52,392); dr(26,373); dr(36,352);
  dr(44,360); dr(52,355); dr(65,358);
  dr(70,350); dr(88,340);
  el(818,408,112,78,75,105,40);
  el(830,408,112,78,75,105,40);
  el(846,408,112,78,66,105,46);
  el(815,416,42,21,360,105,0);
  el(815,416,34,13,360,105,0);
  el(757,392,91,57,40,105,-60);
  el(753,428,91,57,44,105,180);
  mv(815,416); dr(862,444);
  closepl();
}

el(X,Y,a,b,AR,TH,P)
  int X,Y,a,b,AR,TH,P;
{
  double x,y,ar,th,p,c,s,i,st;

  ar = (double)AR/180.0*PI;
  th = (double)TH/180.0*PI;
  p = (double)P/180.0*PI;
  s = sin(th);
  c = cos(th);
  x = (double)a*cos(p);
  y = (double)b*sin(p);
  mv((int)((double)X+x*c-y*s),(int)((double)Y+x*s+y*c));
  st = 10.0/(double)(a+b);
  for (i=p; i<=ar+p+st; i+=st) {
    x = (double)a*cos(i);
    y = (double)b*sin(i);
    dr((int)((double)X+x*c-y*s),(int)((double)Y+x*s+y*c));
  }
}

int cx=0,cy=0;

mv(x,y)
  int x,y;
{
  cx = (int)((double)x * 1.6);
  cy = (int)((double)y * 1.6) + 205;
}

dr(x,y)
  int x,y;
{
  int nx,ny;

  nx = (int)((double)x * 1.6);
  ny = (int)((double)y * 1.6) + 205;
  line(cx,cy,nx,ny);
  cx = nx;
  cy = ny;
}
SHAR_EOF
if test 2427 -ne "`wc -c 'ent.c'`"
then
	echo shar: error transmitting "'ent.c'" '(should have been 2427 characters)'
fi
echo shar: extracting "'makefile'" '(162 characters)'
if test -f 'makefile'
then
	echo shar: over-writing existing file "'makefile'"
fi
cat << \SHAR_EOF > 'makefile'
# make a drawing of the enterprise on a Versatec printer/plotter
#
# Kriton Kyrimis - 3/26/85
#
ent:	ent.c
	cc ent.c -O -o ent -lm -lplot
draw:
	ent | plot -Tver
SHAR_EOF
if test 162 -ne "`wc -c 'makefile'`"
then
	echo shar: error transmitting "'makefile'" '(should have been 162 characters)'
fi
echo shar: extracting "'conversion'" '(757 characters)'
if test -f 'conversion'
then
	echo shar: over-writing existing file "'conversion'"
fi
cat << \SHAR_EOF > 'conversion'
This program was originally written for a BBC micro, where the machine
coordinates are 0,0 (bottom left corner) to 1279,1023 (top right corner).
This is reflected in the mv (move) and dr (draw) routines in the program.
If you have to alter the program to draw on another machine, all you have
to do is change these two routines, so that they convert the BBC micro
coordinates to the coordinates of your machine. There is also a call to
openpl() and closepl(). These should be replaced with calls to routines
to initialise and terminate your graphic package (if you're not using
plot(3)). Finally, the  call to space() should probably be omitted
(if you aren't using plot(3)) or modified (if you're using plot(3), but
for a different machine).
				Have fun!
SHAR_EOF
if test 757 -ne "`wc -c 'conversion'`"
then
	echo shar: error transmitting "'conversion'" '(should have been 757 characters)'
fi
#	End of shell archive
exit 0