[comp.sys.sgi] panel03/06

dat@ORVILLE.NAS.NASA.GOV ("David A. Tristram") (08/19/88)

#!/bin/sh
# this is part 3 of a multipart archive
# do not concatenate these parts, unpack them in order with /bin/sh
# file ep.c continued
#
CurArch=3
if test ! -r s2_seq_.tmp
then echo "Please unpack part 1 first!"
     exit 1; fi
( read Scheck
  if test "$Scheck" != $CurArch
  then echo "Please unpack part $Scheck next!"
       exit 1;
  else exit 0; fi
) < s2_seq_.tmp || exit 1
sed 's/^X//' << 'SHAR_EOF' >> ep.c
X  regx = MARGIN,
X  regy = MARGIN,
X  regw = WINSIZE,
X  regh = WINSIZE;
X
Xint bkg=BLACK;	/* the background of the data window */
Xint n;	    /* what one are we drawing now? */
Xfloat t;    /* how far are we toward the next triangle? */
Xint nlimit; /* how many do we draw? */
Xint ncolors;/* how many colors do we get? */
Xint basecolor;/* lowest color that we use */
X
XPanel *panel;
X
XActuator *positionpuck, *speedslider, *zoomslider, *wheelslider, *twistslider,
X	 *flipslider, *spinslider, *armslider, *wristslider, *smearbutton,
X	 *zbufbutton, *smoothbutton, *outlinebutton, *sizeslider,
X	 *stopbutton, *fillbutton, *nslider, *fatlinebutton, *fullbutton,
X         *maprangeslider, *maprateslider, *fadebutton, *ribbonbutton;
X
XActuator *spectrumbutton, *contourbutton, *bandbutton;
X
Xstruct resetbutton {
X    Actuator button;
X    Actuator *targetact;
X    float    *targetvar;
X    float    varinitval;
X};
X
Xvoid
Xload_spectrum_map()
X{
Xfloat h, s, v, r, g, b, x;
Xint i, ir, ig, ib;
X
X  x = 0.0;
X  for (i=0; i<ncolors; i++)
X    {
X/*      x = 2.0*(float)i / (float)ncolors;
X      hls_to_rgb (1.0-ABS(1.0-x), 0.5, 1.0, &r, &g, &b); */
X      x = (float)i / (float)ncolors;
X      hls_to_rgb (x, 0.5, 1.0, &r, &g, &b);
X      rgb_to_irgb (r, g, b, &ir, &ig, &ib);
X      mapcolor ((Colorindex)(basecolor+i), ir, ig, ib);
X    }
X}
X				    
Xvoid
Xload_contour_map(a) 
X  Actuator *a;
X{
Xfloat h, s, v, r, g, b, x, y;
Xint i, ir, ig, ib;
X
X  x = 0.0;
X  for (i=0; i<=ncolors; i++)
X    {
X      /* only want to go from red to violet, hence the "0.8" */
X      x = (float)i / ((float)ncolors);
X      /* quantize in 8 bands */
X      y = fmod(x, (0.85/7.99));
X      x = x - y;
X      hls_to_rgb (x, 6.5*y+0.1, 1.0, &r, &g, &b);
X      rgb_to_irgb (r, g, b, &ir, &ig, &ib);
X      mapcolor ((Colorindex)(basecolor+i), ir, ig, ib);
X    }
X}
X
X
X#define MAPBANDWIDTH 20
X#define MAPLINEWIDTH 4
X
Xvoid
Xload_band_map(a)
X  Actuator *a;
X{
X  int i;
X  load_spectrum_map(a);
X  for (i=MAPBANDWIDTH; i<(ncolors-MAPBANDWIDTH); i++)
X    {
X      if (i%MAPBANDWIDTH <= MAPLINEWIDTH)
X	mapcolor(basecolor+i, 0, 0, 0);
X    }
X   
X}
X
Xskew(x, y, z)
Xfloat x, y, z;
X{
X  static Matrix mat = {
X    {1.0, 0.0, 0.0, 0.0},
X    {0.0, 1.0, 0.0, 0.0},
X    {0.0, 0.0, 1.0, 0.0},
X    {0.0, 0.0, 0.0, 1.0}
X  };
X
X  mat[0][0] = 1.0+x;
X  mat[0][1] = y;
X  mat[1][2] = z;
X  multmatrix(mat);
X}
X
Xvoid
Xresetact(b)
Xstruct resetbutton *b;
X{
X    if (b->targetact->val!=b->targetact->initval) {
X	b->targetact->val=b->targetact->initval;
X        fixact(b->targetact);
X    } else if (b->targetvar) {
X	*b->targetvar=b->varinitval;
X    }
X}
X
Xstatic short savR[MAXCOLORS], savG[MAXCOLORS], savB[MAXCOLORS];
X
Xsavecolors()
X{
Xint i;
X
X  for (i=0;i<ncolors;i++)
X    getmcolor(i+basecolor, &savR[i], &savG[i], &savB[i]);
X}
X
Xrestorecolors()
X{
Xint i;
X
X  for (i=0;i<ncolors;i++)
X    mapcolor(i+basecolor, savR[i], savG[i], savB[i]);
X}
X
Xvoid
Xcleanexit()
X{
X  restorecolors();
X  exit(0);
X}
X
Xvoid
Xsetsmooth(a)
XActuator *a;
X{
X  if (smearbutton->val==1.0) {
X    if (a->val==1.0) {
X      frontbuffer(FALSE);
X      backbuffer(TRUE);
X    } else {
X      frontbuffer(TRUE);
X      backbuffer(TRUE);
X    }
X  }
X}
X
Xvoid
Xsetsmear(a)
XActuator *a;
X{
X  if (a->val==1.0) {
X    if (smoothbutton->val!=1.0) {
X      if (stopbutton->val!=1.0) {
X	color(bkg);
X	clear();
X	drawit();
X      }
X      frontbuffer(TRUE);
X      backbuffer(TRUE);
X    }
X  } else {
X    frontbuffer(FALSE);
X    backbuffer(TRUE);
X  }
X}
X
Xvoid
Xsetzbuf(a)
XActuator *a;
X{
X    if (a->val!=1.0) {
X        zbuffer(FALSE);
X    } else {
X        zbuffer(TRUE);
X	zclear();
X    }
X}
X
Xvoid
Xfullscreen(a)
XActuator *a;
X{
X  if (stopbutton->val==1.0) {	/* a bit of a hack, but expressed nicely */
X    a->val=0.0;
X    fixact(a);
X    return;
X  }
X  getorigin(&regx, &regy);
X  getsize(&regw, &regh);
X  winconstraints();
X  winposition(0, XMAXSCREEN, 0, YMAXSCREEN);
X  reshapeviewport();
X  perspective(300, (float)XMAXSCREEN/(float)YMAXSCREEN, 0.01, 10000.0);
X  polarview(10.0, 0, 0, 0);
X#ifdef IRIS_GT
X  lsetdepth(0x0, 0x7fffff);
X#else  IRIS_GT
X  setdepth(0x0000,0x3fff);
X#endif IRIS_GT
X  winpop();
X  color(bkg);
X  clear();
X  swapbuffers();
X  color(bkg);
X  clear();
X  swapbuffers();
X}  
X
Xvoid
Xregularscreen()
X{
X  fullbutton->val=0.0;
X  fixact(fullbutton);
X
X  winposition(regx, regx+regw, regy, regy+regh);
X  reshapeviewport();
X  perspective(300, 1.0, 0.01, 10000.0);
X  polarview(10.0, 0, 0, 0);
X#ifdef IRIS_GT
X  lsetdepth(0x0, 0x7fffff);
X#else  IRIS_GT
X  setdepth(0x0000,0x3fff);
X#endif IRIS_GT
X  keepaspect(1, 1);
X  winconstraints();
X  
X  color(bkg);
X  clear();
X  swapbuffers();
X  panel->dirtycnt=2;
X  drawpanel();
X  color(bkg);
X  clear();
X  swapbuffers();
X}
X
Xvoid
Xtogglefullscreen(a)
XActuator *a;
X{
X  static fullscreenmode=FALSE;
X
X  if (!fullscreenmode) {
X    fullscreen(a);
X    fullscreenmode=TRUE;
X  } else {
X    regularscreen(a);
X    fullscreenmode=FALSE;
X  }
X}
X
Xfloat wheel, dwheel;
Xfloat *x, *y, *dzoom, *arm, *wrist, *dtwist, *flip, *spin;
XBoolean *outline, *fatline, *fill;
Xfloat *size;
Xfloat gflip, dflip, gspin, dspin, gcol;
Xfloat *maprange, *maprate;
XCoord square[][2] = {
X    {-0.1, -0.1},
X    { 0.1, -0.1},
X    { 0.1,  0.1},
X    {-0.1,  0.1}
X};
X  
XCoord triangle[][2] = {
X    { 0.0,  0.0 },
X    { 0.2,  0.0 },
X    { 0.1, SQRT3/10.0 }
X};
X
Xmain()
X{
X  Actuator *a;
X  Device dev;
X  short val;
X  int h, i, j, mexwin;
X  int itmp;
X  float tmp;
X  Boolean newn;
X
X  wheel=0.0;
X  x=(float *)calloc(NPNTS, sizeof(float));
X  y=(float *)calloc(NPNTS, sizeof(float));
X  dzoom=(float *)calloc(NPNTS, sizeof(float));
X  arm=(float *)calloc(NPNTS, sizeof(float));
X  wrist=(float *)calloc(NPNTS, sizeof(float));
X  dtwist=(float *)calloc(NPNTS, sizeof(float));
X  flip=(float *)calloc(NPNTS, sizeof(float));
X  spin=(float *)calloc(NPNTS, sizeof(float));
X  outline=(Boolean *)calloc(NPNTS, sizeof(Boolean));
X  fatline=(Boolean *)calloc(NPNTS, sizeof(Boolean));
X  fill=(Boolean *)calloc(NPNTS, sizeof(Boolean));
X  size=(float *)calloc(NPNTS, sizeof(float));
X  maprange=(float *)calloc(NPNTS, sizeof(float));
X  maprate=(float *)calloc(NPNTS, sizeof(float));
X  
X#ifdef DEBUG
X  foreground();
X#endif DEBUG
X  prefposition(regx, regx+regw, regy, regy+regh);
X  winopen("ep");
X  winconstraints();
X  keepaspect(1, 1); 
X  winconstraints();	/* make the window reshapeable */
X  winattach();
X  mexwin=winget();
X  
X  doublebuffer();
X  gconfig();
X
X  needredraw();
X  defpanel();
X
X  switch (getplanes()) {
X  case 4:
X    ncolors=15;
X    basecolor=1;
X    maprangeslider->minval=0.0;
X    maprangeslider->maxval=10.0;
X    fixact(maprangeslider);
X    pnl_background_color	= 8;
X    pnl_white_color		= 4;
X    pnl_normal_color		= 9;
X    pnl_other_color		= 7;
X    pnl_highlight_color		= 4;
X    pnl_outline_color		= 11;
X    break;
X  case 8:
X    ncolors=128;
X    basecolor=128;
X    break;
X  case 12:
X  default:
X    ncolors=128;
X    basecolor=512;
X    break;
X  }
X  savecolors();
X
X  load_spectrum_map();
X  color(bkg);
X  clear();
X  swapbuffers();
X  clear();
X  
X#ifdef IRIS_4D
X  shademodel(FLAT);
X  concave(FALSE);
X#endif IRIS_4D
X#ifdef IRIS_GT
X  glcompat(GLC_OLDPOLYGON, FALSE);
X#endif IRIS_GT
X
X  perspective(300, 1.0, 0.01, 1000000.0);
X  polarview(10.0, 0, 0, 0);
X  /*   lookat(0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0); */
X#ifdef IRIS_GT
X  lsetdepth(0x0, 0x7fffff);
X#else  IRIS_GT
X  setdepth(0x0000,0x3fff);
X#endif IRIS_GT
X  
X  n=0;
X  t=0.0;
X  gcol=BASECOLOR+ncolors/2;
X
X  for (;;) {
X
X    a=dopanel();
X    if (stopbutton->val==1.0) {
X      if (smearbutton->val!=1.0) {
X        color(bkg);
X	clear();
X      }
X      drawit();
X      swapbuffers();
X      do {
X	a=dopanel();
X	if (!a) sginap(0);
X	swapbuffers();
X      } while (stopbutton->val==1.0);
X    }
X
X    if (fullbutton->val==1.0
X        && getbutton(LEFTMOUSE)) regularscreen();
X
X    t+=speedslider->val;
X    newn=FALSE;
X    if (t>=1.0) newn=TRUE;
X    n+=floor(t);
X    t=fmod(t,1.0);
X
X    x[n%NPNTS]=PNL_ACCESS(Puck,positionpuck,x);
X    y[n%NPNTS]=PNL_ACCESS(Puck,positionpuck,y);
X    dzoom[n%NPNTS]=zoomslider->val;
X    arm[n%NPNTS]=armslider->val;
X    wrist[n%NPNTS]=wristslider->val;
X    dwheel=speedslider->val*wheelslider->val;
X    dtwist[n%NPNTS]=twistslider->val;
X    nlimit=(int)nslider->val;
X    outline[n%NPNTS]=outlinebutton->val==1.0;
X    fatline[n%NPNTS]=fatlinebutton->val==1.0;
X    fill[n%NPNTS]=fillbutton->val==1.0;
X    size[n%NPNTS]=sizeslider->val;
X    maprange[n%NPNTS]=maprangeslider->val;
X    gcol+=speedslider->val*maprateslider->val;
X    while(gcol<basecolor) gcol+=ncolors;
X    while(gcol>=basecolor+ncolors) gcol-=ncolors;
X        
X    if (newn) {
X        dflip=flipslider->val;
X	dspin=spinslider->val;
X
X        gflip=fmod(gflip+dflip,360.0);
X	flip[n%NPNTS]=gflip;
X
X	gspin=fmod(gspin+dspin,360.0);
X	spin[n%NPNTS]=gspin;
X    }
X
X/*     winset(mexwin); */
X    if (userredraw()) {
X	reshapeviewport();
X	if (fullbutton->val==1.0) 
X	  perspective(300, (float)XMAXSCREEN/(float)YMAXSCREEN, 0.01, 10000.0);
X	else
X	  perspective(300, 1.0, 0.01, 10000.0);
X	polarview(10.0, 0, 0, 0);
X#ifdef IRIS_GT
X	lsetdepth(0x0, 0x7fffff);
X#else  IRIS_GT
X	setdepth(0x0000,0x3fff);
X#endif IRIS_GT
X    }
X
X    wheel=fmod(wheel-dwheel,360.0);
X/* fprintf(stderr, "wheel:%f  dwheel:%f\n", wheel, dwheel); */
X
X    if (smearbutton->val!=1.0) {
X        color(bkg);
X	clear();
X    } else {
X      if (fadebutton->val==1.0) fadebackground(bkg, 1);
X      if (smoothbutton->val==1.0) {
X	drawit();
X	swapbuffers();
X	if (fadebutton->val==1.0) fadebackground(bkg, 0);
X	drawpanel();
X      }
X    }
X
X    drawit();
X    swapbuffers();
X  }
X}
X
Xfloat
Xtwixt(i,x,t)
Xint i;
Xfloat *x;
Xfloat t;
X{
Xint j=i-1;
X
X    if (j<0) j+=NPNTS;
X    return x[i]*t+x[j]*(1.0-t);
X}
X
Xfloat
Xfoldtwixt(i,x,t)
Xint i;
Xfloat *x;
Xfloat t;
X{
X  float r;
X  float d;
X  int j=i-1;
X
X    if (j<0) j+=NPNTS;
X    d=x[i]-x[j];
X    if	    (d> 180.0) r=x[i]*t+(x[j]+360.0)*(1.0-t);
X    else if (d<-180.0) r=(x[i]+360.0)*t+x[j]*(1.0-t);
X    else	       r=x[i]*t+x[j]*(1.0-t);
X
X    return r;
X}
X
Xdrawit()
X{
Xint i,j;
Xint outlinecolor;
Xfloat tx,ty,tdzoom,tarm,twrist,tsize;
Xfloat tspin,tflip,tdtwist;
Xfloat col;
X
X    if (ribbonbutton->val==1.0) {
X      drawribbons(); return;
X    }
X    if (zbufbutton->val==1.0) zclear();
X    col=gcol;
X
X    pushmatrix();
X#ifdef FLOAT_ROTATE
X    rot(wheel, 'x');
X#else
X    rotate((int)(10.0*wheel), 'x');
X#endif
X
X    for (i=n;i>n-nlimit;i--) {
X      j=i%NPNTS;
X      if (j<0) j+=NPNTS;
X      if (j>NPNTS-1) j-=NPNTS;
X
X      tx=twixt(j,x,t);
X      ty=twixt(j,y,t);
X      tdzoom=twixt(j,dzoom,t);
X      tarm=twixt(j,arm,t);
X      twrist=twixt(j,wrist,t);
X      tsize=twixt(j,size,t);
X      tspin=foldtwixt(j,spin,t);
X      tflip=foldtwixt(j,flip,t);
X      tdtwist=twixt(j,dtwist,t);
X
X      color((int)col);
X      if (outline[j]) {
X	outlinecolor=((int)col+ncolors/2);
X	if (outlinecolor>=basecolor+ncolors) outlinecolor-=ncolors;
X      }
X      col-=maprange[j];
X      while(col<basecolor) col+=ncolors;
X      while(col>=basecolor+ncolors) col-=ncolors;
X
X      if (fatline[j]) {
X	linewidth(FATLINEWIDTH);
X      } else {
X	linewidth(NORMALLINEWIDTH);
X      }
X      
X      pushmatrix();
X      translate(tx, ty, 0.0);
X#ifdef FLOAT_ROTATE
X      rot(tspin, 'z');
X#else  FLOAT_ROTATE
X      rotate((int)(10.0*tspin), 'z');
X#endif FLOAT_ROTATE
X      translate(0.0,tarm,0.0);
X#ifdef FLOAT_ROTATE
X      rot(tflip, 'y');
X#else  FLOAT_ROTATE
X      rotate((int)(10.0*tflip), 'y');
X#endif FLOAT_ROTATE
X      translate(twrist,0.0,0.0);
X      scale(tsize,tsize,1.0);
X      if (fill[j]) polf2(3, triangle);
X      if (outline[j]) {
X	  color(outlinecolor);
X	  poly2(3, triangle);
X          color((int)col);
X      }
X      popmatrix();
X
X      scale(1.0, -1.0, 1.0);
X
X      pushmatrix();
X      translate(tx, ty, 0.0);
X#ifdef FLOAT_ROTATE
X      rot(tspin, 'z');
X#else  FLOAT_ROTATE
X      rotate((int)(10.0*tspin), 'z');
X#endif FLOAT_ROTATE
X      translate(0.0,tarm,0.0);
X#ifdef FLOAT_ROTATE
X      rot(tflip, 'y');
X#else  FLOAT_ROTATE
X      rotate((int)(10.0*tflip), 'y');
X#endif FLOAT_ROTATE
X      translate(twrist,0.0,0.0);
X      scale(tsize,tsize,1.0);
X      if (fill[j]) polf2(3, triangle);
X      if (outline[j]) {
X	  color(outlinecolor);
X	  poly2(3, triangle);
X          color((int)col);
X      }
X      popmatrix();
X
X#ifdef FLOAT_ROTATE
X      rot(180.0, 'z');
X#else  FLOAT_ROTATE
X      rotate((int)(10.0*180.0), 'z');
X#endif FLOAT_ROTATE
X
X      pushmatrix();
X      translate(tx, ty, 0.0);
X#ifdef FLOAT_ROTATE
X      rot(tspin, 'z');
X#else  FLOAT_ROTATE
X      rotate((int)(10.0*tspin), 'z');
X#endif FLOAT_ROTATE
X      translate(0.0,tarm,0.0);
X#ifdef FLOAT_ROTATE
X      rot(tflip, 'y');
X#else  FLOAT_ROTATE
X      rotate((int)(10.0*tflip), 'y');
X#endif FLOAT_ROTATE
X      translate(twrist,0.0,0.0);
X      scale(tsize,tsize,1.0);
X      if (fill[j]) polf2(3, triangle);
X      if (outline[j]) {
X	  color(outlinecolor);
X	  poly2(3, triangle);
X          color((int)col);
X      }
X      popmatrix();
X
X      scale(1.0, -1.0, 1.0);
X
X      pushmatrix();
X      translate(tx, ty, 0.0);
X#ifdef FLOAT_ROTATE
X      rot(tspin, 'z');
X#else  FLOAT_ROTATE
X      rotate((int)(10.0*tspin), 'z');
X#endif FLOAT_ROTATE
X      translate(0.0,tarm,0.0);
X#ifdef FLOAT_ROTATE
X      rot(tflip, 'y');
X#else  FLOAT_ROTATE
X      rotate((int)(10.0*tflip), 'y');
X#endif FLOAT_ROTATE
X      translate(twrist,0.0,0.0);
X      scale(tsize,tsize,1.0);
X      if (fill[j]) polf2(3, triangle);
X      if (outline[j]) {
X	  color(outlinecolor);
X	  poly2(3, triangle);
X          color((int)col);
X      }
X      popmatrix();
X
X#ifdef FLOAT_ROTATE
X      rot(tdtwist, 'z');
X#else  FLOAT_ROTATE
X      rotate((int)(10.0*tdtwist), 'z');
X#endif FLOAT_ROTATE
X      translate(0.0, 0.0, tdzoom);
X    
X    }
X    popmatrix();
X}
X
Xdrawribbons()
X{
X#ifdef IRIS_GT
X  int ii,i,j;
X  int outlinecolor;
X  float tx,ty,tdzoom,tarm,twrist,tsize;
X  float tspin,tflip,tdtwist;
X  float col;
X  
X  if (zbufbutton->val==1.0) zclear();
X  
X  pushmatrix();
X#ifdef FLOAT_ROTATE
X  rot(wheel, 'x');
X#else
X  rotate((int)(10.0*wheel), 'x');
X#endif
X  
X  for (ii=0;ii<4;ii++) {
X    col=gcol;
X    pushmatrix();
X    bgntmesh();
X    for (i=n;i>n-nlimit;i--) {
X      j=i%NPNTS;
X      if (j<0) j+=NPNTS;
X      if (j>NPNTS-1) j-=NPNTS;
X      
X      tx=twixt(j,x,t);
X      ty=twixt(j,y,t);
X      tdzoom=twixt(j,dzoom,t);
X      tarm=twixt(j,arm,t);
X      twrist=twixt(j,wrist,t);
X      tsize=twixt(j,size,t);
X      tspin=foldtwixt(j,spin,t);
X      tflip=foldtwixt(j,flip,t);
X      tdtwist=twixt(j,dtwist,t);
X      
X      color((int)col);
X      if (outline[j]) {
X	outlinecolor=((int)col+ncolors/2);
X	if (outlinecolor>=basecolor+ncolors) outlinecolor-=ncolors;
X      }
X      col-=maprange[j];
X      while(col<basecolor) col+=ncolors;
X      while(col>=basecolor+ncolors) col-=ncolors;
X      
X      if (fatline[j]) {
X	linewidth(FATLINEWIDTH);
X      } else {
X	linewidth(NORMALLINEWIDTH);
X      }
X      
X      pushmatrix();
X      translate(tx, ty, 0.0);
X#ifdef FLOAT_ROTATE
X      rot(tspin, 'z');
X#else  FLOAT_ROTATE
X      rotate((int)(10.0*tspin), 'z');
X#endif FLOAT_ROTATE
X      translate(0.0,tarm,0.0);
X#ifdef FLOAT_ROTATE
X      rot(tflip, 'y');
X#else  FLOAT_ROTATE
X      rotate((int)(10.0*tflip), 'y');
X#endif FLOAT_ROTATE
X      translate(twrist,0.0,0.0);
X      scale(tsize,tsize,1.0);
X      v2f(&triangle[0][0]); v3f(&triangle[1][0]);
X      popmatrix();
X      
X#ifdef FLOAT_ROTATE
X      if (ii<2) rot(tdtwist, 'z');
X      else      rot(-tdtwist, 'z');
X#else  FLOAT_ROTATE
X      if (ii<2) rotate((int)(10.0*tdtwist), 'z');
X      else      rotate((int)(-10.0*tdtwist), 'z');
X#endif FLOAT_ROTATE
X      translate(0.0, 0.0, tdzoom);
X    
X    }
X    popmatrix();
X
X    if (ii%2) 
X      scale(1.0, -1.0, 1.0);
X    else
X      rotate(1800, 'z');
X
X  }
X  endtmesh();
X  popmatrix();
X#endif IRIS_GT
X}
X
Xdefpanel()
X{
XActuator *a;
Xstruct resetbutton *rb;
XCoord y, dy=0.5;
X
X    initscriptpanel();
X
X    panel=mkpanel();
X#ifdef IRIS_4D
X    panel->ppu=40.0;
X#else
X    panel->ppu=38.0;
X#endif
X    panel->label="electro-paint";
X
X    a=mkact(pnl_label);
X    a->x=0.2;
X    a->y=17.5;
X    a->label="...by Dave Tristram";
X    addact(a,panel);
X
X    a=mkact(pnl_wide_button);
X    a->x=0.0;
X    a->y=0.0;
X    a->label="exit";
X    a->upfunc=cleanexit;
X    addact(a,panel);
X
X    y=3.0;
X
X    outlinebutton=mkact(pnl_toggle_button);
X    outlinebutton->label="outline (O)";
X    outlinebutton->labeltype=PNL_LABEL_LEFT;
X    outlinebutton->x=4.5;
X    outlinebutton->y=(y-=dy);
X    outlinebutton->key=OKEY;
X    addact(outlinebutton,panel);
X
X    fatlinebutton=mkact(pnl_toggle_button);
X    fatlinebutton->label="fat lines (I)";
X    fatlinebutton->labeltype=PNL_LABEL_LEFT;
X    fatlinebutton->x=4.5;
X    fatlinebutton->y=(y-=dy);
X    fatlinebutton->key=IKEY;
X    addact(fatlinebutton,panel);
X
X    fillbutton=mkact(pnl_toggle_button);
X    fillbutton->label="fill (U)";
X    fillbutton->labeltype=PNL_LABEL_LEFT;
X    fillbutton->x=4.5;
X    fillbutton->y=(y-=dy);
X    fillbutton->val=1.0;
X    fillbutton->key=UKEY;
X    addact(fillbutton,panel);
X
X    ribbonbutton=mkact(pnl_toggle_button);
X    ribbonbutton->label="ribbons (R)";
X    ribbonbutton->labeltype=PNL_LABEL_LEFT;
X    ribbonbutton->x=4.5;
X    ribbonbutton->y=(y-=dy);
X    ribbonbutton->key=RKEY;
X    addact(ribbonbutton,panel);
X
X    smoothbutton=mkact(pnl_toggle_button);
X    smoothbutton->label="smooth (M)";
X    smoothbutton->labeltype=PNL_LABEL_LEFT;
X    smoothbutton->x=4.5;
X    smoothbutton->y=(y-=dy);
X    smoothbutton->downfunc=setsmooth;
X    smoothbutton->key=MKEY;
X    addact(smoothbutton,panel);
X
X    smearbutton=mkact(pnl_toggle_button);
X    smearbutton->label="smear (Q)";
X    smearbutton->labeltype=PNL_LABEL_LEFT;
X    smearbutton->x=4.5;
X    smearbutton->y=(y-=dy);
X    smearbutton->downfunc=setsmear;
X    smearbutton->key=QKEY;
X    addact(smearbutton,panel);
X
X    fadebutton=mkact(pnl_toggle_button);
X    fadebutton->label="fade (W)";
X    fadebutton->labeltype=PNL_LABEL_LEFT;
X    fadebutton->x=4.5;
X    fadebutton->y=(y-=dy);
X    fadebutton->key=WKEY;
X    addact(fadebutton,panel);
X
X    zbufbutton=mkact(pnl_toggle_button);
X    zbufbutton->label="z-buf";
X    zbufbutton->labeltype=PNL_LABEL_LEFT;
X    zbufbutton->x=4.5;
X    zbufbutton->y=(y-=dy);
X    zbufbutton->downfunc=setzbuf;
X    addact(zbufbutton,panel);
X
X    stopbutton=mkact(pnl_toggle_button);
X    stopbutton->label="stop (S)";
X    stopbutton->labeltype=PNL_LABEL_LEFT;
X    stopbutton->x=4.5;
X    stopbutton->y=(y-=dy);
X    stopbutton->key= SKEY;
X    addact(stopbutton,panel);
X
X    fullbutton=mkact(pnl_toggle_button);
X    fullbutton->label="full screen (F)";
X    fullbutton->labeltype=PNL_LABEL_LEFT;
X    fullbutton->x=4.5;
X    fullbutton->y=(y-=dy);
X    fullbutton->downfunc=togglefullscreen;
X    fullbutton->key=FKEY;
X    addact(fullbutton,panel);
X
X    positionpuck=mkact(pnl_floating_puck);
X    positionpuck->x=0.0;
X    positionpuck->y=1.5;
X    addact(positionpuck,panel);
X
X#define MK_EP_SLIDER(Mname,Mlabel,Mx,My,Mmin,Mmax,Mval,Mvar)	\
X    Mname/**/slider=mkact(pnl_dvslider);			\
X    Mname/**/slider->label=Mlabel;			\
X    Mname/**/slider->labeltype=PNL_LABEL_BOTTOM;	\
X    Mname/**/slider->x=(Mx);				\
X    Mname/**/slider->y=(My);				\
X    Mname/**/slider->val=(Mval);			\
X    Mname/**/slider->minval=(Mmin);			\
X    Mname/**/slider->maxval=(Mmax);			\
X    addact(Mname/**/slider,panel);				\
X							\
X    rb=PNL_MKUSERACT(resetbutton, pnl_wide_button);	\
X    rb->targetact=Mname/**/slider;			\
X    rb->targetvar=Mvar;					\
X    rb->varinitval=0.0;					\
X    rb->button.label="R";				\
X    rb->button.w=PNL_SLIDER_WIDTH;			\
X    rb->button.h=PNL_BUTTON_EDGE;			\
X    rb->button.x=Mx;					\
X    rb->button.y=(My)+PNL_SLIDER_HEIGHT+PNL_DIM_2;	\
X    rb->button.downfunc=resetact;			\
X    addact((Actuator *)rb, panel);
X
X
X    MK_EP_SLIDER(zoom,"zoom",	0.0,	3.5,	-0.5,	0.5,	0.0, NULL);
X    MK_EP_SLIDER(twist,"twst",	1.0,	3.5,	-100.0,	100.0,	0.0, NULL);
X    MK_EP_SLIDER(speed,"spd",	2.0,	3.5,	0.0,	1.0,	1.0, NULL);
X    MK_EP_SLIDER(n,"n",		3.0,	3.5,	1.0,NPNTS.0-1.0 ,32.0, NULL);
X    MK_EP_SLIDER(maprate,"rat", 4.0,	3.5,	-20.0,	20.0,	1.0, NULL);
X    MK_EP_SLIDER(maprange,"rng",5.0,	3.5,	0.0,	100.0,	1.0, NULL);
X
X    MK_EP_SLIDER(wheel,"whl",	0.0,	10.5,	-60.0,	60.0,	0.0, &wheel);
X    MK_EP_SLIDER(spin,"spn",	1.0,	10.5,	-20.0,	20.0,	0.0, &gspin);
X    rb->varinitval=15.0;	/* initial value for gspin */
X    resetact(rb);
X    MK_EP_SLIDER(flip,"flp",	2.0,	10.5,	-20.0,	20.0,	0.0, &gflip);
X    MK_EP_SLIDER(arm,"arm",	3.0,	10.5,	0.0,	3.0,	0.0, NULL);
X    MK_EP_SLIDER(wrist,"wrst",	4.0,	10.5,	0.0,	3.0,	0.0, NULL);
X    MK_EP_SLIDER(size,"sz",	5.0,	10.5,	0.1,	10.0,	1.0, NULL);
X
X}
X
SHAR_EOF
chmod 0644 ep.c || echo "restore of ep.c fails"
sed 's/^X//' << 'SHAR_EOF' > epslideroid.c &&
X/*
X *	this software is in the public domain, it may not be resold
X *	or relicensed.  Do not remove this notice.  Send modifications
X *	and requests for most recent version to:
X *
X *	Author:  David A. Tristram
X *		 NASA  Ames Research Center
X *		 MS 258-5
X *		 Moffett Field, CA  94035
X *		 415-694-4404
X *		 dat@orville.nas.nasa.gov
X */
X#include <math.h>
X#include <gl.h>
X#include <device.h>
X#include <panel.h>
X
X#define MAXCOLORS	4096	/* for simplicity just make the storage */
X				/* the size of the whole map */
X#define MARGIN		5
X#define WINSIZE		(YMAXSCREEN-(2*MARGIN))
X#define NPNTS		128
X#define BASECOLOR	512
X#define FATLINEWIDTH	3
X#define NORMALLINEWIDTH 1
X#define SQRT3	1.7320508
X
X#define ABS(x)	((x)<0?-(x):(x))
X
Xlong	/* position and size of regularscreen window */
X  regx = MARGIN,
X  regy = MARGIN,
X  regw = WINSIZE,
X  regh = WINSIZE;
X
Xint bkg=BLACK;	/* the background of the data window */
Xint n;	    /* what one are we drawing now? */
Xfloat t;    /* how far are we toward the next triangle? */
Xint nlimit; /* how many do we draw? */
Xint ncolors;/* how many colors do we get? */
Xint basecolor;/* lowest color that we use */
X
XPanel *panel;
X
XActuator *positionpuck, *speedslider, *zoomslider, *wheelslider, *twistslider,
X	 *flipslider, *spinslider, *armslider, *wristslider, *smearbutton,
X	 *zbufbutton, *smoothbutton, *outlinebutton, *sizeslider,
X	 *stopbutton, *fillbutton, *nslider, *fatlinebutton, *fullbutton,
X         *maprangeslider, *maprateslider, *fadebutton;
X
XActuator *spectrumbutton, *contourbutton, *bandbutton;
X
Xstruct resetbutton {
X    Actuator button;
X    Actuator *targetact;
X    float    *targetvar;
X    float    varinitval;
X};
X
Xvoid
Xload_spectrum_map()
X{
Xfloat h, s, v, r, g, b, x;
Xint i, ir, ig, ib;
X
X  x = 0.0;
X  for (i=0; i<ncolors; i++)
X    {
X/*      x = 2.0*(float)i / (float)ncolors;
X      hls_to_rgb (1.0-ABS(1.0-x), 0.5, 1.0, &r, &g, &b); */
X      x = (float)i / (float)ncolors;
X      hls_to_rgb (x, 0.5, 1.0, &r, &g, &b);
X      rgb_to_irgb (r, g, b, &ir, &ig, &ib);
X      mapcolor ((Colorindex)(basecolor+i), ir, ig, ib);
X    }
X}
X				    
Xvoid
Xload_contour_map(a) 
X  Actuator *a;
X{
Xfloat h, s, v, r, g, b, x, y;
Xint i, ir, ig, ib;
X
X  x = 0.0;
X  for (i=0; i<=ncolors; i++)
X    {
X      /* only want to go from red to violet, hence the "0.8" */
X      x = (float)i / ((float)ncolors);
X      /* quantize in 8 bands */
X      y = fmod(x, (0.85/7.99));
X      x = x - y;
X      hls_to_rgb (x, 6.5*y+0.1, 1.0, &r, &g, &b);
X      rgb_to_irgb (r, g, b, &ir, &ig, &ib);
X      mapcolor ((Colorindex)(basecolor+i), ir, ig, ib);
X    }
X}
X
X
X#define MAPBANDWIDTH 20
X#define MAPLINEWIDTH 4
X
Xvoid
Xload_band_map(a)
X  Actuator *a;
X{
X  int i;
X  load_spectrum_map(a);
X  for (i=MAPBANDWIDTH; i<(ncolors-MAPBANDWIDTH); i++)
X    {
X      if (i%MAPBANDWIDTH <= MAPLINEWIDTH)
X	mapcolor(basecolor+i, 0, 0, 0);
X    }
X   
X}
X
Xskew(x, y, z)
Xfloat x, y, z;
X{
X  static Matrix mat = {
X    {1.0, 0.0, 0.0, 0.0},
X    {0.0, 1.0, 0.0, 0.0},
X    {0.0, 0.0, 1.0, 0.0},
X    {0.0, 0.0, 0.0, 1.0}
X  };
X
X  mat[0][0] = 1.0+x;
X  mat[0][1] = y;
X  mat[1][2] = z;
X  multmatrix(mat);
X}
X
Xvoid
Xbeginscript()
X{
X  pnl_beginwritescript("panel.script");
X}
X
Xvoid
Xappendscript()
X{
X  pnl_beginappendscript("panel.script");
X}
X
Xvoid
Xendscript()
X{
X  pnl_endwritescript();
X}
X
Xvoid
Xreadscript()
X{
X  pnl_beginreadscript("panel.script");
X}
X
Xvoid
Xstopscript()
X{
X  pnl_endreadscript();
X}
X
Xvoid
Xresetact(b)
Xstruct resetbutton *b;
X{
X    if (b->targetact->val!=b->targetact->initval) {
X	b->targetact->val=b->targetact->initval;
X        fixact(b->targetact);
X    } else if (b->targetvar) {
X	*b->targetvar=b->varinitval;
X    }
X}
X
Xstatic short savR[MAXCOLORS], savG[MAXCOLORS], savB[MAXCOLORS];
X
Xsavecolors()
X{
Xint i;
X
X  for (i=0;i<ncolors;i++)
X    getmcolor(i+basecolor, &savR[i], &savG[i], &savB[i]);
X}
X
Xrestorecolors()
X{
Xint i;
X
X  for (i=0;i<ncolors;i++)
X    mapcolor(i+basecolor, savR[i], savG[i], savB[i]);
X}
X
Xvoid
Xcleanexit()
X{
X  restorecolors();
X  exit(0);
X}
X
Xvoid
Xsetsmooth(a)
XActuator *a;
X{
X  if (smearbutton->val==1.0) {
X    if (a->val==1.0) {
X      frontbuffer(FALSE);
X      backbuffer(TRUE);
X    } else {
X      frontbuffer(TRUE);
X      backbuffer(TRUE);
X    }
X  }
X}
X
Xvoid
Xsetsmear(a)
XActuator *a;
X{
X  if (a->val==1.0) {
X    if (smoothbutton->val!=1.0) {
X      if (stopbutton->val!=1.0) {
X	color(bkg);
X	clear();
X	drawit();
X      }
X      frontbuffer(TRUE);
X      backbuffer(TRUE);
X    }
X  } else {
X    frontbuffer(FALSE);
X    backbuffer(TRUE);
X  }
X}
X
Xvoid
Xsetzbuf(a)
XActuator *a;
X{
X    if (a->val!=1.0) {
X        zbuffer(FALSE);
X    } else {
X        zbuffer(TRUE);
X	zclear();
X    }
X}
X
Xvoid
Xfullscreen(a)
XActuator *a;
X{
X  if (stopbutton->val==1.0) {	/* a bit of a hack, but expressed nicely */
X    a->val=0.0;
X    fixact(a);
X    return;
X  }
X  getorigin(&regx, &regy);
X  getsize(&regw, &regh);
X  winposition(0, XMAXSCREEN, 0, YMAXSCREEN);
X  reshapeviewport();
X  perspective(300, (float)XMAXSCREEN/(float)YMAXSCREEN, 0.01, 10000.0);
X  polarview(10.0, 0, 0, 0);
X  setdepth(0x0000,0x3fff);
X  winpop();
X  color(bkg);
X  clear();
X  swapbuffers();
X  color(bkg);
X  clear();
X  swapbuffers();
X}  
X
Xvoid
Xregularscreen()
X{
X  fullbutton->val=0.0;
X  fixact(fullbutton);
X
X  winposition(regx, regx+regw, regy, regy+regh);
X  reshapeviewport();
X  perspective(300, 1.0, 0.01, 10000.0);
X  polarview(10.0, 0, 0, 0);
X  setdepth(0xc000,0x3fff);
X  
X  color(bkg);
X  clear();
X  swapbuffers();
X  panel->dirtycnt=2;
X  drawpanel();
X  color(bkg);
X  clear();
X  swapbuffers();
X}
X
Xfloat wheel, dwheel;
Xfloat *x, *y, *dzoom, *arm, *wrist, *dtwist, *flip, *spin;
XBoolean *outline, *fatline, *fill;
Xfloat *size;
Xfloat gflip, dflip, gspin, dspin, gcol;
Xfloat *maprange, *maprate;
XCoord square[][2] = {
X    {-0.1, -0.1},
X    { 0.1, -0.1},
X    { 0.1,  0.1},
X    {-0.1,  0.1}
X};
X  
XCoord triangle[][2] = {
X    { 0.0,  0.0 },
X    { 0.2,  0.0 },
X    { 0.1, SQRT3/10.0 }
X};
X
Xmain()
X{
X  Actuator *a;
X  Device dev;
X  short val;
X  int h, i, j, mexwin;
X  int itmp;
X  float tmp;
X  Boolean newn;
X
X  wheel=0.0;
X  x=(float *)calloc(NPNTS, sizeof(float));
X  y=(float *)calloc(NPNTS, sizeof(float));
X  dzoom=(float *)calloc(NPNTS, sizeof(float));
X  arm=(float *)calloc(NPNTS, sizeof(float));
X  wrist=(float *)calloc(NPNTS, sizeof(float));
X  dtwist=(float *)calloc(NPNTS, sizeof(float));
X  flip=(float *)calloc(NPNTS, sizeof(float));
X  spin=(float *)calloc(NPNTS, sizeof(float));
X  outline=(Boolean *)calloc(NPNTS, sizeof(Boolean));
X  fatline=(Boolean *)calloc(NPNTS, sizeof(Boolean));
X  fill=(Boolean *)calloc(NPNTS, sizeof(Boolean));
X  size=(float *)calloc(NPNTS, sizeof(float));
X  maprange=(float *)calloc(NPNTS, sizeof(float));
X  maprate=(float *)calloc(NPNTS, sizeof(float));
X  
X#ifdef DEBUG
X  foreground();
X#endif DEBUG
X  prefposition(regx, regx+regw, regy, regy+regh);
X  winopen("ep");
X  keepaspect(1, 1);
X  winconstraints();	/* make the window reshapeable */
X  winattach();
X  mexwin=winget();
X  
X  doublebuffer();
X  gconfig();
X
X  needredraw();
X  defpanel();
X
X  switch (getplanes()) {
X  case 4:
X    ncolors=15;
X    basecolor=1;
X    maprangeslider->minval=0.0;
X    maprangeslider->maxval=10.0;
X    fixact(maprangeslider);
X    pnl_background_color	= 8;
X    pnl_white_color		= 4;
X    pnl_normal_color		= 9;
X    pnl_other_color		= 7;
X    pnl_highlight_color		= 4;
X    pnl_outline_color		= 11;
X    break;
X  case 8:
X    ncolors=128;
X    basecolor=128;
X    break;
X  case 12:
X  default:
X    ncolors=128;
X    basecolor=512;
X    break;
X  }
X  savecolors();
X
X  load_spectrum_map();
X  color(bkg);
X  clear();
X  swapbuffers();
X  clear();
X  
X#ifdef IRIS_4D
X  shademodel(FLAT);
X  concave(FALSE);
X#endif IRIS_4D
X
X  perspective(300, 1.0, 0.01, 1000000.0);
X  polarview(10.0, 0, 0, 0);
X  /*   lookat(0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0); */
X  setdepth(0xc000,0x3fff);
X  
X  n=0;
X  t=0.0;
X  gcol=BASECOLOR+ncolors/2;
X
X  for (;;) {
X
X    a=dopanel();
X    if (stopbutton->val==1.0) {
X      if (smearbutton->val!=1.0) {
X        color(bkg);
X	clear();
X      }
X      drawit();
X      swapbuffers();
X      do {
X	a=dopanel();
X	if (!a) sginap(0);
X	swapbuffers();
X      } while (stopbutton->val==1.0);
X    }
X
X    if (fullbutton->val==1.0
X        && getbutton(LEFTMOUSE)) regularscreen();
X
X    t+=speedslider->val;
X    newn=FALSE;
X    if (t>=1.0) newn=TRUE;
X    n+=floor(t);
X    t=fmod(t,1.0);
X
X    x[n%NPNTS]=PNL_ACCESS(Puck,positionpuck,x);
X    y[n%NPNTS]=PNL_ACCESS(Puck,positionpuck,y);
X    dzoom[n%NPNTS]=zoomslider->val;
X    arm[n%NPNTS]=armslider->val;
X    wrist[n%NPNTS]=wristslider->val;
X    dwheel=speedslider->val*wheelslider->val;
X    dtwist[n%NPNTS]=twistslider->val;
X    nlimit=(int)nslider->val;
X    outline[n%NPNTS]=outlinebutton->val==1.0;
X    fatline[n%NPNTS]=fatlinebutton->val==1.0;
X    fill[n%NPNTS]=fillbutton->val==1.0;
X    size[n%NPNTS]=sizeslider->val;
X    maprange[n%NPNTS]=maprangeslider->val;
X    gcol+=speedslider->val*maprateslider->val;
X    while(gcol<basecolor) gcol+=ncolors;
X    while(gcol>=basecolor+ncolors) gcol-=ncolors;
X        
X    if (newn) {
X        dflip=flipslider->val;
X	dspin=spinslider->val;
X
X        gflip=fmod(gflip+dflip,360.0);
X	flip[n%NPNTS]=gflip;
X
X	gspin=fmod(gspin+dspin,360.0);
X	spin[n%NPNTS]=gspin;
X    }
X
X/*    winset(mexwin); */
X    if (userredraw()) {
X	reshapeviewport();
X	if (fullbutton->val==1.0) 
X	  perspective(300, (float)XMAXSCREEN/(float)YMAXSCREEN, 0.01, 10000.0);
X	else
X	  perspective(300, 1.0, 0.01, 10000.0);
X	polarview(10.0, 0, 0, 0);
X	setdepth(0xc000,0x3fff);
X    }
X
X    wheel=fmod(wheel-dwheel,360.0);
X/* fprintf(stderr, "wheel:%f  dwheel:%f\n", wheel, dwheel); */
X
X    if (smearbutton->val!=1.0) {
X        color(bkg);
X	clear();
X    } else {
X      if (fadebutton->val==1.0) fadebackground(bkg, 1);
X      if (smoothbutton->val==1.0) {
X	drawit();
X	swapbuffers();
X	if (fadebutton->val==1.0) fadebackground(bkg, 0);
X	drawpanel();
X      }
X    }
X
X    drawit();
X    swapbuffers();
X  }
X}
X
Xfloat
Xtwixt(i,x,t)
Xint i;
Xfloat *x;
Xfloat t;
X{
Xint j=i-1;
X
X    if (j<0) j+=NPNTS;
X    return x[i]*t+x[j]*(1.0-t);
X}
X
Xfloat
Xfoldtwixt(i,x,t)
Xint i;
Xfloat *x;
Xfloat t;
X{
X  float r;
X  float d;
X  int j=i-1;
X
X    if (j<0) j+=NPNTS;
X    d=x[i]-x[j];
X    if	    (d> 180.0) r=x[i]*t+(x[j]+360.0)*(1.0-t);
X    else if (d<-180.0) r=(x[i]+360.0)*t+x[j]*(1.0-t);
X    else	       r=x[i]*t+x[j]*(1.0-t);
X
X    return r;
X}
X
Xdrawit()
X{
Xint i,j;
Xint outlinecolor;
Xfloat tx,ty,tdzoom,tarm,twrist,tsize;
Xfloat tspin,tflip,tdtwist;
Xfloat col;
X
X    if (zbufbutton->val==1.0) zclear();
X    col=gcol;
X
X    pushmatrix();
X#ifdef IRIS_4D
X    rot(wheel, 'x');
X#else
X    rotate((int)(10.0*wheel), 'x');
X#endif
X
X    for (i=n;i>n-nlimit;i--) {
X      j=i%NPNTS;
X      if (j<0) j+=NPNTS;
X      if (j>NPNTS-1) j-=NPNTS;
X
X      tx=twixt(j,x,t);
X      ty=twixt(j,y,t);
X      tdzoom=twixt(j,dzoom,t);
X      tarm=twixt(j,arm,t);
X      twrist=twixt(j,wrist,t);
X      tsize=twixt(j,size,t);
X      tspin=foldtwixt(j,spin,t);
X      tflip=foldtwixt(j,flip,t);
X      tdtwist=twixt(j,dtwist,t);
X
X      color((int)col);
X      if (outline[j]) {
X	outlinecolor=((int)col+ncolors/2);
X	if (outlinecolor>=basecolor+ncolors) outlinecolor-=ncolors;
X      }
X      col-=maprange[j];
X      while(col<basecolor) col+=ncolors;
X      while(col>=basecolor+ncolors) col-=ncolors;
X
X      if (fatline[j]) {
X	linewidth(FATLINEWIDTH);
X      } else {
X	linewidth(NORMALLINEWIDTH);
X      }
X      
X      pushmatrix();
X      translate(tx, ty, 0.0);
X#ifdef IRIS_4D
X      rot(tspin, 'z');
X#else  IRIS_4D
X      rotate((int)(10.0*tspin), 'z');
X#endif IRIS_4D
X      translate(0.0,tarm,0.0);
X#ifdef IRIS_4D
X      rot(tflip, 'y');
X#else  IRIS_4D
X      rotate((int)(10.0*tflip), 'y');
X#endif IRIS_4D
X      translate(twrist,0.0,0.0);
X      scale(tsize,tsize,1.0);
X      if (fill[j]) polf2(3, triangle);
X      if (outline[j]) {
X	  color(outlinecolor);
X	  poly2(3, triangle);
X          color((int)col);
X      }
X      popmatrix();
X
X      scale(1.0, -1.0, 1.0);
X
X      pushmatrix();
X      translate(tx, ty, 0.0);
X#ifdef IRIS_4D
X      rot(tspin, 'z');
X#else  IRIS_4D
X      rotate((int)(10.0*tspin), 'z');
X#endif IRIS_4D
X      translate(0.0,tarm,0.0);
X#ifdef IRIS_4D
X      rot(tflip, 'y');
X#else  IRIS_4D
X      rotate((int)(10.0*tflip), 'y');
X#endif IRIS_4D
X      translate(twrist,0.0,0.0);
X      scale(tsize,tsize,1.0);
X      if (fill[j]) polf2(3, triangle);
X      if (outline[j]) {
X	  color(outlinecolor);
X	  poly2(3, triangle);
X          color((int)col);
X      }
X      popmatrix();
X
X#ifdef IRIS_4D
X      rot(180.0, 'z');
X#else  IRIS_4D
X      rotate((int)(10.0*180.0), 'z');
X#endif IRIS_4D
X
X      pushmatrix();
X      translate(tx, ty, 0.0);
X#ifdef IRIS_4D
X      rot(tspin, 'z');
X#else  IRIS_4D
X      rotate((int)(10.0*tspin), 'z');
X#endif IRIS_4D
X      translate(0.0,tarm,0.0);
X#ifdef IRIS_4D
X      rot(tflip, 'y');
X#else  IRIS_4D
X      rotate((int)(10.0*tflip), 'y');
X#endif IRIS_4D
X      translate(twrist,0.0,0.0);
X      scale(tsize,tsize,1.0);
X      if (fill[j]) polf2(3, triangle);
X      if (outline[j]) {
X	  color(outlinecolor);
X	  poly2(3, triangle);
X          color((int)col);
X      }
X      popmatrix();
X
X      scale(1.0, -1.0, 1.0);
X
X      pushmatrix();
X      translate(tx, ty, 0.0);
X#ifdef IRIS_4D
X      rot(tspin, 'z');
X#else  IRIS_4D
X      rotate((int)(10.0*tspin), 'z');
X#endif IRIS_4D
X      translate(0.0,tarm,0.0);
X#ifdef IRIS_4D
X      rot(tflip, 'y');
X#else  IRIS_4D
X      rotate((int)(10.0*tflip), 'y');
X#endif IRIS_4D
X      translate(twrist,0.0,0.0);
X      scale(tsize,tsize,1.0);
X      if (fill[j]) polf2(3, triangle);
X      if (outline[j]) {
X	  color(outlinecolor);
X	  poly2(3, triangle);
X          color((int)col);
X      }
X      popmatrix();
X
X#ifdef IRIS_4D
X      rot(tdtwist, 'z');
X#else  IRIS_4D
X      rotate((int)(10.0*tdtwist), 'z');
X#endif IRIS_4D
X      translate(0.0, 0.0, tdzoom);
X    
X    }
X    popmatrix();
X}
X
Xdefpanel()
X{
XActuator *a;
XSlideroid *ad;
X
X    panel=mkpanel();
X    panel->label="scripting";
X
X    a=mkact(pnl_button);
X    a->label="dump state";
X    a->x=1.0;
X    a->y=4.5;
X    a->downfunc=dumpstate;
X    addact(a, panel);
X
X    a=mkact(pnl_button);
X    a->label="begin script";
X    a->x=1.0;
X    a->y=4.0;
X    a->downfunc=beginscript;
X    addact(a, panel);
X
X    a=mkact(pnl_button);
X    a->label="end script";
X    a->x=1.0;
X    a->y=3.5;
X    a->downfunc=endscript;
X    addact(a, panel);
X
X    a=mkact(pnl_button);
X    a->label="append to script";
X    a->x=1.0;
X    a->y=3.0;
X    a->downfunc=appendscript;
X    addact(a, panel);
X
X    a=mkact(pnl_button);
X    a->label="read script";
X    a->x=1.0;
X    a->y=2.5;
X    a->downfunc=readscript;
X    addact(a, panel);
X
X    a=mkact(pnl_button);
X    a->label="stop reading script";
X    a->x=1.0;
X    a->y=2.0;
X    a->downfunc=stopscript;
X    addact(a, panel);
X
X
X    panel=mkpanel();
X#ifdef IRIS_4D
X    panel->ppu=50.0;
X#else
X    panel->ppu=45.0;
X#endif
X    panel->label="electro-paint";
X
X    a=mkact(pnl_label);
X    a->x=0.2;
X    a->y=17.5;
X    a->label="...by Dave Tristram";
X    addact(a,panel);
X
X    a=mkact(pnl_wide_button);
X    a->x=0.0;
X    a->y=0.0;
X    a->label="exit";
X    a->upfunc=cleanexit;
X    addact(a,panel);
X
X    outlinebutton=mkact(pnl_toggle_button);
X    outlinebutton->label="outline";
X    outlinebutton->labeltype=PNL_LABEL_LEFT;
X    outlinebutton->x=3.5;
X    outlinebutton->y=2.5;
X    addact(outlinebutton,panel);
X
X    fatlinebutton=mkact(pnl_toggle_button);
X    fatlinebutton->label="fat lines";
X    fatlinebutton->labeltype=PNL_LABEL_LEFT;
X    fatlinebutton->x=3.5;
X    fatlinebutton->y=2.0;
X    addact(fatlinebutton,panel);
X
X    fillbutton=mkact(pnl_toggle_button);
X    fillbutton->label="fill";
X    fillbutton->labeltype=PNL_LABEL_LEFT;
X    fillbutton->x=3.5;
X    fillbutton->y=1.5;
X    fillbutton->val=1.0;
X    addact(fillbutton,panel);
X
X    smoothbutton=mkact(pnl_toggle_button);
X    smoothbutton->label="smooth";
X    smoothbutton->labeltype=PNL_LABEL_LEFT;
X    smoothbutton->x=3.5;
X    smoothbutton->y=1.0;
X    smoothbutton->downfunc=setsmooth;
X    addact(smoothbutton,panel);
X
X    smearbutton=mkact(pnl_toggle_button);
X    smearbutton->label="smear";
X    smearbutton->labeltype=PNL_LABEL_LEFT;
X    smearbutton->x=3.5;
X    smearbutton->y=0.5;
X    smearbutton->downfunc=setsmear;
X    addact(smearbutton,panel);
X
X    fadebutton=mkact(pnl_toggle_button);
X    fadebutton->label="fade";
X    fadebutton->labeltype=PNL_LABEL_LEFT;
X    fadebutton->x=3.5;
X    fadebutton->y=0.0;
X    addact(fadebutton,panel);
X
X    zbufbutton=mkact(pnl_toggle_button);
X    zbufbutton->label="z-buf";
X    zbufbutton->labeltype=PNL_LABEL_LEFT;
X    zbufbutton->x=3.5;
X    zbufbutton->y=0.0;
X    zbufbutton->downfunc=setzbuf;
X/*    addact(zbufbutton,panel); */
X
X    stopbutton=mkact(pnl_toggle_button);
X    stopbutton->label="stop";
X    stopbutton->labeltype=PNL_LABEL_LEFT;
X    stopbutton->x=3.5;
X    stopbutton->y= -0.5;
X    addact(stopbutton,panel);
X
X    fullbutton=mkact(pnl_toggle_button);
X    fullbutton->label="full screen";
X    fullbutton->labeltype=PNL_LABEL_LEFT;
X    fullbutton->x=3.5;
X    fullbutton->y= -1.0;
X    fullbutton->downfunc=fullscreen;
X    addact(fullbutton,panel);
X
X    positionpuck=mkact(pnl_floating_puck);
X    positionpuck->x=0.0;
X    positionpuck->y=1.5;
X    addact(positionpuck,panel);
X
X#define MK_EP_SLIDEROID(Mname,Mlabel,Mx,My,Mmin,Mmax,Mval,Mvar)	\
X    Mname/**/slider=mkact(pnl_slideroid);			\
X    Mname/**/slider->label=Mlabel;			\
X    Mname/**/slider->labeltype=PNL_LABEL_BOTTOM;	\
X    Mname/**/slider->x=(Mx);				\
X    Mname/**/slider->y=(My);				\
X    Mname/**/slider->val=(Mval);			\
X    Mname/**/slider->minval=(Mmin);			\
X    Mname/**/slider->maxval=(Mmax);			\
X    ad=(Slideroid *)Mname/**/slider->data;		\
X    ad->resettarget=Mvar;				\
X    ad->resetval=Mval;					\
X    addact(Mname/**/slider,panel);
X
X
X    MK_EP_SLIDEROID(zoom,"zoom",  0.0, 3.5, -0.5,   0.5,	0.0, NULL);
X    MK_EP_SLIDEROID(twist,"twist",0.0, 5.5, -100.0, 100.0,	0.0, NULL);
X    MK_EP_SLIDEROID(speed,"speed",0.0, 7.5, 0.0,    1.0,	1.0, NULL);
X    MK_EP_SLIDEROID(n,"n",	  0.0, 9.5, 1.0,NPNTS.0-1.0 ,32.0, NULL);
X    MK_EP_SLIDEROID(maprate,"rate",0.0,11.5, -20.0,  20.0,	1.0, NULL);
X    MK_EP_SLIDEROID(maprange,"range",0.0, 13.5, 0.0,    100.0,	1.0, NULL);
X
X    MK_EP_SLIDEROID(wheel,"wheel",2.0, 3.5, -60.0, 60.0,	0.0, &wheel);
X    MK_EP_SLIDEROID(spin,"spin",  2.0, 5.5, -20.0, 20.0,	0.0, &gspin);
X    gspin=((Slideroid *)spinslider->data)->resetval=15.0;
X    MK_EP_SLIDEROID(flip,"flip",  2.0, 7.5, -20.0, 20.0,	0.0, &gflip);
X    MK_EP_SLIDEROID(arm,"arm",	  2.0, 9.5, 0.0,   3.0,	0.0, NULL);
X    MK_EP_SLIDEROID(wrist,"wrist",2.0, 11.5, 0.0,   3.0,	0.0, NULL);
X    MK_EP_SLIDEROID(size,"size",  2.0, 13.5, 0.1,   10.0,	1.0, NULL);
X
X}
X
SHAR_EOF
chmod 0644 epslideroid.c || echo "restore of epslideroid.c fails"
sed 's/^X//' << 'SHAR_EOF' > eric.c &&
X/*
X *	this software is in the public domain, it may not be resold
X *	or relicensed.  Do not remove this notice.  Send modifications
X *	and requests for most recent version to:
X *
X *	Author:  David A. Tristram
X *		 NASA  Ames Research Center
X *		 MS 258-5
X *		 Moffett Field, CA  94035
X *		 415-694-4404
X *		 dat@orville.nas.nasa.gov
X */
X#include <gl.h>
X#include <device.h>
X#include </usr/local/include/panel.h>
X
XActuator *hs, *vs;
X
XPanel
X*defpanel1(), *defpanel2(), *defpanel3();
X
Xmain () 
X{
X  short col;
X
X  foreground ();
X  winopen ("demo");
X  doublebuffer ();
X  gconfig ();
X
X  ortho2 (-1.0,1.0,-1.0,1.0);
X
X  defpanel1 ();
X  defpanel2 ();
X  defpanel3 ();
X
X  color (RED);
X
X  for (;;) {
X    (void) dopanel ();
X    pushmatrix ();
X    translate (hs->val,vs->val,0.0);
X    col = getcolor ();
X    color (BLACK);
X    clear ();
X    color (col);
X    rectf (-.10,-.10,.10,.10);
X    swapbuffers ();
X    popmatrix ();
X  }
X}
X
X
Xtypedef void (*PFV)();
X
Xstruct button_hook
X{
X  Actuator act;
X  Actuator *button;
X};
X
Xset_my_button (b)
X     struct button_hook *b;
X{
X  b->button->val = b->act.val;
X  b->button->dirtycnt = 2;
X}
X
XPanel
X*defpanel1 ()
X{
X  Panel *panel;
X  Actuator *slave;
X  struct button_hook *master;
X
X  panel=mkpanel ();
X  panel->label="panel one";
X  panel->ppu=50.0;
X
X  hs = mkact (PNL_HSLIDER);
X  hs->label	= "y position";
X  hs->x		=  1.0;
X  hs->y		=  0.0;
X  hs->minval	= -1.0;
X  hs->maxval	=  1.0;
X  addact (hs, panel);
X
X  slave = mkact (PNL_TOGGLE_BUTTON);
X  slave->label	= "I push myself";
X  slave->x	= 1.0;
X  slave->y	= 2.0;
X  addact (slave, panel);
X
X  master = PNL_MKUSERACT (button_hook, PNL_TOGGLE_BUTTON);
X  master->button	= slave;
X  master->act.label	= "push me";
X  master->act.x	 	= 1.0;
X  master->act.y	 	= 1.5;
X  master->act.downfunc	= (PFV) set_my_button;
X  addact (master, panel);
X
X  return panel;
X}
X
Xclean_exit ()
X{
X  exit (0);
X}
X
XPanel
X*defpanel2 ()
X{
X  Panel *panel;
X  Actuator *tem;
X
X  panel = mkpanel ();
X  panel->label	= "panel two";
X  panel->ppu	= 50.0;
X
X  vs = mkact (PNL_VSLIDER);
X  vs->label	= "x position";
X  vs->x		= 0.0;
X  vs->y		= 0.0;
X  vs->minval	=  -1.0;
X  vs->maxval	= 1.0;
X  addact (vs, panel);
X
X  tem = mkact (PNL_BUTTON);
X  tem->label	= "dumppanel";
X  tem->x	= 1.0;
X  tem->y	= 1.5;
X  tem->downfunc = (void (*)()) dumppanel;
X  addact (tem, panel);
X
X  tem = mkact (PNL_BUTTON);
X  tem->label	= "exit";
X  tem->x	= 1.0;
X  tem->y	= 1.0;
X  tem->downfunc = (void (*)()) clean_exit;
X  addact (tem, panel);
X
X  return panel;
X}
X
Xstruct color_struct
X{
X  Actuator act;
X  Colorindex color;
X} *cs;
X
Xset_color_func (cs)
X struct color_struct *cs;
X{
X  color (cs->color);
X}
X
XPanel
X*defpanel3 ()
X{
X  Panel *panel;
X
X  panel	= mkpanel ();
X  panel->label	= "panel three";
X  panel->ppu	= 50.0;
X
X#define MAKE_COLOR_BUTTON(_color, _label, _x, _y, _val)	\
X  cs = PNL_MKUSERACT (color_struct, PNL_RADIO_BUTTON);	\
X  cs->color	= _color;				\
X  cs->act.label	= _label;				\
X  cs->act.x	= _x;					\
X  cs->act.y	= _y;					\
X  cs->act.val	= _val;					\
X  cs->act.downfunc = (void (*)()) set_color_func;	\
X  addact (cs, panel)
X
X  MAKE_COLOR_BUTTON (RED,   "red",   1.0, 2.0, 1.0);
X  MAKE_COLOR_BUTTON (GREEN, "green", 1.0, 1.5, 0.0);
X  MAKE_COLOR_BUTTON (CYAN, " cyan",  1.0, 1.0, 0.0);
X
X  return panel;
X}
SHAR_EOF
chmod 0644 eric.c || echo "restore of eric.c fails"
sed 's/^X//' << 'SHAR_EOF' > fade.c &&
X/*
X *	this software is in the public domain, it may not be resold
X *	or relicensed.  Do not remove this notice.  Send modifications
X *	and requests for most recent version to:
X *
X *	Author:  David A. Tristram
X *		 NASA  Ames Research Center
X *		 MS 258-5
X *		 Moffett Field, CA  94035
X *		 415-694-4404
X *		 dat@orville.nas.nasa.gov
X */
X/*
X *	fade - 
X *		Make a background that fades windows out using a special
X *		pixel hack.
X *
X *				Paul Haeberli - 1985
X *
X */
X#include "gl.h"
X#include "device.h"
X
Xshort tex[16];
Xint slow;
X
Xstatic int shifts[16] = {
X    0, 2, 2, 0,
X    1, 3, 3, 1,
X    0, 2, 2, 0,
X    1, 3, 3, 1,
X};
X
Xstatic int wheres[16] = {
X    0, 2, 0, 2,
X    1, 3, 1, 3,
X    1, 3, 1, 3,
X    0, 2, 0, 2,
X};
X
X/* bkg-  the color you want to fade to
X * adv-  1 to advance to the next texture (the normal case)
X *	 0 to remain at the same one (for the back buffer, say)
X */
X
Xfadebackground(bkg, adv)
XColorindex bkg;
Xint adv;
X{
Xstatic int state;
X
X    int i, k;
X    static int texno;
X    register int shift, where, pattern;
X
X    texno+=adv;
X/*    texno=rand()%16;  band mode */
X
X    while (texno>=16) texno -= 16; 
X    for (i=0; i<16; i++)
X      tex[i] = 0;
X    shift = shifts[texno]; 	
X    where = wheres[texno]; 	
X    pattern = 0x1111<<shift;
X    tex[where+0] = pattern;
X    tex[where+4] = pattern;
X    tex[where+8] = pattern;
X    tex[where+12] = pattern;
X    defpattern(2,16,tex);	/* define a pattern */
X    color(bkg);
X    setpattern(2);
X    clear();
X    setpattern(0);
X}
SHAR_EOF
chmod 0644 fade.c || echo "restore of fade.c fails"
sed 's/^X//' << 'SHAR_EOF' > g_gets.c &&
X/*
X *	this software is in the public domain, it may not be resold
X *	or relicensed.  Do not remove this notice.  Send modifications
X *	and requests for most recent version to:
X *
X *	Author:  David A. Tristram
X *		 NASA  Ames Research Center
X *		 MS 258-5
X *		 Moffett Field, CA  94035
X *		 415-694-4404
X *		 dat@orville.nas.nasa.gov
X */
X/*
X * g_gets.c	: How to read a string from the keyboard without a textport.
X *
X * char *g_gets(stringcolor, backcolor, cursorcolor)
X *		    			         returns stuff like gets() does
X * Colorindex stringcolor, backcolor, cursorcolor;
X *	
X */
X#include <stdio.h>
X#include <gl.h>
X#include <device.h>
X
X#define MAXSTRINGLEN 	80
X#define MAXQUEUED 	100
X#define MAXEVENTS	100
X#define MAXDEVICES 	1024
X#define RESET		-3
X#define ERASE   	-2
X#define QUIT		-1
X
Xstatic int numqueued = 0;
Xstatic int numevents = 0;
Xstatic int qstack[MAXQUEUED];
Xstatic struct {
X    Device dev;
X    short data;
X} eventq[MAXEVENTS];
Xstatic long buf_state;
X
Xtypedef struct {
X    int device_num;
X    char lower;
X    char upper;
X} KEY ;
X
Xstatic KEY keyboard[] = 
X{
X    {	 AKEY,		'a',	'A' },
X    {	 BKEY,		'b',    'B' },
X    {	 CKEY,		'c',    'C' },
X    {	 DKEY,		'd',    'D' },
X    {	 EKEY,		'e',    'E' },
X    {	 FKEY,		'f',    'F' },
X    {	 GKEY,		'g',    'G' },
X    {	 HKEY,		'h',    'H' },
X    {	 IKEY,		'i',    'I' },
X    {	 JKEY,		'j',    'J' },
X    {	 KKEY,		'k',    'K' },
X    {	 LKEY,		'l',    'L' },
X    {	 MKEY,		'm',    'M' },
X    {	 NKEY,		'n',    'N' },
X    {	 OKEY,		'o',    'O' },
X    {	 PKEY,		'p',    'P' },
X    {	 QKEY,		'q',    'Q' },
X    {	 RKEY,		'r',    'R' },
X    {	 SKEY,		's',    'S' },
X    {	 TKEY,		't',    'T' },
X    {	 UKEY,		'u',    'U' },
X    {	 VKEY,		'v',    'V' },
X    {	 WKEY,		'w',    'W' },
X    {	 XKEY,		'x',    'X' },
X    {	 YKEY,		'y',    'Y' },
X    {	 ZKEY,		'z',    'Z' },
X    {	 ZEROKEY,	'0',    ')' },
X    {	 ONEKEY,	'1',    '!' },
X    {	 TWOKEY,	'2',    '@' },
X    {	 THREEKEY,	'3',    '#' }, 
X    {	 FOURKEY,	'4',    '$' }, 
X    {	 FIVEKEY,	'5',    '%' }, 
X    {	 SIXKEY,	'6',    '^' }, 
X    {	 SEVENKEY,	'7',    '&' }, 
X    {	 EIGHTKEY,	'8',    '*' }, 
X    {	 NINEKEY,	'9',    '(' },
X    { 	 SEMICOLONKEY,	';',    ':' },
X    {	 PERIODKEY,	'.',    '>' },
X    {	 COMMAKEY,	',',    '<' },
X    {	 ACCENTGRAVEKEY,'`',    '~' },
X    {	 MINUSKEY,	'-',    '_' },
X    {	 QUOTEKEY,	'\'',    '"' },
X    {	 BACKSLASHKEY,	'\\',    '|' },
X    {	 EQUALKEY,	'=',    '+' },
X    {	 LEFTBRACKETKEY,'[',    '{' },
X    {	 RIGHTBRACKETKEY,']',   '}' },
X    {	 VIRGULEKEY,	'/',	'?' },
X    {	 SPACEKEY,	' ',    '\0' },
X    {	 TABKEY,	'\t',    '\0' },
X    {	 RETKEY,	'\r',    '\0' },
X    {	 LINEFEEDKEY,	'\n',    '\0' },
X    {	 BREAKKEY,	'\0',    '\0' },
X    {	 BACKSPACEKEY,	'\b',    '\0' },
X    {	 DELKEY,	'\0',    '\0' },
X    {	 SETUPKEY,	'\0',    '\0' },
X    {	 CTRLKEY,	'\0',    '\0' },
X    {	 CAPSLOCKKEY,	'\0',    '\0' },
X    {	 RIGHTSHIFTKEY,	'\0',    '\0' },
X    {	 LEFTSHIFTKEY,	'\0',    '\0' },
X    {	 NOSCRLKEY,	'\0',    '\0' },
X    {	 ESCKEY,	'\0',    '\0' },
X    {	 LEFTARROWKEY,	'\0',    '\0' },
X    {	 DOWNARROWKEY,	'\0',    '\0' },
X    {	 RIGHTARROWKEY,	'\0',    '\0' },
X    {	 UPARROWKEY,	'\0',    '\0' },
X    {	 -1,		'\0',    '\0' } 
X};
X
X
XScreencoord ix, iy;
Xint char_width;
Xint char_height;
Xint char_descender;
Xint capitalize, controlize;
Xstatic char string[MAXSTRINGLEN];
X
X/*-----------------------------------------------------------------------*/
Xchar *g_gets(stringcolor, backcolor, cursorcolor)
X		   /* do a gets without using textports ..echoing the    */
X		   /* character on the screen, erasing when necessary    */
X/*-----------------------------------------------------------------------*/
XColorindex stringcolor, backcolor, cursorcolor;
X{
Xchar *g_getstring();
X
X    return g_getstring(stringcolor, backcolor, "", MAXSTRINGLEN);
X}
X
X
X/*-----------------------------------------------------------------------*/
SHAR_EOF
echo "End of part 3, continue with part 4"
echo "4" > s2_seq_.tmp
exit 0