#ifdef SCCS
static char sccsid[]="@(#)plcube.c	1.1 Oki 93/05/18";
#endif
/*
 * plogo.c - PEXlib logo
   cc -o plcube plcube.c -lPEX5 -lm -lX11                    -lnsl
   
			Copyright (c) 1992, 1993 by 
			Oki Electric Industry Co., Ltd.
			All Rights Reserved
	
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose and without fee is hereby granted,
 * provided that the above copyright notice appear in all copies and that
 * both that copyright notice and this permission notice appear in
 * supporting documentation, and that the name of Oki not be
 * used in advertising or publicity pertaining to distribution of the
 * software without specific, written prior permission. Oki
 * makes no representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
*/

#define NeedFunctionPrototypes 1

#include <X11/Xlib.h>
#include <X11/PEX5/PEXlib.h>

#define SET_POINT(p,a,b,c) {(p)->x=(a);(p)->y=(b);(p)->z=(c);}

#define RADIAN(x) ((x)*(3.1415927 / 180.0))


PEXColorRGB red     = {1,0,0};
PEXColorRGB green   = {0,1,0};
PEXColorRGB blue    = {0,0,1};
PEXColorRGB cyan    = {0,1,1};
PEXColorRGB magenta = {1,0,1};
PEXColorRGB yellow  = {1,1,0};

PEXColorRGB purple  = {1,0,0.8};

Display		*theDisplay;
PEXStructure     theStrux;

main (argc, argv)
     int argc;
     char  *argv[];
{
  char			*displayString = (char *)0;
  PEXExtensionInfo	*info_return;
  char			err_msg[PEXErrorStringLength];
  int                   i;
  PEXCoord p[2];
  PEXCoord verts[30], *pts;
  PEXVector normals[30], *ns;
  PEXArrayOfFacetData fData;
  PEXArrayOfVertex vData;

  PEXVector shift, scale;
  PEXMatrix bldmat, scaleMatrix;
  PEXCoord  pt;
  double x_ang, y_ang, z_ang;

  for ( i = 1; i<argc; i++ ) {
    if ((strncmp(argv[i],"-display",strlen(argv[i]))) == 0) {
      if (++i > argc) { printf("not enough args"); exit(1); }
      displayString = argv[i];
    } else if ((strncmp(argv[i],"-strux",strlen(argv[i]))) == 0) {
      if (++i > argc) { printf("not enough args"); exit(1); }
      theStrux = atoi(argv[i]);
    }
  }

  /*
   * Open the display and initialize the PEX extension.
   */
  
  if (!(theDisplay = XOpenDisplay(displayString)))
    {
      printf ( "Could not open display %s\n",displayString);
      exit (1);
    }
  
  if (PEXInitialize(theDisplay, &info_return, PEXErrorStringLength, err_msg))
    {
      printf ("%s\n", err_msg);
      exit (1);	    
    }

  PEXSetLineColorIndex( theDisplay, theStrux, PEXOCStore, 2);
  p[0].x = -3; p[0].y = -2; p[0].z = 0;
  p[1].x = 3; p[1].y = -2; p[1].z = 0;
  PEXPolyline(theDisplay, theStrux, PEXOCStore, 2, p );

  scale.x = 0.7; scale.y = -0.7; scale.z = 0.7;
  PEXScale(&scale,scaleMatrix);
  shift.x = -3; shift.y = 0; shift.z = 0;
  PEXTranslate(&shift,bldmat);
  PEXMatrixMult( scaleMatrix, bldmat, bldmat );

  PEXSetLocalTransform( theDisplay, theStrux, PEXOCStore,
                      PEXPreConcatenate, bldmat);
  PutPEXlib();
  
  XSync(theDisplay,0); /* must sync before we exit, we care about the strux */
}


PutPEXlib()
{
  PEXCoord points[30], *pts;
  PEXListOfCoord lop[2];
  
  pts = points;
  
  pts->x = 0.1434; pts->y = 1.625; pts->z = -0.1; pts++;
  pts->x = 0.1434; pts->y = 0.92486; pts->z = -0.1; pts++;
  pts->x = 0.39947; pts->y = 0.92486; pts->z = -0.1; pts++;
  pts->x = 0.39947; pts->y = 1.625; pts->z = -0.1; pts++;
  
  PEXSetSurfaceColor(  theDisplay, theStrux, PEXOCStore,
		     PEXColorTypeRGB, (PEXColor *)&red );
  
  PEXFillArea(  theDisplay, theStrux, PEXOCStore,
	      PEXShapeComplex, True, 4, points );
  
  pts = points;
  
  pts->x = 0.1434; pts->y = 0.87487; pts->z = -0.1; pts++;
  pts->x = 0.1434; pts->y = 0.77489; pts->z = -0.1; pts++;
  pts->x = 0.61286; pts->y = 0.77489; pts->z = -0.1; pts++;
  pts->x = 0.7409; pts->y = 0.7249; pts->z = -0.1; pts++;
  pts->x = 0.82625; pts->y = 0.67491; pts->z = -0.1; pts++;
  pts->x = 0.86893; pts->y = 0.57492; pts->z = -0.1; pts++;
  pts->x = 0.86893; pts->y = 0.42495; pts->z = -0.1; pts++;
  pts->x = 0.82625; pts->y = 0.32497; pts->z = -0.1; pts++;
  pts->x = 0.7409; pts->y = 0.27498; pts->z = -0.1; pts++;
  pts->x = 0.61286; pts->y = 0.22499; pts->z = -0.1; pts++;
  pts->x = 0.39947; pts->y = 0.22499; pts->z = -0.1; pts++;
  pts->x = 0.39947; pts->y = 0.7249; pts->z = -0.1; pts++;
  pts->x = 0.1434; pts->y = 0.7249; pts->z = -0.1; pts++;
  pts->x = 0.1434; pts->y = 0.125; pts->z = -0.1; pts++;
  pts->x = 0.7409; pts->y = 0.125; pts->z = -0.1; pts++;
  pts->x = 0.91161; pts->y = 0.17499; pts->z = -0.1; pts++;
  pts->x = 0.99697; pts->y = 0.22499; pts->z = -0.1; pts++;
  pts->x = 1.08232; pts->y = 0.32497; pts->z = -0.1; pts++;
  pts->x = 1.125; pts->y = 0.42495; pts->z = -0.1; pts++;
  pts->x = 1.125; pts->y = 0.57492; pts->z = -0.1; pts++;
  pts->x = 1.08232; pts->y = 0.67491; pts->z = -0.1; pts++;
  pts->x = 0.99697; pts->y = 0.77489; pts->z = -0.1; pts++;
  pts->x = 0.91161; pts->y = 0.82488; pts->z = -0.1; pts++;
  pts->x = 0.7409; pts->y = 0.87487; pts->z = -0.1; pts++;
  
  PEXSetSurfaceColor(  theDisplay, theStrux, PEXOCStore,
		     PEXColorTypeRGB, (PEXColor *)&red );
  
  
  PEXFillArea(  theDisplay, theStrux, PEXOCStore,
	      PEXShapeComplex, True, 24, points );
  
  pts = points;
  
  pts->x = 1.25; pts->y = 1.625; pts->z = -0.1; pts++;
  pts->x = 1.25; pts->y = 0.92512; pts->z = -0.1; pts++;
  pts->x = 1.50608; pts->y = 0.92512; pts->z = -0.1; pts++;
  pts->x = 1.50608; pts->y = 1.52499; pts->z = -0.1; pts++;
  pts->x = 2.14625; pts->y = 1.52499; pts->z = -0.1; pts++;
  pts->x = 2.14625; pts->y = 1.625; pts->z = -0.1; pts++;
  
  PEXSetSurfaceColor(  theDisplay, theStrux, PEXOCStore,
		     PEXColorTypeRGB, (PEXColor *)&green );
  
  
  PEXFillArea(  theDisplay, theStrux, PEXOCStore,
	      PEXShapeComplex, True, 6, points );
  
  pts = points;
  
  pts->x = 1.25; pts->y = 0.87513; pts->z = -0.1; pts++;
  pts->x = 1.25; pts->y = 0.77514; pts->z = -0.1; pts++;
  pts->x = 2.14625; pts->y = 0.77514; pts->z = -0.1; pts++;
  pts->x = 2.14625; pts->y = 0.87513; pts->z = -0.1; pts++;
  
  PEXSetSurfaceColor(  theDisplay, theStrux, PEXOCStore,
		     PEXColorTypeRGB, (PEXColor *)&green );
  
  
  PEXFillArea(  theDisplay, theStrux, PEXOCStore,
	      PEXShapeComplex, True, 4, points );
  
  pts = points;
  
  pts->x = 1.25; pts->y = 0.72376; pts->z = -0.1; pts++;
  pts->x = 1.25; pts->y = 0.12386; pts->z = -0.1; pts++;
  pts->x = 2.14625; pts->y = 0.12386; pts->z = -0.1; pts++;
  pts->x = 2.14625; pts->y = 0.22385; pts->z = -0.1; pts++;
  pts->x = 1.50608; pts->y = 0.22385; pts->z = -0.1; pts++;
  pts->x = 1.50608; pts->y = 0.72376; pts->z = -0.1; pts++;
  
  PEXSetSurfaceColor(  theDisplay, theStrux, PEXOCStore,
		     PEXColorTypeRGB, (PEXColor *)&green );
  
  
  PEXFillArea(  theDisplay, theStrux, PEXOCStore,
	      PEXShapeComplex, True, 6, points );
  
  pts = points;
  
  pts->x = 2.40232; pts->y = 1.62386; pts->z = -0.1; pts++;
  pts->x = 2.82911; pts->y = 0.87373; pts->z = -0.1; pts++;
  pts->x = 2.40232; pts->y = 0.12386; pts->z = -0.1; pts++;
  pts->x = 2.65839; pts->y = 0.12386; pts->z = -0.1; pts++;
  pts->x = 2.99982; pts->y = 0.72376; pts->z = -0.1; pts++;
  pts->x = 2.48768; pts->y = 1.62386; pts->z = -0.1; pts++;
  
  PEXSetSurfaceColor(  theDisplay, theStrux, PEXOCStore,
		     PEXColorTypeRGB, (PEXColor *)&blue );
  
  
  PEXFillArea(  theDisplay, theStrux, PEXOCStore,
	      PEXShapeComplex, True, 6, points );
  
  pts = points;
  
  pts->x = 3.25589; pts->y = 1.62386; pts->z = -0.1; pts++;
  pts->x = 2.91447; pts->y = 1.02371; pts->z = -0.1; pts++;
  pts->x = 3.42661; pts->y = 0.12386; pts->z = -0.1; pts++;
  pts->x = 3.51233; pts->y = 0.12386; pts->z = -0.1; pts++;
  pts->x = 3.08518; pts->y = 0.87373; pts->z = -0.1; pts++;
  pts->x = 3.51233; pts->y = 1.62386; pts->z = -0.1; pts++;
  pts->x = 3.25589; pts->y = 1.62386; pts->z = -0.1; pts++;
  
  PEXSetSurfaceColor(  theDisplay, theStrux, PEXOCStore,
		     PEXColorTypeRGB, (PEXColor *)&blue );
  
  
  PEXFillArea(  theDisplay, theStrux, PEXOCStore,
	      PEXShapeComplex, True, 7, points );
  
  pts = points;
  
  pts->x = 3.75; pts->y = 0.375; pts->z = -0.1; pts++;
  pts->x = 3.875; pts->y = 0.25; pts->z = -0.1; pts++;
  pts->x = 4.02367; pts->y = 0.14236; pts->z = -0.1; pts++;
  pts->x = 4.125; pts->y = 0.125; pts->z = -0.1; pts++;
  pts->x = 4.21117; pts->y = 0.15972; pts->z = -0.1; pts++;
  pts->x = 4.25; pts->y = 0.25; pts->z = -0.1; pts++;
  pts->x = 4.0; pts->y = 1.375; pts->z = -0.1; pts++;
  pts->x = 4.04798; pts->y = 1.48264; pts->z = -0.1; pts++;
  pts->x = 4.22506; pts->y = 1.45139; pts->z = -0.1; pts++;
  pts->x = 4.375; pts->y = 1.375; pts->z = -0.1; pts++;
  pts->x = 4.25; pts->y = 1.5; pts->z = -0.1; pts++;
  pts->x = 4.10354; pts->y = 1.60417; pts->z = -0.1; pts++;
  pts->x = 4.0; pts->y = 1.625; pts->z = -0.1; pts++;
  pts->x = 3.91951; pts->y = 1.58333; pts->z = -0.1; pts++;
  pts->x = 3.875; pts->y = 1.5; pts->z = -0.1; pts++;
  pts->x = 4.125; pts->y = 0.375; pts->z = -0.1; pts++;
  pts->x = 4.08617; pts->y = 0.26042; pts->z = -0.1; pts++;
  pts->x = 3.90562; pts->y = 0.29861; pts->z = -0.1; pts++;
  pts->x = 3.75; pts->y = 0.375; pts->z = -0.1; pts++;
  
  PEXSetSurfaceColor(  theDisplay, theStrux, PEXOCStore,
		     PEXColorTypeRGB, (PEXColor *)&cyan );
  
  
  PEXFillArea(  theDisplay, theStrux, PEXOCStore,
	      PEXShapeComplex, True, 19, points );
  
  pts = points;
  
  pts->x = 4.54104; pts->y = 0.84028; pts->z = -0.1; pts++;
  pts->x = 4.69034; pts->y = 0.69792; pts->z = -0.1; pts++;
  pts->x = 4.77715; pts->y = 0.64583; pts->z = -0.1; pts++;
  pts->x = 4.87437; pts->y = 0.64236; pts->z = -0.1; pts++;
  pts->x = 4.9334; pts->y = 0.71875; pts->z = -0.1; pts++;
  pts->x = 4.93687; pts->y = 0.85069; pts->z = -0.1; pts++;
  pts->x = 4.81944; pts->y = 1.36806; pts->z = -0.1; pts++;
  pts->x = 4.86742; pts->y = 1.47569; pts->z = -0.1; pts++;
  pts->x = 5.04451; pts->y = 1.44444; pts->z = -0.1; pts++;
  pts->x = 5.19444; pts->y = 1.36806; pts->z = -0.1; pts++;
  pts->x = 5.06944; pts->y = 1.49306; pts->z = -0.1; pts++;
  pts->x = 4.92298; pts->y = 1.59722; pts->z = -0.1; pts++;
  pts->x = 4.81944; pts->y = 1.61806; pts->z = -0.1; pts++;
  pts->x = 4.73895; pts->y = 1.57639; pts->z = -0.1; pts++;
  pts->x = 4.69444; pts->y = 1.49306; pts->z = -0.1; pts++;
  pts->x = 4.8327; pts->y = 0.86458; pts->z = -0.1; pts++;
  pts->x = 4.8084; pts->y = 0.75694; pts->z = -0.1; pts++;
  pts->x = 4.72854; pts->y = 0.75694; pts->z = -0.1; pts++;
  pts->x = 4.54104; pts->y = 0.84028; pts->z = -0.1; pts++;
  
  PEXSetSurfaceColor(  theDisplay, theStrux, PEXOCStore,
		     PEXColorTypeRGB, (PEXColor *)&magenta );
  
  
  PEXFillArea(  theDisplay, theStrux, PEXOCStore,
	      PEXShapeComplex, True, 19, points );
  
  pts = points;
  
  pts->x = 4.84312; pts->y = 0.30208; pts->z = -0.1; pts++;
  pts->x = 4.95423; pts->y = 0.30208; pts->z = -0.1; pts++;
  pts->x = 5.02367; pts->y = 0.37153; pts->z = -0.1; pts++;
  pts->x = 5.02367; pts->y = 0.48611; pts->z = -0.1; pts++;
  pts->x = 4.9577; pts->y = 0.54514; pts->z = -0.1; pts++;
  pts->x = 4.85354; pts->y = 0.54514; pts->z = -0.1; pts++;
  pts->x = 4.78409; pts->y = 0.48611; pts->z = -0.1; pts++;
  pts->x = 4.78756; pts->y = 0.36458; pts->z = -0.1; pts++;
  
  PEXSetSurfaceColor(  theDisplay, theStrux, PEXOCStore,
		     PEXColorTypeRGB, (PEXColor *)&magenta );
  
  
  PEXFillArea(  theDisplay, theStrux, PEXOCStore,
	      PEXShapeComplex, True, 8, points );
  
  pts = points;
  
  pts->x = 5.38889; pts->y = 0.375; pts->z = -0.1; pts++;
  pts->x = 5.51389; pts->y = 0.25; pts->z = -0.1; pts++;
  pts->x = 5.66256; pts->y = 0.14236; pts->z = -0.1; pts++;
  pts->x = 5.76389; pts->y = 0.125; pts->z = -0.1; pts++;
  pts->x = 5.85006; pts->y = 0.15972; pts->z = -0.1; pts++;
  pts->x = 5.88889; pts->y = 0.25; pts->z = -0.1; pts++;
  pts->x = 5.72159; pts->y = 0.99306; pts->z = -0.1; pts++;
  pts->x = 5.81534; pts->y = 0.89236; pts->z = -0.1; pts++;
  pts->x = 5.92992; pts->y = 0.82986; pts->z = -0.1; pts++;
  pts->x = 6.10006; pts->y = 0.82986; pts->z = -0.1; pts++;
  pts->x = 6.22159; pts->y = 0.95833; pts->z = -0.1; pts++;
  pts->x = 6.14173; pts->y = 1.34375; pts->z = -0.1; pts++;
  pts->x = 6.1; pts->y = 1.42; pts->z = -0.1; pts++;
  pts->x = 6.01389; pts->y = 1.51736; pts->z = -0.1; pts++;
  pts->x = 5.81534; pts->y = 1.59375; pts->z = -0.1; pts++;
  pts->x = 5.63889; pts->y = 1.625; pts->z = -0.1; pts++;
  pts->x = 5.5584; pts->y = 1.58333; pts->z = -0.1; pts++;
  pts->x = 5.51389; pts->y = 1.5; pts->z = -0.1; pts++;
  pts->x = 5.76389; pts->y = 0.375; pts->z = -0.1; pts++;
  pts->x = 5.72506; pts->y = 0.26042; pts->z = -0.1; pts++;
  pts->x = 5.54451; pts->y = 0.29861; pts->z = -0.1; pts++;
  pts->x = 5.38889; pts->y = 0.375; pts->z = -0.1; pts++;
  
  /* start inside of b */
  
  pts->x = 5.70423; pts->y = 1.10417; pts->z = -0.1; pts++;
  pts->x = 5.63826; pts->y = 1.41667; pts->z = -0.1; pts++;
  pts->x = 5.72506; pts->y = 1.50694; pts->z = -0.1; pts++;
  pts->x = 5.87437; pts->y = 1.46528; pts->z = -0.1; pts++;
  pts->x = 6.01326; pts->y = 1.34028; pts->z = -0.1; pts++;
  pts->x = 6.08965; pts->y = 1.0; pts->z = -0.1; pts++;
  pts->x = 6.01673; pts->y = 0.93403; pts->z = -0.1; pts++;
  pts->x = 5.82229; pts->y = 0.98958; pts->z = -0.1; pts++;
  
  lop[0].count = 22;
  lop[0].points = &points[0];
  lop[1].count = 8;
  lop[1].points = &points[22];
  
  PEXSetSurfaceColor(  theDisplay, theStrux, PEXOCStore,
		     PEXColorTypeRGB, (PEXColor *)&yellow );
  
  
  PEXFillAreaSet(  theDisplay, theStrux, PEXOCStore,
		 PEXShapeComplex, True, PEXContourNested, 2, lop );
}
