[comp.sources.x] v03i015: The Chaos Game, Part01/01

mikew@wyse.wyse.com (Mike Wexler) (02/18/89)

Submitted-by: nathan@hp-pcd.hp.com (Nathan Meyers)
Posting-number: Volume 3, Issue 15
Archive-name:  chaos/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:  README AUTHOR Imakefile Makefile chaos.1 chaos.c
#   chaosicon.h patchlevel.h
# Wrapped by mikew@wyse on Fri Feb 17 09:53:50 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(319 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
XChaos plays "The Chaos Game", an exercise in strange attractors,
Xfeatured on television's "Nova" program, originally broadcast on 31
XJanuary 1989.
X
XTo make on bsd systems:
X
X	make
X
XTo make on systems of SYSV descent (such as hp-ux):
X
X	make SYSV
X
X---------------------
XNathan Meyers
XHewlett-Packard
Xnathanm@hp-pcd.hp.com
END_OF_FILE
if test 319 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'AUTHOR' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'AUTHOR'\"
else
echo shar: Extracting \"'AUTHOR'\" \(174 characters\)
sed "s/^X//" >'AUTHOR' <<'END_OF_FILE'
XChaos was written by Nathan Meyers of Hewlett-Packard (internet mail
Xaddress nathanm@hp-pcd.hp.com).  Permission granted to freely copy and
Xdistribute on a non-profit basis.
END_OF_FILE
if test 174 -ne `wc -c <'AUTHOR'`; then
    echo shar: \"'AUTHOR'\" unpacked with wrong size!
fi
# end of 'AUTHOR'
fi
if test -f 'Imakefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Imakefile'\"
else
echo shar: Extracting \"'Imakefile'\" \(82 characters\)
sed "s/^X//" >'Imakefile' <<'END_OF_FILE'
X      SYS_LIBRARIES = -lX11
XSimpleProgramTarget(chaos)
XNormalLintTarget(chaos.c)
X
END_OF_FILE
if test 82 -ne `wc -c <'Imakefile'`; then
    echo shar: \"'Imakefile'\" unpacked with wrong size!
fi
# end of 'Imakefile'
fi
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(6499 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
X# Makefile generated by imake - do not edit!
X# $XConsortium: imake.c,v 1.37 88/10/08 20:08:30 jim Exp $
X#
X# The cpp used on this machine replaces all newlines and multiple tabs and
X# spaces in a macro expansion with a single space.  Imake tries to compensate
X# for this, but is not always successful.
X#
X
X###########################################################################
X# X Window System Makefile generated from template file Imake.tmpl
X# $XConsortium: Imake.tmpl,v 1.91 88/10/23 22:37:10 jim Exp $
X#
X# Do not change the body of the imake template file.  Server-specific
X# parameters may be set in the appropriate .macros file; site-specific
X# parameters (but shared by all servers) may be set in site.def.  If you
X# make any changes, you'll need to rebuild the makefiles using
X# "make World" (at best) or "make Makefile; make Makefiles" (at least) in
X# the top level directory.
X#
X# If your C preprocessor doesn't define any unique symbols, you'll need
X# to set BOOTSTRAPCFLAGS when rebuilding imake (usually when doing
X# "make Makefile", "make Makefiles", or "make World").
X#
X# If you absolutely can't get imake to work, you'll need to set the
X# variables at the top of each Makefile as well as the dependencies at the
X# bottom (makedepend will do this automatically).
X#
X
X###########################################################################
X# platform-specific configuration parameters - edit Sun.macros to change
X
X# platform:  $XConsortium: Sun.macros,v 1.52 88/10/23 11:00:55 jim Exp $
X# operating system:   SunOS 3.4
X
XBOOTSTRAPCFLAGS =
X             AS = as
X             CC = cc
X            CPP = /lib/cpp
X             LD = ld
X           LINT = lint
X        INSTALL = install
X           TAGS = ctags
X             RM = rm -f
X             MV = mv
X             LN = ln -s
X         RANLIB = ranlib
XRANLIBINSTFLAGS = -t
X             AR = ar clq
X             LS = ls
X       LINTOPTS = -xz
X    LINTLIBFLAG = -C
X           MAKE = make
XSTD_CPP_DEFINES =
X    STD_DEFINES =
X
X###########################################################################
X# site-specific configuration parameters - edit site.def to change
X
X# site:  $XConsortium: site.def,v 1.16 88/10/12 10:30:24 jim Exp $
X
X###########################################################################
X# definitions common to all Makefiles - do not edit
X
X          SHELL =  /bin/sh
X
X        DESTDIR = /global
X      USRLIBDIR = $(DESTDIR)/lib
X         BINDIR = $(DESTDIR)/bin/X11
X         INCDIR = $(DESTDIR)/include
X         ADMDIR = $(DESTDIR)/usr/adm
X         LIBDIR = $(USRLIBDIR)/X11
X     LINTLIBDIR = $(USRLIBDIR)/lint
X        FONTDIR = $(LIBDIR)/fonts
X       XINITDIR = $(LIBDIR)/xinit
X         XDMDIR = $(LIBDIR)/xdm
X         UWMDIR = $(LIBDIR)/uwm
X         AWMDIR = $(LIBDIR)/awm
X         TWMDIR = $(LIBDIR)/twm
X          DTDIR = $(LIBDIR)/dt
X        MANPATH = /usr/man
X  MANSOURCEPATH = $(MANPATH)/man
X         MANDIR = $(MANSOURCEPATH)n
X      LIBMANDIR = $(MANSOURCEPATH)n3
X    XAPPLOADDIR = $(LIBDIR)/app-defaults
X
X   INSTBINFLAGS = -m 0755
X   INSTUIDFLAGS = -m 4755
X   INSTLIBFLAGS = -m 0664
X   INSTINCFLAGS = -m 0444
X   INSTMANFLAGS = -m 0444
X   INSTAPPFLAGS = -m 0444
X  INSTKMEMFLAGS = -m 4755
X        FCFLAGS = -t
X    CDEBUGFLAGS = -O
X
X        PATHSEP = /
X         DEPEND = $(BINDIR)/makedepend
X          IMAKE = $(BINDIR)/imake
X            RGB = $(LIBDIR)/rgb
X             FC = $(BINDIR)/bdftosnf
X      MKFONTDIR = $(BINDIR)/mkfontdir
X      MKDIRHIER = $(BINDIR)/mkdirhier.sh
X
X         CFLAGS = $(CDEBUGFLAGS) $(INCLUDES) $(STD_DEFINES) $(DEFINES)
X      LINTFLAGS = $(LINTOPTS) $(INCLUDES) $(STD_DEFINES) $(DEFINES) -DLINT
X        LDFLAGS = $(CDEBUGFLAGS) -L$(USRLIBDIR) $(SYS_LIBRARIES) $(SYSAUX_LIBRARIES)
X
X       IRULESRC = $(LIBDIR)/imake.includes
X
X   EXTENSIONLIB = $(USRLIBDIR)/libext.a
X           XLIB = $(USRLIBDIR)/libX11.a
X         XMULIB = $(USRLIBDIR)/libXmu.a
X        OLDXLIB = $(USRLIBDIR)/liboldX.a
X       XTOOLLIB = $(USRLIBDIR)/libXt.a
X         XAWLIB = $(USRLIBDIR)/libXaw.a
X       LINTXLIB = $(USRLIBDIR)/lint/llib-lX11.ln
X        LINTXMU = $(USRLIBDIR)/lint/llib-lXmu.ln
X      LINTXTOOL = $(USRLIBDIR)/lint/llib-lXt.ln
X        LINTXAW = $(USRLIBDIR)/lint/llib-lXaw.ln
X       INCLUDES = -I$(INCDIR)
X      MACROFILE = Sun.macros
X   ICONFIGFILES = $(IRULESRC)/Imake.tmpl \
X			$(IRULESRC)/$(MACROFILE) $(IRULESRC)/site.def
X  IMAKE_DEFINES =
X      IMAKE_CMD = $(NEWTOP)$(IMAKE) -TImake.tmpl -I$(NEWTOP)$(IRULESRC) \
X			-s Makefile $(IMAKE_DEFINES)
X         RM_CMD = $(RM) *.CKP *.ln *.BAK *.bak *.o core errs ,* *~ *.a \
X			.emacs_* tags TAGS make.log MakeOut
X
X###########################################################################
X# rules:  $XConsortium: Imake.rules,v 1.71 88/10/23 22:46:34 jim Exp $
X
X###########################################################################
X# start of Imakefile
X
X      SYS_LIBRARIES = -lX11
X
X OBJS = chaos.o
X SRCS = chaos.c
X
X PROGRAM = chaos
X
Xall:: chaos
X
Xchaos: $(OBJS) $(LOCAL_LIBRARIES)
X	$(RM) $@
X	$(CC) -o $@ $(OBJS) $(LOCAL_LIBRARIES) $(LDFLAGS) $(SYSLAST_LIBRARIES)
X
Xrelink::
X	$(RM) $(PROGRAM)
X	$(MAKE) $(MFLAGS) $(PROGRAM)
X
Xinstall:: chaos
X	$(INSTALL) -c $(INSTALLFLAGS) chaos $(BINDIR)
X
Xinstall.man:: chaos.man
X	$(INSTALL) -c $(INSTMANFLAGS) chaos.man $(MANDIR)/chaos.n
X
Xdepend:: $(DEPEND)
X
Xdepend::
X	$(DEPEND) -s "# DO NOT DELETE" -- $(CFLAGS) -- $(SRCS)
X
X$(DEPEND):
X	@echo "making $@"; \
X	cd $(DEPENDSRC); $(MAKE)
X
Xclean::
X	$(RM) $(PROGRAM)
X
Xlint:
X	$(LINT) $(LINTFLAGS) chaos.c $(LINTLIBS)
Xlint1:
X	$(LINT) $(LINTFLAGS) $(FILE) $(LINTLIBS)
X
X###########################################################################
X# Imake.tmpl common rules for all Makefiles - do not edit
X
Xemptyrule::
X
Xclean::
X	$(RM_CMD) \#*
X
XMakefile:: $(IMAKE)
X
XMakefile:: Imakefile \
X	$(IRULESRC)/Imake.tmpl \
X	$(IRULESRC)/Imake.rules \
X	$(IRULESRC)/site.def \
X	$(IRULESRC)/$(MACROFILE)
X	-@if [ -f Makefile ]; then \
X	echo "$(RM) Makefile.bak; $(MV) Makefile Makefile.bak"; \
X	$(RM) Makefile.bak; $(MV) Makefile Makefile.bak; \
X	else exit 0; fi
X	$(IMAKE_CMD) -DTOPDIR=$(TOP)
X
X$(IMAKE):
X	@echo "making $@"; \
X	cd $(IMAKESRC); $(MAKE) BOOTSTRAPCFLAGS=$(BOOTSTRAPCFLAGS)
X
Xtags::
X	$(TAGS) -w *.[ch]
X	$(TAGS) -xw *.[ch] > TAGS
X
X###########################################################################
X# empty rules for directories that do not have SUBDIRS - do not edit
X
Xinstall::
X	@echo "install done"
X
Xinstall.man::
X	@echo "install.man done"
X
XMakefiles::
X
X###########################################################################
X# dependencies generated by makedepend
X
END_OF_FILE
if test 6499 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'chaos.1' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'chaos.1'\"
else
echo shar: Extracting \"'chaos.1'\" \(4981 characters\)
sed "s/^X//" >'chaos.1' <<'END_OF_FILE'
X.TH CHAOS 1
X.PD
X.ad b
X.SH NAME
Xchaos \- The Chaos Game for X11
X.SH SYNOPSIS
X.TP \w'\fBchaos\fR 'u
X\fBchaos\fR
X[\|\fB-bd\fR border\|] [\|\fB-bg\fR background\|] [\|\fB-bw\fR borderwidth\|]
X[\|\fB-delay\fR msec\|] [\|\fB-display\fR displayname\|]
X[\|\fB-geometry\fR geometry\|]
X[\|\fB-mpoints\fR\|]
X[\|\fB-out\fR bitmapfile\|]
X[\|\fB-points\fR x1,y1\|[\|,x1,y2\|[\|,x3,y3\|[\|,...\|]\|]\|]\|]
X[\|\fB-udelay\fR msec\|]
X.SH HP-UX COMPATIBILITY
X.TP 10
XOrigin:
XUser Contributed
X.SH DESCRIPTION
X.I Chaos
Xplays ``The Chaos Game'' in an X11 window.  The Chaos Game, as described
Xon television's ``Nova'' program (``The Strange New Science of Chaos'',
Xoriginally broadcast 31 January 1989), is a simple exercise demonstrating
X\&``strange attractors'', one of the fundamental concepts in the science
Xof chaos.
X.PP
XTo play The Chaos Game:
X.TP 4n
X1)
XDraw three dots on a piece of paper, corresponding to the three
Xvertices of an equilateral triangle.
X.TP
X2)
XRandomly select a point on the paper, call it
XP\v'+.2v'\s-20\v'-.2v'\s0.
X.TP
X3)
XRandomly select one of the three vertices.
X.TP
X4)
XGenerate P\v'+.2v'\s-2n\v'-.2v'\s0 as the point midway between
XP\v'+.2v'\s-2n-1\v'-.2v'\s0 and the selected vertex.
X.TP
X5)
XRepeat steps 3 and 4 ad infinitum, plotting the P values generated.
X.PP
XWhat will emerge from this random walk is \fInot\fR a page covered with
Xdots, but a beautiful structure containing triangles within triangles
Xwithin triangles.
X.PP
X\fIChaos\fR plays the game as described above.  It generates a
XP\v'+.2v'\s-20\v'-.2v'\s0 randomly somewhere within the window, then
Xgenerates and plots successive P values ad infinitum.  The \fB-points\fR
Xand \fB-mpoints\fR command-line options allows the user to specify
Xshapes other than the default triangle.
X.PP
XOptions:
X.TP .5i
X.B -bd
XSpecify border color; defaults to white.
X.TP
X.B -bg
XSpecify background color; defaults to black.
X.TP
X.B -bw
XSpecify border width in pixels; defaults to 2.
X.TP
X.B -delay
XSpecify a delay (in msec) to be performed between drawing each point.
XDefaults to 10.
X.TP
X.B -display
XSpecify display on which to run; defaults to contents of DISPLAY
Xenvironment variable.
X.TP
X.B -geometry
XSpecify window geometry; defaults to =300x300+0+0.
X.TP
X.B -mpoints
XAllows you to define your own shape other than the default triangle.
XYou use the cursor to place the vertices: clicking button 1 defines
Xa vertex at the current cursor position, clicking button 3 terminates
Xvertex-definition mode and begins \fIchaos\fR operation.
X.TP
X.B -out
XSpecify filename into which \fIchaos\fR will dump (on request) a bitmap
Xof its current picture.  Defaults to ``chaos.xbm''.  This feature is
Xexplained below in the section on ``BUTTON BEHAVIOR''.
X.TP
X.B -points
XAllows you to specify a set of starting vertices on the command line.
XPoint values are expressed in floating-point, where (0.0,0.0) maps to
Xthe window's upper left and (1.0,1.0) maps to window's lower right.
XCoordinates outside of the window are permissible.  This option can be
Xused to specify any number of points (although fewer than three tends to
Xbe uninteresting).  This option is overridden by the \fB-mpoints\fR
Xoption.
X.TP
X.B -udelay
XNormally, \fIchaos\fR computes and renders its P values only when the
Xwindow is mapped.  If the \fB-udelay\fR option is used, \fIchaos\fR will
Xcontinue to crank away when the window is unmapped (for example,
Xiconified), using the delay value specified with this option.  The
Xpoints computed while the window is unmapped will appear when the window
Xis again mapped.
X.SH NOTE
XSpecifying a delay value of 0 will cause \fIchaos\fR to draw into
Xits window at top speed, bogging down your server and, if
X\fIchaos\fR is run remotely, your network.  The default delay value
Xwas chosen to work well on a fast CPU with a fast X server \(em it is
Xprobably too low for many systems.
X.PP
XIf \fIchaos\fR and the server are running on the same CPU, running
X\fIchaos\fR with a higher nice (nice(1)) value will usually produce
Xgood results without 1) swamping the server, and 2) requiring you to
Ximpose an unpleasantly long delay.
X.PP
XResizing the \fIchaos\fR window will cause \fIchaos\fR to clear the
Xwindow and start over.  \fIChaos\fR will generate a new starting point
Xrandomly somewhere within the resized window.
X.SH "BUTTON BEHAVIOR"
XTwo pointer buttons are active in the \fIchaos\fR window:
X.TP .5i
X.B "Button 1"
XButton 1 will cause the \fIchaos\fR window to be cleared.  \fIChaos\fR
Xwill \fInot\fR generate a new starting point \(em it will use the
Xcurrent point as the starting point.  (This is a nice way to generate a
X\fIchaos\fR display without the droppings from the first few P values.)
X.TP
X.B "Button 3"
XButton 2 will cause \fIchaos\fR to create a bitmap file containing its
Xcurrent picture.  Unless changed with the \fB-out\fR option, the
Xfile will be named ``chaos.xbm''.
X.SH EXAMPLES
Xchaos -delay 0
X.sp .5
Xchaos -points 0,0,.3,1,.7,1,1,0
X.SH AUTHORSHIP
X\fIChaos\fR was authored by Nathan Meyers of Hewlett-Packard
X(nathanm@hp-pcd).
END_OF_FILE
if test 4981 -ne `wc -c <'chaos.1'`; then
    echo shar: \"'chaos.1'\" unpacked with wrong size!
fi
# end of 'chaos.1'
fi
if test -f 'chaos.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'chaos.c'\"
else
echo shar: Extracting \"'chaos.c'\" \(12804 characters\)
sed "s/^X//" >'chaos.c' <<'END_OF_FILE'
X#include <stdio.h>
X#include <X11/X.h>
X#include <X11/Xlib.h>
X#include <X11/Xutil.h>
X#include <X11/Xos.h>
X#include <X11/cursorfont.h>
X#include "chaosicon.h"
X
X/*
X
X  The CHAOS Game
X
X  As demonstrated on "Nova", 1/31/89
X
X  By Nathan Meyers, nathanm@hp-pcd.hp.com.
X
X*/
X
X#define DOTSPERCALL 20
X
Xchar *progname;
X
Xstatic char *what = "@(#)chaos.c $Revision: 1.13 $";
X
Xstruct dattract {
X  double x,y;
X} dpoints[3] = { { 0.1, 0.153589838486 },
X		 { 0.9, 0.153589838486 },
X		 { 0.5, 0.846410161513 } };
X
Xstruct dattract *fpoints = dpoints;
Xint npoints = 3;
Xchar *strchr();
X
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
X  Display *display;
X  int screen;
X  Window win;
X  Pixmap bitmapicon, bitmap;
X  GC bitmapgc1, bitmapgc2, wingc;
X  XGCValues values;
X  unsigned long fgcolor, bgcolor, bdcolor;
X  int bwidth = 2;
X  XSizeHints size_hints;
X  XWMHints wm_hints;
X  char *displayname = NULL;
X  char *foreground = NULL, *background = NULL, *border = NULL;
X  char *geomstring = NULL;
X  XColor visual_def_return, exact_def_return;
X  XEvent event;
X  int o_argc = argc;
X  char **o_argv = argv;
X  int i,j;
X  char *basename;
X  int width, height;
X  int mapped=0;
X  long delayvalue = 10L;
X  long udelayvalue = -1L;
X  long rndm();
X  double drand48(), x, y;
X  char *bitmapfilename = "chaos.xbm";
X  char *pointlist = NULL;
X  int manpoints = 0;
X  double time();
X
X  progname = argv[0];
X
X  if ((basename=strrchr(progname,'/'))!=NULL) basename++;
X  else basename=progname;
X
X  while (--argc>0) {
X    char *option = (*++argv);
X    if (!strcmp(option,"-delay")) {
X      if (--argc==0) usage();
X      delayvalue = atol(*++argv);
X      if (delayvalue < 0) delayvalue = 0;
X    }
X    else if (!strcmp(option,"-udelay")) {
X      if (--argc==0) usage();
X      udelayvalue = atol(*++argv);
X      if (udelayvalue < 0) udelayvalue = 0;
X    }
X    else if (!strcmp(option,"-display")) {
X      if (--argc==0) usage();
X      displayname = (*++argv);
X    }
X    else if (strchr(option,':')) {
X      displayname = option;
X    }
X    else if (!strcmp(option,"-fg")) {
X      if (--argc==0) usage();
X      foreground = (*++argv);
X    }
X    else if (!strcmp(option,"-bg")) {
X      if (--argc==0) usage();
X      background = (*++argv);
X    }
X    else if (!strcmp(option,"-bd")) {
X      if (--argc==0) usage();
X      border = (*++argv);
X    }
X    else if (!strcmp(option,"-bw")) {
X      if (--argc==0) usage();
X      bwidth = atoi(*++argv);
X      if (bwidth<0) bwidth = 0;
X    }
X    else if (!strcmp(option,"-geometry")) {
X      if (--argc==0) usage();
X      geomstring = (*++argv);
X    }
X    else if (*option=='=') {
X      geomstring = option;
X    }
X    else if (!strcmp(option,"-mpoints")) {
X      manpoints = 1;
X    }
X    else if (!strcmp(option,"-out")) {
X      if (--argc==0) usage();
X      bitmapfilename = (*++argv);
X    }
X    else if (!strcmp(option,"-points")) {
X      if (--argc==0) usage();
X      pointlist = (*++argv);
X    }
X    else usage();
X  }
X
X  if (!manpoints && pointlist != NULL) {
X    char *temp = pointlist;
X    char *calloc();
X    double strtod();
X    int commacount = 0;
X    int len;
X    while (*temp != '\0') commacount += (*(temp++) == ',') ? 1 : 0;
X    if (!(commacount & 0x1)) usage();
X    npoints = (commacount >> 1) + 1;
X    fpoints = (struct dattract *)calloc(npoints, sizeof(struct dattract));
X    if (fpoints == NULL) {
X      fprintf(stderr,"%s: calloc() failed\n",progname);
X      exit(1);
X    }
X    for (i=0; i<npoints; i++) {
X      fpoints[i].x = strtod(pointlist, &temp);
X      if (temp == pointlist) usage();
X      pointlist = strchr(temp, ',') + 1;
X      fpoints[i].y = strtod(pointlist, &temp);
X      if (temp == pointlist) usage();
X      pointlist = strchr(temp, ',') + 1;
X    }
X  }
X
X  display = XOpenDisplay(displayname);
X  if (display==NULL) {
X    (void)fprintf(stderr,
X	          (displayname==NULL) ?
X	          "%s: Failed to open display.\n" :
X	          "%s: Failed to open display %s.\n",
X	          progname,displayname);
X    exit(1);
X  }
X  screen = DefaultScreen(display);
X
X  srand48(time((long *)NULL));
X  x = drand48();
X  y = drand48();
X
X  if (background == NULL ||
X      XAllocNamedColor(display,
X		       DefaultColormap(display,screen),
X		       background,
X		       &visual_def_return,
X		       &exact_def_return)==False)
X    bgcolor = WhitePixel(display,screen);
X  else bgcolor = exact_def_return.pixel;
X
X  if (foreground==NULL ||
X      XAllocNamedColor(display,
X		       DefaultColormap(display,screen),
X		       foreground,
X		       &visual_def_return,
X		       &exact_def_return)==False)
X   fgcolor = BlackPixel(display,screen);
X  else fgcolor = exact_def_return.pixel;
X
X  if (border==NULL ||
X      XAllocNamedColor(display,
X		       DefaultColormap(display,screen),
X		       border,
X		       &visual_def_return,
X		       &exact_def_return)==False)
X   bdcolor = BlackPixel(display,screen);
X  else bdcolor = exact_def_return.pixel;
X
X  size_hints.x = 0;
X  size_hints.y = 0;
X  size_hints.width = 300;
X  size_hints.height = 300;
X
X  size_hints.flags = PPosition | PSize;
X  if (geomstring!=NULL) {
X    int result;
X    result = XParseGeometry(geomstring,&size_hints.x,&size_hints.y,
X		            &size_hints.width,&size_hints.height);
X    if (result & XNegative)
X      size_hints.x += DisplayWidth(display,screen)
X		    - size_hints.width
X		    - bwidth*2;
X    if (result & YNegative)
X      size_hints.y += DisplayHeight(display,screen)
X		    - size_hints.height
X		    - bwidth*2;
X    if (result & XValue || result & YValue) {
X      size_hints.flags |= USPosition;
X      size_hints.flags &= ~PPosition;
X    }
X    if (result & WidthValue || result & HeightValue) {
X      size_hints.flags |= USSize;
X      size_hints.flags &= ~PSize;
X    }
X  }
X
X  width = size_hints.width;
X  height = size_hints.height;
X  if (width < 1) width = 1;
X  if (height < 1) height = 1;
X
X  win = XCreateSimpleWindow(display,RootWindow(display,screen),
X			       size_hints.x,size_hints.y,
X			       size_hints.width,size_hints.height,
X			       bwidth,bdcolor,bgcolor);
X
X  values.foreground = fgcolor;
X  values.background = bgcolor;
X  wingc = XCreateGC(display, win, GCForeground|GCBackground, &values);
X
X  bitmap = XCreatePixmap(display, win, width, height, 1);
X
X  values.foreground = 0;
X  bitmapgc1 = XCreateGC(display, bitmap, GCForeground, &values);
X  XFillRectangle(display, bitmap, bitmapgc1, 0, 0, width, height);
X
X  values.foreground = 1;
X  bitmapgc2 = XCreateGC(display, bitmap, GCForeground, &values);
X
X  XSetStandardProperties(display,win,"Chaos",basename,
X			 None,o_argv,o_argc,&size_hints);
X
X  bitmapicon=XCreateBitmapFromData(display,RootWindow(display,screen),
X				   chaosicon_bits, chaosicon_width,
X				   chaosicon_height);
X
X  wm_hints.icon_pixmap = bitmapicon;
X  wm_hints.flags = IconPixmapHint;
X  XSetWMHints(display,win,&wm_hints);
X
X  XSelectInput(display,win, StructureNotifyMask|ExposureMask|ButtonPressMask);
X  XMapWindow(display,win);
X
X  if (manpoints) {
X    Cursor cursor = XCreateFontCursor(display, XC_cross);
X    XDefineCursor(display, win, cursor);
X    fpoints = NULL;
X    npoints = 0;
X    for (;;) {
X      XEvent event;
X      XNextEvent(display, &event);
X      if (event.type == ButtonPress) {
X        if (event.xbutton.button == Button3 && npoints) {
X	  XUndefineCursor(display,win);
X	  XClearWindow(display, win);
X	  break;
X        }
X	else if (event.xbutton.button == Button1) {
X	  char *calloc(), *realloc();
X	  if (fpoints == NULL)
X    	    fpoints = (struct dattract *)calloc(++npoints,
X			sizeof(struct dattract));
X	  else
X    	    fpoints = (struct dattract *)realloc(fpoints,
X			++npoints * sizeof(struct dattract));
X	  if (fpoints == NULL) {
X	    fprintf(stderr,"%s: Memory allocation failed\n",progname);
X	    exit(1);
X	  }
X	  fpoints[npoints-1].x = (double)(event.xbutton.x)/(double)(width-1);
X	  fpoints[npoints-1].y = (double)(event.xbutton.y)/(double)(height-1);
X	}
X      }
X      else if (event.type == ConfigureNotify) {
X        if (event.xconfigure.width != width ||
X            event.xconfigure.height != height ) {
X
X	  XClearWindow(display, win);
X
X	  width = event.xconfigure.width;
X	  height = event.xconfigure.height;
X  	  if (width < 1) width = 1;
X  	  if (height < 1) height = 1;
X
X	  XFreePixmap(display, bitmap);
X	  XFreeGC(display, bitmapgc1);
X	  XFreeGC(display, bitmapgc2);
X
X          bitmap = XCreatePixmap(display, win, width, height, 1);
X
X          values.foreground = 0;
X          bitmapgc1 = XCreateGC(display, bitmap, GCForeground, &values);
X          XFillRectangle(display, bitmap, bitmapgc1, 0, 0, width, height);
X
X          values.foreground = 1;
X          bitmapgc2 = XCreateGC(display, bitmap, GCForeground, &values);
X        }
X      }
X      else if (event.type == MapNotify) mapped=1;
X      else if (event.type == UnmapNotify) mapped=0;
X
X      XClearWindow(display, win);
X      for (i=0; i<npoints; i++) {
X	XDrawArc(display, win, wingc,
X		 (int)(fpoints[i].x * (double)(width-1))-2,
X		 (int)(fpoints[i].y * (double)(height-1))-2,
X		 5, 5, 0, 360*64);
X      }
X
X    }
X  }
X
X  for (;;) {
X    XEvent event;
X    if (mapped || udelayvalue != -1)
X      while (XCheckWindowEvent(display, win, ~0L, &event) == False) {
X        int ix, iy;
X        if (mapped && delayvalue || !mapped && udelayvalue) {
X	  struct timeval delaystruct;
X	  int fd = ConnectionNumber(display);
X	  int readfds = 1<<fd;
X	  long delay = mapped ? delayvalue : udelayvalue;
X          getnextpoint(&x, &y, &ix, &iy, width, height);
X          XFillRectangle(display, win, wingc, ix, iy, 1, 1);
X          XFillRectangle(display, bitmap, bitmapgc2, ix, iy, 1, 1);
X	  if (mapped) XFlush(display);
X	  delaystruct.tv_sec = delay/1000;
X	  delaystruct.tv_usec = (delay%1000) * 1000;
X	  (void)select(fd+1, &readfds, NULL, NULL, &delaystruct);
X        }
X        else {
X	  XRectangle rects[DOTSPERCALL];
X	  for (i=0; i<DOTSPERCALL; i++) {
X            getnextpoint(&x, &y, &ix, &iy, width, height);
X	    rects[i].x = ix;
X	    rects[i].y = iy;
X	    rects[i].width = 1;
X	    rects[i].height = 1;
X	  }
X	  XFillRectangles(display, win, wingc, rects, DOTSPERCALL);
X	  XFillRectangles(display, bitmap, bitmapgc2, rects, DOTSPERCALL);
X        }
X    }
X    else XNextEvent(display, &event);
X    if (event.type == ConfigureNotify) {
X      if (event.xconfigure.width != width ||
X          event.xconfigure.height != height ) {
X
X	XClearWindow(display, win);
X
X	width = event.xconfigure.width;
X	height = event.xconfigure.height;
X  	if (width < 1) width = 1;
X  	if (height < 1) height = 1;
X
X	XFreePixmap(display, bitmap);
X	XFreeGC(display, bitmapgc1);
X	XFreeGC(display, bitmapgc2);
X
X        bitmap = XCreatePixmap(display, win, width, height, 1);
X
X        values.foreground = 0;
X        bitmapgc1 = XCreateGC(display, bitmap, GCForeground, &values);
X        XFillRectangle(display, bitmap, bitmapgc1, 0, 0, width, height);
X
X        values.foreground = 1;
X        bitmapgc2 = XCreateGC(display, bitmap, GCForeground, &values);
X      }
X    }
X    else if (event.type == MapNotify) mapped=1;
X    else if (event.type == UnmapNotify) mapped=0;
X    else if (event.type == Expose) {
X      XCopyPlane(display, bitmap, win, wingc,
X		 event.xexpose.x, event.xexpose.y, 
X		 event.xexpose.width, event.xexpose.height, 
X		 event.xexpose.x, event.xexpose.y, 0x1);
X    }
X    else if (event.type == ButtonPress) {
X      if (event.xbutton.button == Button3) {
X	XBell(display, 100);
X	XFlush(display);
X	XWriteBitmapFile(display, bitmapfilename, bitmap,
X			 width, height, -1, -1);
X	XBell(display, 100);
X	XFlush(display);
X      }
X      else if (event.xbutton.button == Button1) {
X	XClearWindow(display, win);
X        XFillRectangle(display, bitmap, bitmapgc1, 0, 0, width, height);
X      }
X    }
X  }
X}
X
Xgetnextpoint(x, y, ix, iy, width, height)
Xdouble *x, *y;
Xint *ix, *iy;
Xint width, height;
X{
X  long rndm();
X  int dest;
X  dest = (int)rndm((long)npoints);
X  *x = (fpoints[dest].x + *x)/2.0;
X  *y = (fpoints[dest].y + *y)/2.0;
X  *ix = (int)(*x * width + .5);
X  *iy = (int)(*y * height + .5);
X}
X
Xusage()
X{
X  int i,j,spaces,xloc;
X  static char *options[] = {
X    "[-bd <border>]",
X    "[-bg <background>]",
X    "[-bw <borderwidth>]",
X    "[-delay <msec>]",
X    "[-display <displayname>]",
X    "[-geometry <geometry>]",
X    "[-mpoints]",
X    "[-out <bitmapfile>]",
X    "[-points <x1>,<y1>[,<x2>,<y2>[,<x3>,<y3>[,...]]]]",
X    "[-udelay <msec>]"
X  };
X  (void)fprintf(stderr,"Usage: %s", progname);
X  spaces=strlen(progname)+7;
X  xloc=spaces;
X
X  for (j=0; j<(sizeof(options)/sizeof(char *)); j++) {
X    if (xloc+strlen(options[j]) > 78) {
X      putc('\n',stderr);
X      for (i = 0; i<spaces; i++) (void)putc(' ',stderr);
X      xloc=spaces;
X    }
X    xloc += strlen(options[j])+1;
X    fprintf(stderr," %s",options[j]);
X  }
X  putc('\n',stderr);
X
X  exit(1);
X}
X
Xlong rndm(maxval)
Xlong maxval;
X{
X  long lrand48();
X  int sr1=15, sr2=16;
X  long mv=maxval;
X  while (mv > 0x8000L) {
X    sr1++;
X    sr2--;
X    mv >>= 1;
X  }
X  return ((lrand48() >> sr1) * maxval) >> sr2;
X}
END_OF_FILE
if test 12804 -ne `wc -c <'chaos.c'`; then
    echo shar: \"'chaos.c'\" unpacked with wrong size!
fi
# end of 'chaos.c'
fi
if test -f 'chaosicon.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'chaosicon.h'\"
else
echo shar: Extracting \"'chaosicon.h'\" \(2279 characters\)
sed "s/^X//" >'chaosicon.h' <<'END_OF_FILE'
X#define chaosicon_width 50
X#define chaosicon_height 50
Xstatic char chaosicon_bits[] = {
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0xe0, 0x7b, 0xef, 0xbd,
X   0xf7, 0x3e, 0x00, 0xc0, 0x7b, 0xef, 0xbd, 0xf7, 0x1e, 0x00, 0x80, 0x31,
X   0xc6, 0x18, 0x63, 0x0c, 0x00, 0x80, 0x3f, 0x7e, 0xf8, 0xe3, 0x0f, 0x00,
X   0x00, 0x1f, 0x7c, 0xf0, 0xc1, 0x07, 0x00, 0x00, 0x0e, 0x38, 0xe0, 0x80,
X   0x03, 0x00, 0x00, 0x0e, 0x38, 0xe0, 0x80, 0x03, 0x00, 0x00, 0xfc, 0x1f,
X   0xc0, 0xff, 0x01, 0x00, 0x00, 0xfc, 0x1f, 0xc0, 0xff, 0x01, 0x00, 0x00,
X   0x78, 0x0f, 0x80, 0xf7, 0x00, 0x00, 0x00, 0x78, 0x0f, 0x80, 0xf7, 0x00,
X   0x00, 0x00, 0x30, 0x06, 0x00, 0x63, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x00,
X   0x3e, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x3e, 0x00, 0x00, 0x00, 0xc0,
X   0x01, 0x00, 0x1c, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x1c, 0x00, 0x00,
X   0x00, 0x80, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x07,
X   0x00, 0x00, 0x00, 0x00, 0xef, 0xbd, 0x07, 0x00, 0x00, 0x00, 0x00, 0xee,
X   0xbd, 0x03, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x18, 0x03, 0x00, 0x00, 0x00,
X   0x00, 0xfc, 0xf8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xf0, 0x01, 0x00,
X   0x00, 0x00, 0x00, 0x38, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0xe0,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0xe0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x3d, 0x00, 0x00, 0x00,
X   0x00, 0x00, 0xc0, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x18, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x80, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
X   0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0x00};
END_OF_FILE
if test 2279 -ne `wc -c <'chaosicon.h'`; then
    echo shar: \"'chaosicon.h'\" unpacked with wrong size!
fi
# end of 'chaosicon.h'
fi
if test -f 'patchlevel.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'patchlevel.h'\"
else
echo shar: Extracting \"'patchlevel.h'\" \(21 characters\)
sed "s/^X//" >'patchlevel.h' <<'END_OF_FILE'
X#define PATCHLEVEL 0
END_OF_FILE
if test 21 -ne `wc -c <'patchlevel.h'`; then
    echo shar: \"'patchlevel.h'\" unpacked with wrong size!
fi
# end of 'patchlevel.h'
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 the archive.
    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
Moderator of comp.sources.x