v05i003: xfroot - fractal root windows, Part01/01
Dan Heller
argv at island.uu.net
Mon Sep 25 03:39:11 AEST 1989
Submitted-by: Ed Kubaitis <uunet!ux1.cso.uiuc.edu!ejk>
Posting-number: Volume 5, Issue 3
Archive-name: xfroot/part01
xfroot provides something like 1e48 new monochrome things to have in your
root window. (Just what the world needs.)
BTW, thank you for your efforts in providing this service.
Ed Kubaitis (ejk at ux1.cso.uiuc.edu)
Computing Services Office
University of Illinois, Urbana
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create:
# Imakefile
# Makefile
# README
# xfroot.c
# xfroot.man
# This archive created: Sat Sep 23 12:20:19 1989
export PATH; PATH=/bin:/usr/bin:$PATH
if test -f 'Imakefile'
then
echo shar: "will not over-write existing file 'Imakefile'"
else
cat << \SHAR_EOF > 'Imakefile'
INCLUDES = -I$(TOP) -I$(TOP)/X11
LOCAL_LIBRARIES = $(XLIB)
SYS_LIBRARIES = -lm
SRCS = xfroot.c
OBJS = xfroot.o
SimpleProgramTarget(xfroot)
SHAR_EOF
fi
if test -f 'Makefile'
then
echo shar: "will not over-write existing file 'Makefile'"
else
cat << \SHAR_EOF > 'Makefile'
# Makefile generated by imake - do not edit!
# $XConsortium: imake.c,v 1.37 88/10/08 20:08:30 jim Exp $
###########################################################################
# X Window System Makefile generated from template file Imake.tmpl
# $XConsortium: Imake.tmpl,v 1.91 88/10/23 22:37:10 jim Exp $
#
# Do not change the body of the imake template file. Server-specific
# parameters may be set in the appropriate .macros file; site-specific
# parameters (but shared by all servers) may be set in site.def. If you
# make any changes, you'll need to rebuild the makefiles using
# "make World" (at best) or "make Makefile; make Makefiles" (at least) in
# the top level directory.
#
# If your C preprocessor doesn't define any unique symbols, you'll need
# to set BOOTSTRAPCFLAGS when rebuilding imake (usually when doing
# "make Makefile", "make Makefiles", or "make World").
#
# If you absolutely can't get imake to work, you'll need to set the
# variables at the top of each Makefile as well as the dependencies at the
# bottom (makedepend will do this automatically).
#
###########################################################################
# platform-specific configuration parameters - edit Sqnt.macros to change
# P = &
TOP = TOPDIR
BOOTSTRAPCFLAGS =
AS = as
CC = cc
CPP = /lib/cpp
LD = ld
LINT = lint
INSTALL = install
TAGS = ctags
RM = rm -f
MV = mv
LN = ln -s
RANLIB = ranlib
AR = ar clq
LS = ls
LINTOPTS = -axz
LINTLIBFLAG = -C
MAKE = make
STD_DEFINES =
CDEBUGFLAGS = -O
DESTDIR =
###########################################################################
# site-specific configuration parameters - edit site.def to change
# site: $XConsortium: site.def,v 1.16 88/10/12 10:30:24 jim Exp $
###########################################################################
# definitions common to all Makefiles - do not edit
SHELL = /bin/sh
DESTDIR =
USRLIBDIR = $(DESTDIR)/usr/lib
BINDIR = $(DESTDIR)/usr/bin/X11
INCDIR = $(DESTDIR)/usr/include/X11
ADMDIR = $(DESTDIR)/usr/adm
LIBDIR = $(USRLIBDIR)/X11
LINTLIBDIR = $(USRLIBDIR)/lint
FONTDIR = $(LIBDIR)/fonts
XINITDIR = $(LIBDIR)/xinit
XDMDIR = $(LIBDIR)/xdm
UWMDIR = $(LIBDIR)/uwm
AWMDIR = $(LIBDIR)/awm
TWMDIR = $(LIBDIR)/twm
MANPATH = $(DESTDIR)/usr/man
MANSOURCEPATH = $(MANPATH)/man
MANDIR = $(MANSOURCEPATH)n
LIBMANDIR = $(MANSOURCEPATH)3
XAPPLOADDIR = $(LIBDIR)/app-defaults
INSTBINFLAGS = -m 0755
INSTUIDFLAGS = -m 4755
INSTLIBFLAGS = -m 0664
INSTINCFLAGS = -m 0444
INSTMANFLAGS = -m 0444
INSTAPPFLAGS = -m 0444
INSTKMEMFLAGS = -m 4755
FCFLAGS = -t
CDEBUGFLAGS = -O
PATHSEP = /
DEPEND = makedepend
IMAKE = imake
RGB = $(RGBSRC)/rgb
FC = $(BDFTOSNFSRC)/bdftosnf
MKFONTDIR = $(MKFONTDIRSRC)/mkfontdir
MKDIRHIER = $(SCRIPTSSRC)/mkdirhier.sh
CFLAGS = $(CDEBUGFLAGS) $(INCLUDES) $(STD_DEFINES) $(DEFINES)
LINTFLAGS = $(LINTOPTS) $(INCLUDES) $(STD_DEFINES) $(DEFINES) -DLINT
LDFLAGS = $(CDEBUGFLAGS) $(SYS_LIBRARIES) $(SYSAUX_LIBRARIES)
TOP = TOPDIR
CLIENTSRC = $(TOP)/clients
DEMOSRC = $(TOP)/demos
LIBSRC = $(TOP)/lib
FONTSRC = $(TOP)/fonts
INCLUDESRC = $(TOP)/X11
SERVERSRC = $(TOP)/server
UTILSRC = $(TOP)/util
SCRIPTSSRC = $(UTILSRC)/scripts
EXAMPLESRC = $(TOP)/examples
CONTRIBSRC = $(TOP)/contrib
DOCSRC = $(TOP)/doc
RGBSRC = $(TOP)/rgb
DEPENDSRC = $(UTILSRC)/makedepend
IMAKESRC = $(UTILSRC)/imake
IRULESRC = $(UTILSRC)/imake.includes
XLIBSRC = $(LIBSRC)/X
XMUSRC = $(LIBSRC)/Xmu
TOOLKITSRC = $(LIBSRC)/Xt
AWIDGETSRC = $(LIBSRC)/Xaw
OLDXLIBSRC = $(LIBSRC)/oldX
BDFTOSNFSRC = $(FONTSRC)/bdftosnf
MKFONTDIRSRC = $(FONTSRC)/mkfontdir
EXTENSIONSRC = $(TOP)/extensions
EXTENSIONLIB = $(EXTENSIONSRC)/lib/libXext.a
XLIB = $(XLIBSRC)/libX11.a
XMULIB = $(XMUSRC)/libXmu.a
OLDXLIB = $(OLDXLIBSRC)/liboldX.a
XTOOLLIB = $(TOOLKITSRC)/libXt.a
XAWLIB = $(AWIDGETSRC)/libXaw.a
LINTXLIB = $(XLIBSRC)/llib-lX11.ln
LINTXMU = $(XMUSRC)/llib-lXmu.ln
LINTXTOOL = $(TOOLKITSRC)/llib-lXt.ln
LINTXAW = $(AWIDGETSRC)/llib-lXaw.ln
INCLUDES = -I$(TOP)
MACROFILE = Sqnt.macros
ICONFIGFILES = $(IRULESRC)/Imake.tmpl \
$(IRULESRC)/$(MACROFILE) $(IRULESRC)/site.def
IMAKE_DEFINES =
IMAKE_CMD = $(NEWTOP)$(IMAKE) -TImake.tmpl -I$(NEWTOP)$(IRULESRC) \
-s Makefile $(IMAKE_DEFINES)
RM_CMD = $(RM) *.CKP *.ln *.BAK *.bak *.o core errs ,* *~ *.a \
.emacs_* tags TAGS make.log MakeOut
###########################################################################
# rules: $XConsortium: Imake.rules,v 1.71 88/10/23 22:46:34 jim Exp $
#
# The following settings allow this Makefile to stand OUTSIDE of
# a complete X build tree.
#
SYS_LIBS=/usr/lib
XLIB = $(SYS_LIBS)/libX11.a
XMULIB = $(SYS_LIBS)/libXmu.a
OLDXLIB = $(SYS_LIBS)/liboldX.a
XTOOLLIB = $(SYS_LIBS)/libXt.a
XAWLIB = $(SYS_LIBS)/libXaw.a
###########################################################################
# start of Imakefile
INCLUDES = -I$(TOP) -I$(TOP)/X11
LOCAL_LIBRARIES = $(XLIB)
SYS_LIBRARIES = -lm
SRCS = xfroot.c
OBJS = xfroot.o
OBJS = xfroot.o
SRCS = xfroot.c
PROGRAM = xfroot
all:: xfroot
xfroot:$(P) $(OBJS) $(LOCAL_LIBRARIES)
$(RM) $@
$(CC) -o $@ $(OBJS) $(LOCAL_LIBRARIES) $(LDFLAGS) $(SYSLAST_LIBRARIES)
relink::
$(RM) $(PROGRAM)
$(MAKE) $(MFLAGS) $(PROGRAM)
install:: xfroot
$(INSTALL) -c $(INSTALLFLAGS) xfroot $(BINDIR)
install.man:: xfroot.man
$(INSTALL) -c $(INSTMANFLAGS) xfroot.man $(MANDIR)/xfroot.n
depend::
$(DEPEND) -s "# DO NOT DELETE" -- $(CFLAGS) -- $(SRCS)
clean::
$(RM) $(PROGRAM)
###########################################################################
# Imake.tmpl common rules for all Makefiles - do not edit
clean::
$(RM_CMD) \#*
Makefile:: $(IMAKE)
Makefile:: Imakefile \
$(IRULESRC)/Imake.tmpl \
$(IRULESRC)/Imake.rules \
$(IRULESRC)/site.def \
$(IRULESRC)/$(MACROFILE)
- at if [ -f Makefile ]; then \
echo "$(RM) Makefile.bak; $(MV) Makefile Makefile.bak"; \
$(RM) Makefile.bak; $(MV) Makefile Makefile.bak; \
else exit 0; fi
$(IMAKE_CMD) -DTOPDIR=$(TOP)
$(IMAKE):
@echo "making $@"; \
cd $(IMAKESRC); $(MAKE) BOOTSTRAPCFLAGS=$(BOOTSTRAPCFLAGS)
tags::
$(TAGS) -w *.[ch]
$(TAGS) -xw *.[ch] > TAGS
###########################################################################
# empty rules for directories that do not have SUBDIRS - do not edit
install::
@echo "install done"
install.man::
@echo "install.man done"
Makefiles::
###########################################################################
# dependencies generated by makedepend
SHAR_EOF
fi
if test -f 'README'
then
echo shar: "will not over-write existing file 'README'"
else
cat << \SHAR_EOF > 'README'
xfroot - set fractal root window (monochrome)
23 September 1989
The only tailoring needed is the definition of "HZ" in xfroot.c, and that
only if your client uses other than 60 HZ ticks in values returned by
times(3c). Clients found to have 60 HZ ticks include:
Convex C200
Sequent Symmetry
Vaxstation 2000
Vaxserver 3500
Sun 3/50 & 3/60
Clients found to have other than 60 HZ ticks:
Cray 2 (replace "#define HZ 60" with "#include <sys/param.h>"
Cray X (replace "#define HZ 60" with "#include <sys/machd.h>"
For other clients, checks the times(3c) man page.
The man page lists fractal points/cp_second measured by xfroot on the
clients listed above. I would appreciate hearing about values measured on
other platforms.
The Makefile was generated by imake on a Sequent Symmetry, but the "P = &"
(parallel make) platform-specific parameter was commented out.
Portions of xfroot.c are copyrighted by Jef Poskanzer & Craig Leres. See
their copyright and permission notice therein. For other acknowledgements,
see the comments at the beginning of xfroot.c.
Ed Kubaitis (ejk at ux1.cso.uiuc.edu)
Computing Services Office
University of Illinois, Urbana
SHAR_EOF
fi
if test -f 'xfroot.c'
then
echo shar: "will not over-write existing file 'xfroot.c'"
else
cat << \SHAR_EOF > 'xfroot.c'
/*
* xfroot - set root window to monochrome fractal
*
* xfroot [-p npoints] [-P npoints] [-a value] [-b value] [-c value]
* [-display display]
*
* -p npoints: maximum in-range points to calculate
* -P npoints: maximum total points to calculate
* defaults: -p: 25% of pixels in display
* -P: 3 * -p value
* value: floating point values for hopalong a, b, and c parameters
* (default: randomly selected)
*
* The fractal algorithm (hopalong) was adapted from A. K. Dewdney's
* "Computer Recreations" in the 9/86 Scientific American (attributed
* to Barry Martin of Aston University, Birmingham, England.)
*
* The Xlib business-end (setroot) was adapted from "xphoon" by
* Jef Poskanzer and Craig Leres.
*
* The Ranf portable random number generator is based on work by
* D. H. Lehmer, Knuth, David Sachs(Fermilab) and Curt Canada(NCSA).
*
* This software is provided "as is" and with no warranties of any kind.
*
* Ed Kubaitis
* Computing Services Office
* University of Illinois, Urbana
*/
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdio.h>
#include <math.h>
#include <stdio.h>
#include <sys/times.h>
#define HZ 60 /* see REAMDME */
#define Ranf() (double)((Ranfseed=(Ranfseed*1629+1)%1048576)/1048576.)
#define Ranfset(l) (Ranfseed=((abs(l)*1629)+1)%1048576)
long Ranfseed=4326;
int mxp=0, np=0; /* max in-range points, in-range points */
int mxP=0, nP=0; /* max total points, total points */
double A=0, B=0, C=0; /* hopalong parameters */
int W, H; /* width and height of display (pixels) */
char *bmap; /* bitmap */
int bmn; /* number of bytes in bitmap */
Display *dpy = NULL;
main(argc, argv) int argc; char *argv[]; {
struct tms t;
preset(argc, argv);
hopalong();
times(&t);
printf("xfroot: %d points %d(%d%%) in-range %d points/cp_second\n",
nP, np, (100*np)/nP,
(int)((double)nP/((double)(t.tms_utime + t.tms_stime)/(double)HZ)));
setroot(W,H,bmap);
XCloseDisplay(dpy);
exit(0);
}
hopalong() {
int wc=W/8, cx=W/2, cy=H/2, ix, iy;
double x=0, y=0, xx, yy, t;
while (np < mxp && ++nP < mxP) {
t = sqrt(fabs(B*x-C));
xx = y - ( (x<0) ? t : -t );
yy = A - x;
x = xx; y = yy;
ix = cx + x; iy = cy + y;
if (ix>-1 && iy>-1 && ix<(W-1) && iy<(H-1)) {
bmap[iy*wc+(ix>>3)] |= 1<<(ix&7);
np++;
}
}
}
hopset() {
int r = Ranfseed; double pmax=1.0*W, logpmax=log(pmax);
A = (A) ? A : exp(Ranf()*logpmax); if (r&2) A = -A;
B = (B) ? B : exp(Ranf()*logpmax); if (r&4) B = -B;
C = (C) ? C : Ranf()*pmax; if (r&8) C = -C;
}
preset(argc, argv) int argc; char *argv[]; {
char *display = NULL;
int i;
for (i=1; i<argc; i++) {
if (!strcmp(argv[i], "-p")) {
if (++i>argc) usage();
if(!sscanf(argv[i], "%d", &mxp)) usage();
if (mxp <= 0) usage();
}
else if (!strcmp(argv[i], "-P")) {
if (++i>argc) usage();
if(!sscanf(argv[i], "%d", &mxP)) usage();
if (mxP <= 0) usage();
}
else if (!strcmp(argv[i], "-a")) {
if (++i>argc) usage();
if(!sscanf(argv[i], "%lf", &A)) usage();
}
else if (!strcmp(argv[i], "-b")) {
if (++i>argc) usage();
if(!sscanf(argv[i], "%lf", &B)) usage();
}
else if (!strcmp(argv[i], "-c")) {
if (++i>argc) usage();
if(!sscanf(argv[i], "%lf", &C)) usage();
}
else if (!strcmp(argv[i], "-display")) {
if (++i>argc) usage();
display=argv[i];
}
else
usage();
}
dpy = XOpenDisplay(display);
if (!dpy) {
fprintf(stderr, "xfroot: Can't open display '%s'.\n", display);
exit(1);
}
W = (int) DisplayWidth(dpy,0);
H = (int) DisplayHeight(dpy,0);
bmn =((W+7)/8)*H;
bmap = (char *) malloc((unsigned)bmn);
if (!bmap) { fprintf(stderr, "xfroot: malloc failed.\n"); exit(1);}
bzero(bmap, bmn);
Ranfset(time(0)%getpid()); hopset();
if (!mxp && !mxP) {
mxp = (int) (0.25 * (float)(W*H));
mxP = 3 * mxp;
}
else if (!mxp)
mxp = mxP;
else if (!mxP)
mxP = 3 * mxp;
fprintf(stderr, "xfroot: A:%f B:%f C:%f\n", A, B, C);
}
/*
** Copyright (C) 1988 by Jef Poskanzer and Craig Leres.
**
** 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. This software is provided "as is" without express or
** implied warranty.
*/
setroot(w, h, bits)
int w, h;
char *bits;
{
Pixmap bitmap, pixmap;
GC gc;
XGCValues gcv;
bitmap = XCreateBitmapFromData(dpy, DefaultRootWindow(dpy), bits, w, h);
if (bitmap == 0) {
fprintf(stderr, "%s: Unable to store Bitmap", "xfroot");
exit(1);
}
gcv.foreground = WhitePixel(dpy,DefaultScreen(dpy));
gcv.background = BlackPixel(dpy,DefaultScreen(dpy));
gc = XCreateGC(
dpy, DefaultRootWindow(dpy), GCForeground|GCBackground, &gcv);
pixmap = XCreatePixmap(
dpy, DefaultRootWindow(dpy), w, h,
DefaultDepth(dpy, DefaultScreen(dpy)));
if (pixmap == 0) {
fprintf(stderr, "%s: Unable to create Pixmap", "xfroot");
exit(1);
}
XCopyPlane(dpy, bitmap, pixmap, gc, 0, 0, w, h, 0, 0, 1L);
XSetWindowBackgroundPixmap(dpy, DefaultRootWindow(dpy), pixmap);
XFreeGC(dpy, gc);
XFreePixmap(dpy, bitmap);
XFreePixmap(dpy, pixmap);
XClearWindow(dpy, DefaultRootWindow(dpy));
XFlush(dpy);
}
usage() {
fprintf(stderr, "usage: xfroot ");
fprintf(stderr, "[-p npoints] ");
fprintf(stderr, "[-P npoints] ");
fprintf(stderr, "[-a real] ");
fprintf(stderr, "[-b real] ");
fprintf(stderr, "[-c real] ");
fprintf(stderr, "[-display display] ");
fprintf(stderr, "\n");
exit(1);
}
SHAR_EOF
fi
if test -f 'xfroot.man'
then
echo shar: "will not over-write existing file 'xfroot.man'"
else
cat << \SHAR_EOF > 'xfroot.man'
.TH xfroot 1 "21 September 1989"
.SH NAME
xfroot \- set fractal root window (monochrome)
.SH SYNOPSIS
.in +.5i
.ti -.5i
xfroot \%[\-p n] \%[\-P n] \%[\-a r] \%[\-b r] \%[\-c r] \%[\-display display]
.in -.5i
.SH DESCRIPTION
.I Xfroot
sets the X root window to display a monochrome fractal.
The fractal algorithm was published in A. K. Dewdney's
.I "Computer Recreations"
column in the September 1986
.I "Scientific American"
and attributed to Barry Martin of Aston University, Birmingham, England.
.sp
.SH OPTIONS
.PP
.B "\-p \-P"
.RS 5
Sets maximum points to calculate to \fIn\fP. \fB\-p\fP sets the maximum
for in-range (i.e. on display) points. \fB\-P\fP sets the total points
to calculate. Defaults: \fB\-p\fP: 25% of pixels in server display.
\fB\-P\fP: 3 times the \fB\-p\fP value.
.RE
.sp
.B "\-a \-b \-c"
.RS 5
Sets the corresponding fractal algorithm parameter to the real value
.IR r .
Interesting values seem to be in the range -1000 < r < 1000.
The algorithm seems sensitive to changes in the values out to the precision
(double) of the arithmetic, about 16 significant digits.
By default, random values are assigned.
.SH SPECIAL CONSIDERATIONS
With the default parameters,
.I xfroot
calculates hundreds of thousands of points. Each point requires a double
precision square root, multiply and three or four subtracts, plus integer
arithmetic to determine if the point is in range and store the point in
a bit map. Since each point depends on the value for the previous point,
the calculation does not lend itself to vectorizing or parallelization.
.LP
The following table is a rough guide to the amount of processor time
involved. It gives ranges of fractal points per uniprocessor second measured
on a variety of client hosts. The lower values for a processor reflect
the case when all or most points are in in-range and require bit-manipulation
to record the point.
.sp
.B " Cray X-MP: 157,000 to 194,000 *"
.br
.B " Cray 2: 129,000 to 183,000 *"
.br
.B " Convex C200: 41,000 to 47,000 *"
.br
.B " Vaxserver 3500: 13,200 to 15,200"
.br
.B " Sequent Symmetry: 9,900 to 10,500 *"
.br
.B " Vaxstation 2000: 4,670 to 5,530"
.br
.B " Sun 3/60: 1,960 to 2,060"
.br
.B " Sun 3/50: 1,270 to 1,330"
.br
.B " (* = per processor)"
.sp
.SH AUTHORS
.LP
Ed Kubaitis, Computing Services Office, University of Illinois.
.LP
The Xlib code to set the root screen was adapted from code in xphoon
by Jef Poskanzer and Craig Leres, and carries the following copyright:
Copyright (C) 1988 by Jef Poskanzer and Craig Leres.
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. This software is provided "as is" without express or
implied warranty.
SHAR_EOF
fi
exit 0
# End of shell archive
More information about the Comp.sources.x
mailing list