v01i036: xmoire, a screensaver, Part01/01

Mike Wexler mikew at wyse.wyse.com
Wed Sep 14 06:31:32 AEST 1988


Submitted-by: eichin at athena.mit.edu (Mark W. Eichin)
Posting-number: Volume 1, Issue 36
Archive-name: xmoire/part01

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 1 (of 1)."
# Contents:  Makefile README patchlevel.h xmoire.1 xmoire.c
# Wrapped by mikew at x2 on Tue Sep 13 13:30:04 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f Makefile -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"Makefile\"
else
echo shar: Extracting \"Makefile\" \(387 characters\)
sed "s/^X//" >Makefile <<'END_OF_Makefile'
X#	$Source: /mit/eichin/Src/X/xmoire/RCS/Makefile,v $
X#	$Header: Makefile,v 1.1 88/04/15 14:05:17 eichin Exp $
X#
XDESTDIR=
XBINDIR=/mit/sipb/$${MACHTYPE}bin
XCFLAGS=	-O
X
XONEFILE=xmoire
X
Xall:	${ONEFILE}
X
Xdepend:
X
Xclean:
X	rm -f ${ONEFILE}.o ${ONEFILE} *~
X
Xinstall:
X	install -c -s ${ONEFILE} ${DESTDIR}${BINDIR}/${ONEFILE}
X
X${ONEFILE}:	${ONEFILE}.o
X	cc $(CFLAGS) -o ${ONEFILE} ${ONEFILE}.o -lX
END_OF_Makefile
if test 387 -ne `wc -c <Makefile`; then
    echo shar: \"Makefile\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f README -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"README\"
else
echo shar: Extracting \"README\" \(239 characters\)
sed "s/^X//" >README <<'END_OF_README'
Xxmoire is a client application running under the X windowing system that 
Xblanks the display when activated. It is activated by sliding the mouse
Xinto the upper right corner of the screen, and deactivated by sliding it
Xout of that corner.
END_OF_README
if test 239 -ne `wc -c <README`; then
    echo shar: \"README\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f patchlevel.h -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"patchlevel.h\"
else
echo shar: Extracting \"patchlevel.h\" \(22 characters\)
sed "s/^X//" >patchlevel.h <<'END_OF_patchlevel.h'
X#define patchlevel 0
X
END_OF_patchlevel.h
if test 22 -ne `wc -c <patchlevel.h`; then
    echo shar: \"patchlevel.h\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f xmoire.1 -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"xmoire.1\"
else
echo shar: Extracting \"xmoire.1\" \(2035 characters\)
sed "s/^X//" >xmoire.1 <<'END_OF_xmoire.1'
X.TH xmoire SIPB "August 1988" "X Version 11"
X.SH NAME
Xxmoire \- blanks display with a changeable vector pattern
X.SH SYNOPSIS
X.B xmoire
X.SH DESCRIPTION
X.I xmoire
Xis a client application running under the X windowing system that blanks
Xthe display when activated. It is activated by sliding the mouse into
Xthe upper right corner of the screen, and deactivated by sliding it
Xout of that corner.
X.PP
XControl of the display is as follows:
X.nf
Xkey	function (picture drawn)
Xr	rectangle
Xo	circle (oval)
Xp	pentagram
X/	left slant
X\\	right slant
Xh	hourglass
X+	plus
Xx	cross
Xv	vee
Xt	triangle
XQ	quit the screensaver completely
X]	make the set of patterns larger
X[	make the set of patterns slower
X{	speed up the display (it usually starts out display bound, though)
X}	slow down the display
X.fi
X.PP
XIf the system seems to react slowly to keystrokes, try using } to slow
Xdown the display.
X.SH HISTORY
XThe idea for this program comes from a public domain `screensaver'
Xfor the Mac labeled:
X.B
X.nf
X	"Moire V1.1 by John Lim"
X	"Algorithm by Anonymous"
X	"Portions (c) John Lim and THINK Tech." 
X.fi
XAfter watching it for a short time, it was obvious how to implement a
Xsimilar (if not identical) program; however, all the code here is my
Xoriginal work, its purpose only being to provide the same look and
Xfeel under X11. Due to the eminent simplicity of the concept, I feel I
Xam not stepping on any toes by creating this. In any case, it is a
Xdifferent window system, and the user interface differs in certain
Xways (unlabeled keys do NOT produce rectangles; space bar does NOT
Xproduce an instructional message (yet); curly braces are used to
Xcontrol operation speed, not 0-9) and that this alone may be
Xsufficient to call the look and feel different. The people here who
Xhave found it most similar included at least one person who despised
Xthe original, and wanted me to port Pyro instead...
X
X.SH FILES
XNone yet.
X.SH AUTHOR
XWritten by Mark W. Eichin for the Student Information Processing Board
Xof MIT (SIPB).
X.PP
XInspiration from "Moire V1.1 by John Lim"
X
X
END_OF_xmoire.1
if test 2035 -ne `wc -c <xmoire.1`; then
    echo shar: \"xmoire.1\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f xmoire.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"xmoire.c\"
else
echo shar: Extracting \"xmoire.c\" \(19200 characters\)
sed "s/^X//" >xmoire.c <<'END_OF_xmoire.c'
X/*
X * xmoire.c
X * Copyright 1988 The Student Information Processing Board (SIPB)
X * Written by Mark W. Eichin, begun April 13, 1988.
X *
X * All distribution rights hereby granted, as long as
X *	1) you do not charge for this code or derivatives of it
X *	without my consent;
X *	2) you leave this header comment in place unchanged;
X * 	3) you attempt to inform myself <eichin at athena.mit.edu> or the
X * 	Board <sipb at athena.mit.edu> of any changes or improvements.
X *
X * The idea for this program comes from a public domain `screensaver'
X * for the Mac labeled:
X * * * "Moire V1.1 by John Lim"
X * * * "Algorithm by Anonymous"
X * * * "Portions (c) John Lim and THINK Tech." 
X * After watching it for a short time, it was obvious how to implement
X * a similar (if not identical) program; however, all the code here is
X * my original work, its purpose only being to provide the same look
X * and feel under X11. Due to the eminent simplicity of the concept, I
X * feel I am not stepping on any toes by creating this. In any case,
X * it is a different window system, and the user interface differs in
X * certain ways (unlabeled keys do NOT produce rectangles; space bar
X * does NOT produce an instructional message (yet); curly braces are
X * used to control operation speed, not 0-9) and that this alone may
X * be sufficient to call the look and feel different. The people here
X * who have found it most similar included at least one person who
X * despised the original, and wanted me to port Pyro instead...
X */
X
X/*
X * Mutable comments follow:
X * $Header: xmoire.c,v 1.1 88/04/15 12:51:10 eichin Exp $
X * $Log:	xmoire.c,v $
X * Revision 1.1  88/04/15  12:51:10  eichin
X * Initial revision
X * 
X */
X
X/*
X * Things to add (may be superseded by the above logs):
X * 	geometry spec for the mousetrap window
X * 	password locking (or integration with xscreensaver)
X * Things *not* to add (don't waste time on:)
X * 	number keys to control speed
X */
X
X#include <X11/Xlib.h>
X#include <stdio.h>
X#include <sys/types.h>
X#include <strings.h>
X
XDisplay *dpy;
X
X#define SIZ 51
X/* SIZ is for alloc'ing */
X#define MAXSIZ SIZ-1
X/* valid indices are <= MAXSIZ, so if (x>MAXSIZ) x=0; */
X#define INITSIZ 5
X#define MINSIZ 2
X#define MAXTIM 1000000
X#define MINTIM 1000
X
X#define SLEEPTIME 50000
X#define XR 5
X#define XRM 1
X#define YR 5
X#define YRM 1
X#define CHCHANCE (25 - 1)
X
Xvoid init_random()
X{
X  /*
X   * We really don't need a VERY random seed, since we are only
X   * adjusting the vectors, and that only needs about 4 bits/sample of
X   * magnitude change. Low part of time would be ok, I suppose. So
X   * what?
X   */
X  srandom(getpid());
X}
X
X/*
X * These are global, so they don't have to be passed between main and
X * the draw/undraw procs. They should at least be made local to a
X * smaller file/set of procs... for now, they just sit here.
X *
X * The routine simply bounces a bounding box around the screen, and
X * then draws the correct image within it; these are the origin and
X * sides of the bounding box.
X */
Xint xx[SIZ], yy[SIZ], xs[SIZ], ys[SIZ];
Xvoid draw(), undraw();
X
X/*
X * pic is all the possible returns from a keyboard entry; it is also
X * all of the possible shapes (a subset.)
X */
Xtypedef enum _pic {
X  RECT, CIRC, PENT, DIAM, LEFT, RIGHT, HGLS, PLUS, CROSS, VEE, TRI,
X  PUNT, LONG, SHORT, FAST, SLOW,
X} pic;
X/* HGLS == HourGlass, also H key... */
X/*
X * opts are the keys pressed, and popts are the values returned from
X * char2pic for those keys.
X */
Xchar opts[] = "ropd/\\h+xvtQ][}{";
Xpic popts[] = {
X  RECT, CIRC, PENT, DIAM, LEFT, RIGHT, HGLS, PLUS, CROSS, VEE, TRI,
X  PUNT, LONG, SHORT, FAST, SLOW,
X};
X
Xpic char2pic(in,old)
X     char in;
X     pic old;
X{
X  char *where;
X
X  where = index(opts, in);
X  return(where?popts[where-opts]:old);
X}
X
X/*
X * again, it is easier to make these global than to pass them to the
X * draw/undraw routines all the time.
X */
XGC gc, ungc;
XWindow win;
X
X/*
X * This could stand to be broken down a bit more. But then, none of
X * the important bottlenecks are here... far too much time was spent
X * writing it in the first place to justify rewriting it. Unless of
X * course we can merge it into the other xscreensaver...
X */
Xmain (argc, argv)
X	int argc;
X	char **argv;
X{
X  Window rtwin, scanwin;	/* root and mouse entry windows */
X  int scrn;
X  XGCValues gc_val;
X  pic pictype = RECT;		/* current displayed picture */
X  int siz = INITSIZ;
X  int start, end, ostart;
X  int swid, shi;
X  int xxoff, yyoff, xsoff, ysoff;
X  unsigned long vmask;
X  XSetWindowAttributes wvals;
X  int timeout, interval, blanking, exposures; /* screen saver parameters */
X  unsigned micr = SLEEPTIME;	/* microseconds between motion */
X  
X  init_random();		/* start random number generator */
X  
X  dpy = XOpenDisplay("");
X  scrn = DefaultScreen(dpy);
X  rtwin = RootWindow(dpy, scrn);
X
X  swid = DisplayWidth(dpy, scrn);
X  shi = DisplayHeight(dpy, scrn);
X  
X  wvals.override_redirect = True;
X  wvals.background_pixel = BlackPixel(dpy, scrn);
X  
X  vmask = CWOverrideRedirect | CWBackPixel;
X/*
X * Creating the drawing window to fill the whole screen and get mapped
X * later on.
X */
X  win = XCreateWindow(dpy, rtwin, /* excitement window */
X		      0, 0,	/* origin */
X		      swid, shi, /* size */
X		      0,	/* border width */
X		      0,	/* depth from parent */
X		      InputOutput, /* class */
X		      CopyFromParent, /* visual */
X		      vmask, &wvals);
X  
X#define BOXSIZ 50
X
X  vmask = CWOverrideRedirect;
X/*
X * Creating the window to catch the mouse motion, into and out of the
X * ``corner''; this perhaps ought to be smaller, and should parse the
X * geometry specification from somwhere as well.
X */
X  scanwin = XCreateWindow(dpy, rtwin, /* toggle window */
X			  swid-BOXSIZ, 0, /* origin */
X			  BOXSIZ, BOXSIZ, /* size */
X			  0,	/* border width */
X			  0,	/* depth from parent */
X			  InputOnly, /* class */
X			  CopyFromParent, /* visual */
X			  vmask, &wvals);
X/*
X * The GC's for draw and undraw. The method used is to draw the first
X * shapes, then erase the last one and repeat.
X */
X  gc_val.foreground = (unsigned long) WhitePixel (dpy, scrn); 
X  gc_val.background = (unsigned long) BlackPixel (dpy, scrn); 
X  gc = XCreateGC (dpy, win, GCForeground|GCBackground, &gc_val);
X
X  gc_val.foreground = (unsigned long) BlackPixel (dpy, scrn); 
X  gc_val.background = (unsigned long) WhitePixel (dpy, scrn); 
X  ungc = XCreateGC (dpy, win, GCForeground|GCBackground, &gc_val);
X
X  start = 0;			/* duplicated later... */
X  xx[start] = 0;		/* initial vals, should read them? */
X  yy[start] = 0;
X  xs[start] = 100;
X  ys[start] = 100;
X  
X  xxoff = 3;
X  yyoff = 3;
X  xsoff = 0;
X  ysoff = 0;
X
X  for (;;)
X    {
X      int sizoff;
X      /*
X       * First we deal with the selector window, then we fall into the
X       * drawing window, and then back to the selector window.
X       */
X
X      XSelectInput(dpy, scanwin, EnterWindowMask);
X      XMapWindow(dpy, scanwin);
X      
X      for (;;)
X	{
X	  XEvent event;
X	  
X	  XNextEvent(dpy, &event);
X	  if(event.type == EnterNotify)
X	    {
X	      break;		/*
X				 * they came in to the corner zone...
X				 * interesting frob here might be to
X				 * check the position on an angle.
X				 */
X	    }
X	}
X      /*
X       * Nuke the screensaver, for now WE are the screensaver. There
X       * really should be a ``screensaver activated'' event of some
X       * sort, so we could trigger on this too...
X       */
X      XGetScreenSaver(dpy, &timeout, &interval, &blanking, &exposures);
X      XSetScreenSaver(dpy,	/* all these are zero, but lets do it right */
X		      DisableScreenSaver,
X		      DisableScreenInterval,
X		      DontPreferBlanking,
X		      DontAllowExposures); /* disable screen saver */
X
X      /*
X       * Now wait for the full-screen drawing window to show up
X       */
X      XSelectInput(dpy, win, ExposureMask);
X      XMapRaised(dpy, win);	/* put it on top */
X
X      /*
X       * Turn off entry, just notice when the mouse exits. To make it
X       * appear on top again, and to allow other events to leak
X       * through, reparent the mousetrap window into the drawing
X       * window.
X       */
X
X      XSelectInput(dpy, scanwin, LeaveWindowMask);
X      XReparentWindow(dpy, scanwin, win, swid-BOXSIZ, 0);
X      
X      /*
X       * always start with one, but make end negative so that we don't
X       * start erasing things until we have enough of them there.
X       */
X      start = 0;
X      end = start - siz;
X  
X      for (;;)
X	{
X	  XEvent event;
X	  
X	  XNextEvent(dpy, &event);
X	  if(event.type == Expose)
X	    {
X	      break;		/*
X				 * same type of loop as above, but
X				 * this time it is waiting for the
X				 * mapping to finish. This could be
X				 * made MUCH prettier. */
X	    }
X	}
X
X      /*
X       * Now start looking for key presses to change the display. Note
X       * that we could just look at scanwin (we know we are in it,
X       * right?) but this way is more fun...
X       */
X      XSelectInput(dpy, win, KeyPressMask);
X
X      for (;;)
X	{
X	  usleep(micr);		/* bored with the X server, sleeping... */
X  
X	  if(XPending(dpy))	/* Got one! */
X	    {
X	      XEvent event;
X	  
X	      XNextEvent(dpy, &event);
X	      if(event.type == KeyPress) /* Could listen to both windows... */
X		{
X		  char input;
X		  pic tmppic;
X
X		  /* just get the first char of the keypress */
X		  (void)XLookupString(&event.xkey, &input, 1, NULL, NULL);
X	      
X		  /* convert it to a picture index */
X		  tmppic = char2pic(input, pictype);
X	      
X		  if (tmppic == pictype)
X		    continue;	/* punt if already running that one */
X
X		  if (tmppic == PUNT) /* get out, should check passwd? */
X		    {
X		      break;	/*
X				 * actually a relic from before
X				 * mousing stuff worked.
X				 */
X		    }
X		  if (tmppic == LONG) /* make the pattern longer */
X		    {
X		      sizoff = 1;
X		      continue;
X		    }
X		  if (tmppic == SHORT) /* make it shorter */
X		    {
X		      sizoff = -1;
X		      continue;
X		    }
X		  if (tmppic == FAST) /* update faster */
X		    {
X		      micr <<= (micr>=MAXTIM)?0:1;
X		      continue;
X		    }
X		  if (tmppic == SLOW) /* update slower */
X		    {
X		      micr >>= (micr<=MINTIM)?0:1;
X		      continue;
X		    }
X
X		  while(start != end) /* ok, it IS a new pattern, wipe old */
X		    {
X		      undraw(pictype, end);
X		      end++;
X		      if(end > MAXSIZ) end = 0;
X		    }
X		  /* set up as a fresh start for the new one */
X		  xx[0] = xx[start]; xs[0] = xs[start];
X		  yy[0] = yy[start]; ys[0] = ys[start];
X		  
X		  start = 0;
X		  end = start - siz;
X		  pictype = tmppic;
X		}
X	      else if (event.type == LeaveNotify)
X		{
X		  /* this is the REAL escape method... */
X		  break;	/* getting out... Password? */
X		}
X	      continue;
X	    }
X
X	  if(sizoff == -1)
X	    {
X	      if(siz > MINSIZ)
X		{
X		  siz--;
X		  undraw(pictype, end);
X		  end++;
X		  if(end > MAXSIZ) end = 0;
X		}
X	      sizoff = 0;
X	    }
X	  /* else */
X	    {
X	      if (sizoff == 0 || siz >= MAXSIZ)
X		{
X		  undraw(pictype, end);
X		  end++;
X		  if(end > MAXSIZ) end = 0;
X		}
X	      if(sizoff == 1 && siz <= MAXSIZ)
X		{
X		  siz++;
X		}
X	      sizoff = 0;
X	    }
X	  
X	  draw(pictype, start);	/* actually draw a stage */
X	  /*
X	   * Now for the common box incrementing code...
X	   */
X	  ostart = start++;
X	  if(start >= SIZ) start = 0;
X
X	  /* jump the bounding box a step... */
X	  xx[start] = xx[ostart] + xxoff;
X	  xs[start] = xs[ostart] + xsoff;
X	  yy[start] = yy[ostart] + yyoff;
X	  ys[start] = ys[ostart] + ysoff;
X      
X
X	  if(xx[start]+xs[start] + xxoff + xsoff > swid) /* past right edge */
X	    {
X	      if(xxoff>0) xxoff = -xxoff;
X	      if(xsoff>0) xsoff = -xsoff;
X	    }
X	  if(xx[start]+xxoff < 0) /* past left edge */
X	    {
X	      xxoff = -xxoff;
X	    }
X	  if(yy[start]+ys[start] + yyoff + ysoff > shi)	/* below bottom */
X	    {
X	      if(yyoff>0) yyoff = -yyoff;
X	      if(ysoff>0) ysoff = -ysoff;
X	    }
X	  if(yy[start]+yyoff < 0) /* above top */
X	    {
X	      yyoff = -yyoff;
X	    }
X	  if(xs[start]+xsoff < 0) /* too narrow */
X	    {
X	      xsoff = - xsoff;
X	    }
X	  if(ys[start]+ysoff < 0) /* too short */
X	    {
X	      ysoff = - ysoff;
X	    }
X	  if(!small_random(0,CHCHANCE))	/* 1:20 chance of actual change */
X	    {
X	      if(small_random(0,1)) /* 1:2 choice... */
X		{
X		  xxoff =
X		    small_random((xxoff>0?XRM:-XR),
X				 (xxoff>0?XR:-XRM));
X		}
X	      else
X		{
X		  yyoff =
X		    small_random((yyoff>0?YRM:-YR),
X				 (yyoff>0?YR:-YRM));
X		}
X	    }
X	  if(!small_random(0,CHCHANCE))
X	    {
X	      if(small_random(0,1)) /* 1:2 choice... */
X		{
X		  xsoff =
X		    2*small_random((xsoff>0?XRM:-XR),
X				   (xsoff>0?XR:-XRM));
X		}
X	      else
X		{
X		  ysoff =
X		    2*small_random((ysoff>0?YRM:-YR),
X				   (ysoff>0?YR:-YRM));
X		}
X	    }
X	}
X      /* put the special box back in the root window */
X      XReparentWindow(dpy, scanwin, rtwin, swid-BOXSIZ, 0);
X      /* turn the drawing window off */
X      XUnmapWindow(dpy, win);	/*
X				 * hide the graphics, and fall up to
X				 * the top.
X				 */
X      /* restore the screensaver to the old defaults */
X      XSetScreenSaver(dpy, timeout, interval, blanking, exposures);
X    }
X}
X  
Xvoid undraw(ptype, ind)
X     pic ptype;
X     int ind;
X{
X  switch(ptype)
X    {
X    case RECT:
X      if (ind>=0)
X	{
X	  XDrawRectangle(dpy, win, ungc,
X			 xx[ind], yy[ind],
X			 xs[ind], ys[ind]);
X	}
X      break;
X    case CIRC:
X      if(ind>=0) XDrawArc(dpy, win, ungc,
X			  xx[ind], yy[ind],
X			  xs[ind], ys[ind],
X			  0, 360*64);
X      break;
X    case PENT:
X      if(ind>=0)
X	{
X	  XPoint xps[6];
X
X	  xps[5].x = xps[0].x = xx[ind]+xs[ind]/2;
X	  xps[5].y = xps[0].y = yy[ind];
X	  xps[2].x = xx[ind];
X	  xps[2].y = yy[ind]+ys[ind]/2;
X	  xps[3].x = xx[ind]+xs[ind];
X	  xps[3].y = yy[ind]+ys[ind]/2;
X	  xps[4].x = xx[ind]+xs[ind]/3;
X	  xps[4].y = yy[ind]+ys[ind];
X	  xps[1].x = xx[ind]+2*xs[ind]/3;
X	  xps[1].y = yy[ind]+ys[ind];
X	    
X	  XDrawLines(dpy, win, ungc, xps, 6, CoordModeOrigin);
X	}
X      break;
X    case DIAM:
X      if(ind>=0)
X	{
X	  XPoint xps[5];
X
X	  xps[4].x = xps[0].x = xx[ind]+xs[ind]/2;
X	  xps[4].y = xps[0].y = yy[ind];
X	  xps[1].x = xx[ind]+xs[ind];
X	  xps[1].y = yy[ind]+ys[ind]/2;
X	  xps[2].x = xx[ind]+xs[ind]/2;
X	  xps[2].y = yy[ind]+ys[ind];
X	  xps[3].x = xx[ind];
X	  xps[3].y = yy[ind]+ys[ind]/2;
X
X	  XDrawLines(dpy, win, ungc, xps, 5, CoordModeOrigin);
X	}
X      break;
X    case LEFT:			/* / */
X      if(ind>=0) XDrawLine(dpy, win, ungc,
X			   xx[ind], yy[ind]+ys[ind],
X			   xx[ind]+xs[ind], yy[ind]);
X      break;
X    case RIGHT:			/* \ */
X      if(ind>=0) XDrawLine(dpy, win, ungc,
X			   xx[ind], yy[ind],
X			   xx[ind]+xs[ind], yy[ind]+ys[ind]);
X      break;
X    case HGLS:
X      if(ind>=0)
X	{
X	  XPoint xps[5];
X
X	  xps[4].x = xps[0].x = xx[ind];
X	  xps[4].y = xps[0].y = yy[ind];
X	  xps[1].x = xx[ind]+xs[ind];
X	  xps[1].y = yy[ind];
X	  xps[2].x = xx[ind];
X	  xps[2].y = yy[ind]+ys[ind];
X	  xps[3].x = xx[ind]+xs[ind];
X	  xps[3].y = yy[ind]+ys[ind];
X
X	  XDrawLines(dpy, win, ungc, xps, 5, CoordModeOrigin);
X	}
X      break;
X    case PLUS:
X      if(ind>=0)
X	{
X	  XDrawLine(dpy, win, ungc, /* - */
X		    xx[ind], yy[ind]+ys[ind]/2,
X		    xx[ind]+xs[ind], yy[ind]+ys[ind]/2);
X	  XDrawLine(dpy, win, ungc, /* | */
X		    xx[ind]+xs[ind]/2, yy[ind],
X		    xx[ind]+xs[ind]/2, yy[ind]+ys[ind]);
X	}
X      break;
X      
X    case CROSS:
X      if(ind>=0)
X	{
X	  XDrawLine(dpy, win, ungc, /* / */
X		    xx[ind], yy[ind]+ys[ind],
X		    xx[ind]+xs[ind], yy[ind]);
X	  XDrawLine(dpy, win, ungc, /* \ */
X		    xx[ind], yy[ind],
X		    xx[ind]+xs[ind], yy[ind]+ys[ind]);
X	}
X      break;
X    case VEE:
X      if(ind>=0)
X	{
X	  XDrawLine(dpy, win, ungc, /* \ */
X		    xx[ind], yy[ind],
X		    xx[ind]+xs[ind]/2, yy[ind]+ys[ind]);
X	  XDrawLine(dpy, win, ungc, /* / */
X		    xx[ind]+xs[ind], yy[ind],
X		    xx[ind]+xs[ind]/2, yy[ind]+ys[ind]);
X	}
X      break;
X    case TRI:
X      if(ind>=0)
X	{
X	  XPoint xps[4];
X
X	  xps[3].x = xps[0].x = xx[ind]+xs[ind]/2;
X	  xps[3].y = xps[0].y = yy[ind];
X	  xps[1].x = xx[ind]+xs[ind];
X	  xps[1].y = yy[ind]+ys[ind];
X	  xps[2].x = xx[ind];
X	  xps[2].y = yy[ind]+ys[ind];
X
X	  XDrawLines(dpy, win, ungc, xps, 4, CoordModeOrigin);
X	}
X      break;
X      
X      /* , TRI, */
X    default:
X      break;
X    }
X}
X
Xvoid draw(ptype, ind)
X     pic ptype;
X     int ind;
X{
X  switch(ptype)
X    {
X    case RECT:
X      XDrawRectangle(dpy, win, gc,
X		     xx[ind], yy[ind],
X		     xs[ind], ys[ind]);
X      break;
X    case CIRC:
X      XDrawArc(dpy, win, gc,
X	       xx[ind], yy[ind],
X	       xs[ind], ys[ind],
X	       0, 360*64);
X      break;
X    case PENT:
X      /*
X       * Pentagon: five points.
X       * Top center,
X       * upper left/right (same y, diff. x)
X       * lower left/right (same y, diff. x)
X       * This should fit in a rectangle...
X       * tc = (xx+xs/2, yy)
X       * ul = (xx, yy+ys/2) ur = (xx+xs, yy+ys/2)
X       * ll = (xx+xs/3, yy+ys) lr = (xx+2xs/3, yy+ys)
X       * draw tc->lr->ul->ur->ll->tc.
X       */
X      {
X	XPoint xps[6];
X
X	xps[5].x = xps[0].x = xx[ind]+xs[ind]/2;
X	xps[5].y = xps[0].y = yy[ind];
X	xps[2].x = xx[ind];
X	xps[2].y = yy[ind]+ys[ind]/2;
X	xps[3].x = xx[ind]+xs[ind];
X	xps[3].y = yy[ind]+ys[ind]/2;
X	xps[4].x = xx[ind]+xs[ind]/3;
X	xps[4].y = yy[ind]+ys[ind];
X	xps[1].x = xx[ind]+2*xs[ind]/3;
X	xps[1].y = yy[ind]+ys[ind];
X	    
X	XDrawLines(dpy, win, gc, xps, 6, CoordModeOrigin);
X      }
X      break;
X    case DIAM:
X      {
X	XPoint xps[5];
X
X	xps[4].x = xps[0].x = xx[ind]+xs[ind]/2;
X	xps[4].y = xps[0].y = yy[ind];
X	xps[1].x = xx[ind]+xs[ind];
X	xps[1].y = yy[ind]+ys[ind]/2;
X	xps[2].x = xx[ind]+xs[ind]/2;
X	xps[2].y = yy[ind]+ys[ind];
X	xps[3].x = xx[ind];
X	xps[3].y = yy[ind]+ys[ind]/2;
X
X	XDrawLines(dpy, win, gc, xps, 5, CoordModeOrigin);
X      }
X      break;
X    case LEFT:			/* / */
X      XDrawLine(dpy, win, gc,
X		xx[ind], yy[ind]+ys[ind],
X		xx[ind]+xs[ind], yy[ind]);
X      break;
X    case RIGHT:			/* \ */
X      XDrawLine(dpy, win, gc,
X		xx[ind], yy[ind],
X		xx[ind]+xs[ind], yy[ind]+ys[ind]);
X      break;
X    case HGLS:
X      {
X	XPoint xps[5];
X
X	xps[4].x = xps[0].x = xx[ind];
X	xps[4].y = xps[0].y = yy[ind];
X	xps[1].x = xx[ind]+xs[ind];
X	xps[1].y = yy[ind];
X	xps[2].x = xx[ind];
X	xps[2].y = yy[ind]+ys[ind];
X	xps[3].x = xx[ind]+xs[ind];
X	xps[3].y = yy[ind]+ys[ind];
X
X	XDrawLines(dpy, win, gc, xps, 5, CoordModeOrigin);
X      }
X      break;
X    case PLUS:
X      XDrawLine(dpy, win, gc, /* - */
X		xx[ind], yy[ind]+ys[ind]/2,
X		xx[ind]+xs[ind], yy[ind]+ys[ind]/2);
X      XDrawLine(dpy, win, gc, /* | */
X		xx[ind]+xs[ind]/2, yy[ind],
X		xx[ind]+xs[ind]/2, yy[ind]+ys[ind]);
X      break;
X    case CROSS:
X      XDrawLine(dpy, win, gc, /* / */
X		xx[ind], yy[ind]+ys[ind],
X		xx[ind]+xs[ind], yy[ind]);
X      XDrawLine(dpy, win, gc, /* \ */
X		xx[ind], yy[ind],
X		xx[ind]+xs[ind], yy[ind]+ys[ind]);
X      break;
X    case VEE:
X      XDrawLine(dpy, win, gc, /* \ */
X		xx[ind], yy[ind],
X		xx[ind]+xs[ind]/2, yy[ind]+ys[ind]);
X      XDrawLine(dpy, win, gc, /* / */
X		xx[ind]+xs[ind], yy[ind],
X		xx[ind]+xs[ind]/2, yy[ind]+ys[ind]);
X      break;
X    case TRI:
X      {
X	XPoint xps[4];
X      
X	xps[3].x = xps[0].x = xx[ind]+xs[ind]/2;
X	xps[3].y = xps[0].y = yy[ind];
X	xps[1].x = xx[ind]+xs[ind];
X	xps[1].y = yy[ind]+ys[ind];
X	xps[2].x = xx[ind];
X	xps[2].y = yy[ind]+ys[ind];
X
X	XDrawLines(dpy, win, gc, xps, 4, CoordModeOrigin);
X      }
X      break;
X    default:
X      break;
X    }
X}
X
Xint small_random(low, high)	/* low <= s_r <= high */
X     int low, high;
X{
X  long r;
X
X  r = random();
X  return((r % (high-low+1))+low);
X}
END_OF_xmoire.c
if test 19200 -ne `wc -c <xmoire.c`; then
    echo shar: \"xmoire.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of archive 1 \(of 1\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 1 archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0
-- 
Mike Wexler(wyse!mikew)    Phone: (408)433-1000 x1330



More information about the Comp.sources.x mailing list