home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume18 / xsplinfn / part01 < prev    next >
Encoding:
Text File  |  1992-07-13  |  35.5 KB  |  1,366 lines

  1. Newsgroups: comp.sources.x
  2. Path: uunet!paladin.american.edu!darwin.sura.net!wupost!usc!sdd.hp.com!mips!msi!dcmartin
  3. From: jef@netcom.com (Jef Poskanzer)
  4. Subject: v18i018: Xsplinefun, Part01/01
  5. Message-ID: <1992Jul14.151016.14450@msi.com>
  6. Originator: dcmartin@fascet
  7. Sender: dcmartin@msi.com (David C. Martin - Moderator)
  8. Organization: Molecular Simulations, Inc.
  9. Date: Tue, 14 Jul 1992 15:10:16 GMT
  10. Approved: dcmartin@msi.com
  11. Lines: 1353
  12.  
  13. Submitted-by: jef@netcom.com (Jef Poskanzer)
  14. Posting-number: Volume 18, Issue 18
  15. Archive-name: xsplinefun/part01
  16.  
  17. Xsplinefun displays colorful moving splines in the X11 root window.
  18. This is more impressive on a fast-displaying machine like an Indigo
  19. or a SparcStation 2.
  20.  
  21. #!/bin/sh
  22. # This is a shell archive (produced by shar 3.50)
  23. # To extract the files from this archive, save it to a file, remove
  24. # everything above the "!/bin/sh" line above, and type "sh file_name".
  25. #
  26. # made 07/14/1992 15:06 UTC by dcmartin@fascet
  27. # Source directory /home/fascet/dcmartin/csx/src/tmp
  28. #
  29. # existing files will NOT be overwritten unless -c is specified
  30. #
  31. #                                                                          
  32. #                                                                          
  33. #
  34. # This shar contains:
  35. # length  mode       name
  36. # ------ ---------- ------------------------------------------
  37. #    547 -rw-r--r-- Imakefile
  38. #  10777 -rw-r--r-- Makefile.std
  39. #    558 -rw-r--r-- README
  40. #  17478 -rw-r--r-- xsplinefun.c
  41. #   1878 -rw-r--r-- xsplinefun.man
  42. #
  43. if test -r _shar_seq_.tmp; then
  44.     echo 'Must unpack archives in sequence!'
  45.     echo Please unpack part `cat _shar_seq_.tmp` next
  46.     exit 1
  47. fi
  48. # ============= Imakefile ==============
  49. if test -f 'Imakefile' -a X"$1" != X"-c"; then
  50.     echo 'x - skipping Imakefile (File already exists)'
  51.     rm -f _shar_wnt_.tmp
  52. else
  53. > _shar_wnt_.tmp
  54. echo 'x - extracting Imakefile (Text)'
  55. sed 's/^X//' << 'SHAR_EOF' > 'Imakefile' &&
  56. # Copyright (C) 1992 by Jef Poskanzer
  57. #
  58. # Permission to use, copy, modify, and distribute this software and its
  59. # documentation for any purpose and without fee is hereby granted, provided
  60. # that the above copyright notice appear in all copies and that both that
  61. # copyright notice and this permission notice appear in supporting
  62. # documentation.  This software is provided "as is" without express or
  63. # implied warranty.
  64. X
  65. LOCAL_LIBRARIES =    $(XLIB)
  66. DEPLIBS =        $(DEPXLIB)
  67. SRCS =            xsplinefun.c
  68. OBJS =            xsplinefun.o
  69. X
  70. ComplexProgramTarget(xsplinefun)
  71. SHAR_EOF
  72. chmod 0644 Imakefile ||
  73. echo 'restore of Imakefile failed'
  74. Wc_c="`wc -c < 'Imakefile'`"
  75. test 547 -eq "$Wc_c" ||
  76.     echo 'Imakefile: original size 547, current size' "$Wc_c"
  77. rm -f _shar_wnt_.tmp
  78. fi
  79. # ============= Makefile.std ==============
  80. if test -f 'Makefile.std' -a X"$1" != X"-c"; then
  81.     echo 'x - skipping Makefile.std (File already exists)'
  82.     rm -f _shar_wnt_.tmp
  83. else
  84. > _shar_wnt_.tmp
  85. echo 'x - extracting Makefile.std (Text)'
  86. sed 's/^X//' << 'SHAR_EOF' > 'Makefile.std' &&
  87. # Makefile generated by imake - do not edit!
  88. # $XConsortium: imake.c,v 1.65 91/07/25 17:50:17 rws Exp $
  89. #
  90. # The cpp used on this machine replaces all newlines and multiple tabs and
  91. # spaces in a macro expansion with a single space.  Imake tries to compensate
  92. # for this, but is not always successful.
  93. #
  94. X
  95. # -------------------------------------------------------------------------
  96. # Makefile generated from "Imake.tmpl" and </tmp/IIf.a07273>
  97. # $XConsortium: Imake.tmpl,v 1.139 91/09/16 08:52:48 rws Exp $
  98. #
  99. # Platform-specific parameters may be set in the appropriate <vendor>.cf
  100. # configuration files.  Site-specific parameters should be set in the file
  101. # site.def.  Full rebuilds are recommended if any parameters are changed.
  102. #
  103. # If your C preprocessor does not define any unique symbols, you will need
  104. # to set BOOTSTRAPCFLAGS when rebuilding imake (usually when doing
  105. # "make World" the first time).
  106. #
  107. X
  108. # -------------------------------------------------------------------------
  109. # site-specific configuration parameters that need to come before
  110. # the platform-specific parameters - edit site.def to change
  111. X
  112. # site:  $XConsortium: site.def,v 1.2 91/07/30 20:26:44 rws Exp $
  113. X
  114. # -------------------------------------------------------------------------
  115. # platform-specific configuration parameters - edit sun.cf to change
  116. X
  117. # platform:  $XConsortium: sun.cf,v 1.68 91/07/30 11:34:39 rws Exp $
  118. X
  119. # operating system:  SunOS 4.1.1
  120. X
  121. # $XConsortium: sunLib.rules,v 1.6 91/03/24 17:55:58 rws Exp $
  122. X
  123. # -------------------------------------------------------------------------
  124. # site-specific configuration parameters that go after
  125. # the platform-specific parameters - edit site.def to change
  126. X
  127. # site:  $XConsortium: site.def,v 1.2 91/07/30 20:26:44 rws Exp $
  128. X
  129. X            SHELL = /bin/sh
  130. X
  131. X              TOP = .
  132. X      CURRENT_DIR = .
  133. X
  134. X               AR = ar clq
  135. X  BOOTSTRAPCFLAGS =
  136. X               CC = cc
  137. X               AS = as
  138. X
  139. X         COMPRESS = compress
  140. X              CPP = /lib/cpp $(STD_CPP_DEFINES)
  141. X    PREPROCESSCMD = cc -E $(STD_CPP_DEFINES)
  142. X          INSTALL = install
  143. X               LD = ld
  144. X             LINT = lint
  145. X      LINTLIBFLAG = -C
  146. X         LINTOPTS = -axz
  147. X               LN = ln -s
  148. X             MAKE = make
  149. X               MV = mv
  150. X               CP = cp
  151. X
  152. X           RANLIB = ranlib
  153. X  RANLIBINSTFLAGS =
  154. X
  155. X               RM = rm -f
  156. X            TROFF = psroff
  157. X         MSMACROS = -ms
  158. X              TBL = tbl
  159. X              EQN = eqn
  160. X     STD_INCLUDES =
  161. X  STD_CPP_DEFINES =
  162. X      STD_DEFINES =
  163. X EXTRA_LOAD_FLAGS =
  164. X  EXTRA_LIBRARIES =
  165. X             TAGS = ctags
  166. X
  167. X    SHAREDCODEDEF = -DSHAREDCODE
  168. X         SHLIBDEF = -DSUNSHLIB
  169. X
  170. X    PROTO_DEFINES =
  171. X
  172. X     INSTPGMFLAGS =
  173. X
  174. X     INSTBINFLAGS = -m 0755
  175. X     INSTUIDFLAGS = -m 4755
  176. X     INSTLIBFLAGS = -m 0644
  177. X     INSTINCFLAGS = -m 0444
  178. X     INSTMANFLAGS = -m 0444
  179. X     INSTDATFLAGS = -m 0444
  180. X    INSTKMEMFLAGS = -m 4755
  181. X
  182. X      PROJECTROOT = /usr/X11/R5
  183. X
  184. X     TOP_INCLUDES = -I$(INCROOT)
  185. X
  186. X      CDEBUGFLAGS = -O
  187. X        CCOPTIONS = -pipe
  188. X
  189. X      ALLINCLUDES = $(INCLUDES) $(EXTRA_INCLUDES) $(TOP_INCLUDES) $(STD_INCLUDES)
  190. X       ALLDEFINES = $(ALLINCLUDES) $(STD_DEFINES) $(EXTRA_DEFINES) $(PROTO_DEFINES) $(DEFINES)
  191. X           CFLAGS = $(CDEBUGFLAGS) $(CCOPTIONS) $(ALLDEFINES)
  192. X        LINTFLAGS = $(LINTOPTS) -DLINT $(ALLDEFINES)
  193. X
  194. X           LDLIBS = $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
  195. X
  196. X        LDOPTIONS = $(CDEBUGFLAGS) $(CCOPTIONS) $(LOCAL_LDFLAGS) -L$(USRLIBDIR)
  197. X
  198. X   LDCOMBINEFLAGS = -X -r
  199. X      DEPENDFLAGS =
  200. X
  201. X        MACROFILE = sun.cf
  202. X           RM_CMD = $(RM) *.CKP *.ln *.BAK *.bak *.o core errs ,* *~ *.a .emacs_* tags TAGS make.log MakeOut
  203. X
  204. X    IMAKE_DEFINES =
  205. X
  206. X         IRULESRC = $(CONFIGDIR)
  207. X        IMAKE_CMD = $(IMAKE) -DUseInstalled -I$(IRULESRC) $(IMAKE_DEFINES)
  208. X
  209. X     ICONFIGFILES = $(IRULESRC)/Imake.tmpl $(IRULESRC)/Imake.rules \
  210. X            $(IRULESRC)/Project.tmpl $(IRULESRC)/site.def \
  211. X            $(IRULESRC)/$(MACROFILE) $(EXTRA_ICONFIGFILES)
  212. X
  213. # -------------------------------------------------------------------------
  214. # X Window System Build Parameters
  215. # $XConsortium: Project.tmpl,v 1.138 91/09/10 09:02:12 rws Exp $
  216. X
  217. # -------------------------------------------------------------------------
  218. # X Window System make variables; this need to be coordinated with rules
  219. X
  220. X          PATHSEP = /
  221. X        USRLIBDIR = /usr/X11/R5/lib
  222. X           BINDIR = /usr/X11/R5/bin
  223. X          INCROOT = /usr/X11/R5/include
  224. X     BUILDINCROOT = $(TOP)
  225. X      BUILDINCDIR = $(BUILDINCROOT)/X11
  226. X      BUILDINCTOP = ..
  227. X           INCDIR = $(INCROOT)/X11
  228. X           ADMDIR = /usr/adm
  229. X           LIBDIR = $(USRLIBDIR)/X11
  230. X        CONFIGDIR = $(LIBDIR)/config
  231. X       LINTLIBDIR = $(USRLIBDIR)/lint
  232. X
  233. X          FONTDIR = $(LIBDIR)/fonts
  234. X         XINITDIR = $(LIBDIR)/xinit
  235. X           XDMDIR = $(LIBDIR)/xdm
  236. X           TWMDIR = $(LIBDIR)/twm
  237. X          MANPATH = /usr/X11/R5/man
  238. X    MANSOURCEPATH = $(MANPATH)/man
  239. X        MANSUFFIX = n
  240. X     LIBMANSUFFIX = 3
  241. X           MANDIR = $(MANSOURCEPATH)$(MANSUFFIX)
  242. X        LIBMANDIR = $(MANSOURCEPATH)$(LIBMANSUFFIX)
  243. X           NLSDIR = $(LIBDIR)/nls
  244. X        PEXAPIDIR = $(LIBDIR)/PEX
  245. X      XAPPLOADDIR = $(LIBDIR)/app-defaults
  246. X       FONTCFLAGS = -t
  247. X
  248. X     INSTAPPFLAGS = $(INSTDATFLAGS)
  249. X
  250. X            IMAKE = imake
  251. X           DEPEND = makedepend
  252. X              RGB = rgb
  253. X
  254. X            FONTC = bdftopcf
  255. X
  256. X        MKFONTDIR = mkfontdir
  257. X        MKDIRHIER = /bin/sh $(BINDIR)/mkdirhier
  258. X
  259. X        CONFIGSRC = $(TOP)/config
  260. X       DOCUTILSRC = $(TOP)/doc/util
  261. X        CLIENTSRC = $(TOP)/clients
  262. X          DEMOSRC = $(TOP)/demos
  263. X           LIBSRC = $(TOP)/lib
  264. X          FONTSRC = $(TOP)/fonts
  265. X       INCLUDESRC = $(TOP)/X11
  266. X        SERVERSRC = $(TOP)/server
  267. X          UTILSRC = $(TOP)/util
  268. X        SCRIPTSRC = $(UTILSRC)/scripts
  269. X       EXAMPLESRC = $(TOP)/examples
  270. X       CONTRIBSRC = $(TOP)/../contrib
  271. X           DOCSRC = $(TOP)/doc
  272. X           RGBSRC = $(TOP)/rgb
  273. X        DEPENDSRC = $(UTILSRC)/makedepend
  274. X         IMAKESRC = $(CONFIGSRC)
  275. X         XAUTHSRC = $(LIBSRC)/Xau
  276. X          XLIBSRC = $(LIBSRC)/X
  277. X           XMUSRC = $(LIBSRC)/Xmu
  278. X       TOOLKITSRC = $(LIBSRC)/Xt
  279. X       AWIDGETSRC = $(LIBSRC)/Xaw
  280. X       OLDXLIBSRC = $(LIBSRC)/oldX
  281. X      XDMCPLIBSRC = $(LIBSRC)/Xdmcp
  282. X      BDFTOSNFSRC = $(FONTSRC)/bdftosnf
  283. X      BDFTOSNFSRC = $(FONTSRC)/clients/bdftosnf
  284. X      BDFTOPCFSRC = $(FONTSRC)/clients/bdftopcf
  285. X     MKFONTDIRSRC = $(FONTSRC)/clients/mkfontdir
  286. X         FSLIBSRC = $(FONTSRC)/lib/fs
  287. X    FONTSERVERSRC = $(FONTSRC)/server
  288. X     EXTENSIONSRC = $(TOP)/extensions
  289. X         XILIBSRC = $(EXTENSIONSRC)/lib/xinput
  290. X      PHIGSLIBSRC = $(EXTENSIONSRC)/lib/PEX
  291. X
  292. # $XConsortium: sunLib.tmpl,v 1.11 91/07/31 11:32:08 rws Exp $
  293. X
  294. SHLIBLDFLAGS = -assert pure-text
  295. PICFLAGS = -pic
  296. X
  297. X  DEPEXTENSIONLIB =
  298. X     EXTENSIONLIB = -lXext
  299. X
  300. X          DEPXLIB = $(DEPEXTENSIONLIB)
  301. X             XLIB = $(EXTENSIONLIB) -lX11
  302. X
  303. X        DEPXMULIB = $(USRLIBDIR)/libXmu.sa.$(SOXMUREV)
  304. X           XMULIB = -lXmu
  305. X
  306. X       DEPOLDXLIB =
  307. X          OLDXLIB = -loldX
  308. X
  309. X      DEPXTOOLLIB = $(USRLIBDIR)/libXt.sa.$(SOXTREV)
  310. X         XTOOLLIB = -lXt
  311. X
  312. X        DEPXAWLIB = $(USRLIBDIR)/libXaw.sa.$(SOXAWREV)
  313. X           XAWLIB = -lXaw
  314. X
  315. X        DEPXILIB =
  316. X           XILIB = -lXi
  317. X
  318. X        SOXLIBREV = 4.10
  319. X          SOXTREV = 4.10
  320. X         SOXAWREV = 5.0
  321. X        SOOLDXREV = 4.10
  322. X         SOXMUREV = 4.10
  323. X        SOXEXTREV = 4.10
  324. X      SOXINPUTREV = 4.10
  325. X
  326. X      DEPXAUTHLIB = $(USRLIBDIR)/libXau.a
  327. X         XAUTHLIB =  -lXau
  328. X      DEPXDMCPLIB = $(USRLIBDIR)/libXdmcp.a
  329. X         XDMCPLIB =  -lXdmcp
  330. X
  331. X        DEPPHIGSLIB = $(USRLIBDIR)/libphigs.a
  332. X           PHIGSLIB =  -lphigs
  333. X
  334. X       DEPXBSDLIB = $(USRLIBDIR)/libXbsd.a
  335. X          XBSDLIB =  -lXbsd
  336. X
  337. X LINTEXTENSIONLIB = $(LINTLIBDIR)/llib-lXext.ln
  338. X         LINTXLIB = $(LINTLIBDIR)/llib-lX11.ln
  339. X          LINTXMU = $(LINTLIBDIR)/llib-lXmu.ln
  340. X        LINTXTOOL = $(LINTLIBDIR)/llib-lXt.ln
  341. X          LINTXAW = $(LINTLIBDIR)/llib-lXaw.ln
  342. X           LINTXI = $(LINTLIBDIR)/llib-lXi.ln
  343. X        LINTPHIGS = $(LINTLIBDIR)/llib-lphigs.ln
  344. X
  345. X          DEPLIBS = $(DEPXAWLIB) $(DEPXMULIB) $(DEPXTOOLLIB) $(DEPXLIB)
  346. X
  347. X         DEPLIBS1 = $(DEPLIBS)
  348. X         DEPLIBS2 = $(DEPLIBS)
  349. X         DEPLIBS3 = $(DEPLIBS)
  350. X
  351. # -------------------------------------------------------------------------
  352. # Imake rules for building libraries, programs, scripts, and data files
  353. # rules:  $XConsortium: Imake.rules,v 1.123 91/09/16 20:12:16 rws Exp $
  354. X
  355. # -------------------------------------------------------------------------
  356. # start of Imakefile
  357. X
  358. # Copyright (C) 1992 by Jef Poskanzer
  359. #
  360. # Permission to use, copy, modify, and distribute this software and its
  361. # documentation for any purpose and without fee is hereby granted, provided
  362. # that the above copyright notice appear in all copies and that both that
  363. # copyright notice and this permission notice appear in supporting
  364. # documentation.  This software is provided "as is" without express or
  365. # implied warranty.
  366. X
  367. LOCAL_LIBRARIES =    $(XLIB)
  368. DEPLIBS =        $(DEPXLIB)
  369. SRCS =            xsplinefun.c
  370. OBJS =            xsplinefun.o
  371. X
  372. X PROGRAM = xsplinefun
  373. X
  374. all:: xsplinefun
  375. X
  376. xsplinefun: $(OBJS) $(DEPLIBS)
  377. X    $(RM) $@
  378. X    $(CC) -o $@ $(OBJS) $(LDOPTIONS) $(LOCAL_LIBRARIES) $(LDLIBS) $(EXTRA_LOAD_FLAGS)
  379. X
  380. saber_xsplinefun:: $(SRCS)
  381. X    # load $(ALLDEFINES) $(SRCS) $(LOCAL_LIBRARIES) $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
  382. X
  383. osaber_xsplinefun:: $(OBJS)
  384. X    # load $(ALLDEFINES) $(OBJS) $(LOCAL_LIBRARIES) $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
  385. X
  386. install:: xsplinefun
  387. X    @if [ -d $(DESTDIR)$(BINDIR) ]; then set +x; \
  388. X    else (set -x; $(MKDIRHIER) $(DESTDIR)$(BINDIR)); fi
  389. X    $(INSTALL) -c $(INSTPGMFLAGS)  xsplinefun $(DESTDIR)$(BINDIR)
  390. X
  391. install.man:: xsplinefun.man
  392. X    @if [ -d $(DESTDIR)$(MANDIR) ]; then set +x; \
  393. X    else (set -x; $(MKDIRHIER) $(DESTDIR)$(MANDIR)); fi
  394. X    $(INSTALL) -c $(INSTMANFLAGS) xsplinefun.man $(DESTDIR)$(MANDIR)/xsplinefun.$(MANSUFFIX)
  395. X
  396. depend::
  397. X    $(DEPEND) $(DEPENDFLAGS) -s "# DO NOT DELETE" -- $(ALLDEFINES) -- $(SRCS)
  398. X
  399. lint:
  400. X    $(LINT) $(LINTFLAGS) $(SRCS) $(LINTLIBS)
  401. lint1:
  402. X    $(LINT) $(LINTFLAGS) $(FILE) $(LINTLIBS)
  403. X
  404. clean::
  405. X    $(RM) $(PROGRAM)
  406. X
  407. # -------------------------------------------------------------------------
  408. # common rules for all Makefiles - do not edit
  409. X
  410. emptyrule::
  411. X
  412. clean::
  413. X    $(RM_CMD) "#"*
  414. X
  415. Makefile::
  416. X    -@if [ -f Makefile ]; then set -x; \
  417. X    $(RM) Makefile.bak; $(MV) Makefile Makefile.bak; \
  418. X    else exit 0; fi
  419. X    $(IMAKE_CMD) -DTOPDIR=$(TOP) -DCURDIR=$(CURRENT_DIR)
  420. X
  421. tags::
  422. X    $(TAGS) -w *.[ch]
  423. X    $(TAGS) -xw *.[ch] > TAGS
  424. X
  425. saber:
  426. X    # load $(ALLDEFINES) $(SRCS)
  427. X
  428. osaber:
  429. X    # load $(ALLDEFINES) $(OBJS)
  430. X
  431. # -------------------------------------------------------------------------
  432. # empty rules for directories that do not have SUBDIRS - do not edit
  433. X
  434. install::
  435. X    @echo "install in $(CURRENT_DIR) done"
  436. X
  437. install.man::
  438. X    @echo "install.man in $(CURRENT_DIR) done"
  439. X
  440. Makefiles::
  441. X
  442. includes::
  443. X
  444. # -------------------------------------------------------------------------
  445. # dependencies generated by makedepend
  446. X
  447. SHAR_EOF
  448. chmod 0644 Makefile.std ||
  449. echo 'restore of Makefile.std failed'
  450. Wc_c="`wc -c < 'Makefile.std'`"
  451. test 10777 -eq "$Wc_c" ||
  452.     echo 'Makefile.std: original size 10777, current size' "$Wc_c"
  453. rm -f _shar_wnt_.tmp
  454. fi
  455. # ============= README ==============
  456. if test -f 'README' -a X"$1" != X"-c"; then
  457.     echo 'x - skipping README (File already exists)'
  458.     rm -f _shar_wnt_.tmp
  459. else
  460. > _shar_wnt_.tmp
  461. echo 'x - extracting README (Text)'
  462. sed 's/^X//' << 'SHAR_EOF' > 'README' &&
  463. X                           xsplinefun
  464. X                     Distribution of 02may92
  465. X                  Previous distribution NONE
  466. X
  467. XXsplinefun displays colorful moving splines in the X11 root window.
  468. X
  469. Files in this distribution:
  470. X
  471. X    README        this
  472. X    Imakefile        guess
  473. X    xsplinefun.c    source file
  474. X    xsplinefun.man    manual entry
  475. X
  476. To compile: do an xmkmf, make depend, make.
  477. X
  478. Feedback is welcome - send bug reports, enhancements, checks, money orders,
  479. gold bullion, drugs, etc. to the addresses below.
  480. X
  481. X    Jef Poskanzer
  482. X    jef@netcom.com
  483. X    jef@well.sf.ca.us
  484. SHAR_EOF
  485. chmod 0644 README ||
  486. echo 'restore of README failed'
  487. Wc_c="`wc -c < 'README'`"
  488. test 558 -eq "$Wc_c" ||
  489.     echo 'README: original size 558, current size' "$Wc_c"
  490. rm -f _shar_wnt_.tmp
  491. fi
  492. # ============= xsplinefun.c ==============
  493. if test -f 'xsplinefun.c' -a X"$1" != X"-c"; then
  494.     echo 'x - skipping xsplinefun.c (File already exists)'
  495.     rm -f _shar_wnt_.tmp
  496. else
  497. > _shar_wnt_.tmp
  498. echo 'x - extracting xsplinefun.c (Text)'
  499. sed 's/^X//' << 'SHAR_EOF' > 'xsplinefun.c' &&
  500. /* xsplinefun.c - X11 version of spline fun #3
  501. **
  502. ** Displays colorful moving splines in the X11 root window.
  503. **
  504. ** Copyright (C) 1992 by Jef Poskanzer
  505. **
  506. ** Permission to use, copy, modify, and distribute this software and its
  507. ** documentation for any purpose and without fee is hereby granted, provided
  508. ** that the above copyright notice appear in all copies and that both that
  509. ** copyright notice and this permission notice appear in supporting
  510. ** documentation.  This software is provided "as is" without express or
  511. ** implied warranty.
  512. */
  513. X
  514. #include <stdio.h>
  515. #include <errno.h>
  516. #include <malloc.h>
  517. #include <signal.h>
  518. #include <pwd.h>
  519. #include <sys/types.h>
  520. #include <sys/time.h>
  521. #include <sys/ioctl.h>
  522. X
  523. #if defined(SYSV) || defined(SVR4)
  524. #include <string.h>
  525. #define index strchr
  526. #include <sys/termio.h>
  527. #else /*SYSV*/
  528. #include <strings.h>
  529. #endif /*SYSV*/
  530. X
  531. #include <X11/Xlib.h>
  532. #include <X11/Xutil.h>
  533. #include <X11/Xatom.h>
  534. #include <X11/Xresource.h>
  535. #define XTSTRINGDEFINES
  536. #include <X11/StringDefs.h>
  537. X
  538. X
  539. /* Definitions. */
  540. X
  541. #define X_CLASS "Xsplinefun"
  542. X
  543. #define DEFAULT_MAX_COLORS 256
  544. #define DEFAULT_LOOPS_PER_SECOND 50
  545. X
  546. #define MIN_COLORS 4
  547. #define INITIAL_LOOPS_PER_SLEEP 10
  548. #define MIN_LOOPS_PER_SLEEP 1
  549. #define INITIAL_SLEEP_USECS 100000
  550. #define MIN_SLEEP_USECS 50000
  551. X
  552. #define POINTS 5
  553. #define MAX_DELTA 3
  554. #define MAX_COLOR_DELTA (3*256)
  555. X
  556. #define SPLINE_THRESH 5
  557. X
  558. X
  559. /* Externals. */
  560. X
  561. extern char* getenv();
  562. extern long random();
  563. X
  564. X
  565. /* Forward routines. */
  566. X
  567. static void x_init();
  568. static void x_alloc_colors();
  569. static void x_cleanup();
  570. static Window VirtualRootWindowOfScreen();
  571. static void x_rdb_init();
  572. static char* x_get_resource();
  573. static int x_str_to_bool();
  574. static void stealth();
  575. static void main_loop();
  576. static void sigcatch();
  577. static void init_timing();
  578. static void timing();
  579. static void init_splines();
  580. static void rotate_colormap();
  581. static void new_color();
  582. static void move_splines();
  583. static void XDrawSpline();
  584. X
  585. X
  586. /* Routines. */
  587. X
  588. static char* argv0;
  589. static char* app_name;
  590. static int forwards, backwards;
  591. static int max_colors;
  592. static int loops_per_second;
  593. X
  594. static int loops_per_sleep;
  595. static int sleep_usecs;
  596. X
  597. void
  598. main( argc, argv )
  599. X    int argc;
  600. X    char* argv[];
  601. X    {
  602. X    char* rval;
  603. X    char* usage = "usage: %s [-display d] [-forwards|-backwards] [-maxcolors n] [-loops n] [-id]\n";
  604. X
  605. X    argv0 = argv[0];
  606. X    app_name = "xsplinefun";
  607. X    forwards = backwards = False;
  608. X    max_colors = DEFAULT_MAX_COLORS;
  609. X    loops_per_second = DEFAULT_LOOPS_PER_SECOND;
  610. X    loops_per_sleep = INITIAL_LOOPS_PER_SLEEP;
  611. X    sleep_usecs = INITIAL_SLEEP_USECS;
  612. X
  613. X    /* Parse args and initialize X stuff. */
  614. X    x_init( &argc, argv );
  615. X
  616. X    /* Check usage. */
  617. X    if ( argc != 1 )
  618. X    {
  619. X    (void) fprintf( stderr, usage, argv[0] );
  620. X    exit( 1 );
  621. X    }
  622. X
  623. X    /* Check rotation. */
  624. X    rval = x_get_resource( "rotation", "Rotation" );
  625. X    if ( rval != (char*) 0 )
  626. X    if ( rval[0] == 'f' || rval[0] == 'F' )
  627. X        forwards = True;
  628. X    else if ( rval[0] == 'b' || rval[0] == 'B' )
  629. X        backwards = True;
  630. X
  631. X    /* Check max colors. */
  632. X    rval = x_get_resource( "maxcolors", "Maxcolors" );
  633. X    if ( rval != (char*) 0 )
  634. X    max_colors = atoi(rval);
  635. X    x_alloc_colors();
  636. X
  637. X    /* Check loops. */
  638. X    rval = x_get_resource( "loops", "Loops" );
  639. X    if ( rval != (char*) 0 )
  640. X    loops_per_second = atoi(rval);
  641. X
  642. X    /* Initialize the random number generator. */
  643. X    srandom( (int) ( time( (long*) 0 ) ^ getpid() ) );
  644. X
  645. X    /* Initialize the splines. */
  646. X    init_splines();
  647. X
  648. X    /* Fork, if necessary. */
  649. X    rval = x_get_resource( "id", "Id" );
  650. X    if ( rval != (char*) 0 )
  651. X    if ( x_str_to_bool( rval ) )
  652. X        stealth();
  653. X
  654. X    /* Main loop. */
  655. X    main_loop();
  656. X    
  657. X    /* Done. */
  658. X    x_cleanup();
  659. X    exit( 0 );
  660. X    }
  661. X
  662. X
  663. /* X stuff. */
  664. X
  665. static Display* display = (Display*) 0;
  666. static int screennum;
  667. static Screen* screen;
  668. static Window root;
  669. static int width, height;
  670. static int depth;
  671. static GC gc;
  672. static Colormap cmap;
  673. static int ncolors;
  674. static unsigned long pixels[DEFAULT_MAX_COLORS];
  675. X
  676. static void
  677. x_init( argcP, argv )
  678. X    int* argcP;
  679. X    char** argv;
  680. X    {
  681. X    char* display_name;
  682. X    char* rval;
  683. X    int i, d;
  684. X
  685. X    /* Scan args looking for -display. */
  686. X    display_name = (char*) 0;
  687. X    for ( i = 1; i + 1 < *argcP; ++i )
  688. X    {
  689. X    if ( strcmp( argv[i], "-display" ) == 0 ||
  690. X         strcmp( argv[i], "-displa" ) == 0 ||
  691. X         strcmp( argv[i], "-displ" ) == 0 ||
  692. X         strcmp( argv[i], "-disp" ) == 0 ||
  693. X         strcmp( argv[i], "-dis" ) == 0 ||
  694. X         strcmp( argv[i], "-di" ) == 0 ||
  695. X         strcmp( argv[i], "-d" ) == 0 )
  696. X        {
  697. X        display_name = argv[i + 1];
  698. X        for ( i = i + 2; i <= *argcP; ++i )
  699. X        argv[i - 2] = argv[i];
  700. X        *argcP -= 2;
  701. X        break;
  702. X        }
  703. X    }
  704. X
  705. X    display = XOpenDisplay( display_name );
  706. X    if ( display == (Display*) 0 )
  707. X    {
  708. X    (void) fprintf(
  709. X        stderr, "%s: can't open display \"%s\"\n", argv0,
  710. X        XDisplayName( display_name ) );
  711. X    exit( 1 );
  712. X    }
  713. X
  714. X    screennum = DefaultScreen( display );
  715. X    screen = ScreenOfDisplay( display, DefaultScreen( display ) );
  716. X    root = VirtualRootWindowOfScreen( screen );
  717. X    width = WidthOfScreen( screen );
  718. X    height = HeightOfScreen( screen );
  719. X    depth = DefaultDepthOfScreen( screen );
  720. X    if ( depth <= 1 )
  721. X    {
  722. X    (void) fprintf(
  723. X        stderr, "%s: screen depth must be greater than 1\n", argv0 );
  724. X    exit( 1 );
  725. X    }
  726. X    gc = XCreateGC( display, root, 0, (XGCValues*) 0 );
  727. X    cmap = DefaultColormapOfScreen( screen );
  728. X
  729. X    x_rdb_init( argcP, argv );
  730. X
  731. X    rval = x_get_resource( XtNname, "Name" );
  732. X    if ( rval != (char*) 0 )
  733. X    app_name = rval;
  734. X
  735. X    rval = x_get_resource( "synchronous", "Synchronous" );
  736. X    if ( rval != (char*) 0 )
  737. X    if ( x_str_to_bool( rval ) )
  738. X        XSynchronize( display, True );
  739. X    }
  740. X
  741. static void
  742. x_alloc_colors()
  743. X    {
  744. X    for ( ncolors = max_colors; ncolors >= MIN_COLORS; --ncolors )
  745. X    if ( XAllocColorCells(
  746. X        display, cmap, False, (unsigned long*) 0, 0, pixels, ncolors ) )
  747. X        break;
  748. X    if ( ncolors < MIN_COLORS )
  749. X    {
  750. X    (void) fprintf( stderr, "%s: can't allocate enough colors\n", argv0 );
  751. X    exit( 1 );
  752. X    }
  753. X    if ( ncolors < max_colors )
  754. X    (void) fprintf(
  755. X        stderr, "%s: only %d colors available\n", argv0, ncolors );
  756. X    }
  757. X
  758. static void
  759. x_cleanup()
  760. X    {
  761. X    XClearArea( display, root, 0, 0, width, height, True );
  762. X    XFreeColors( display, cmap, pixels, ncolors, (unsigned long) 0 );
  763. X    XFreeGC( display, gc );
  764. X    XCloseDisplay( display );
  765. X    }
  766. X
  767. X
  768. /* From vroot.h by Andreas Stolcke. */
  769. X
  770. static Window
  771. VirtualRootWindowOfScreen( screenP )
  772. X    Screen* screenP;
  773. X    {
  774. X    static Window root = (Window) 0;
  775. X    Display* dpy = DisplayOfScreen( screenP );
  776. X    Atom __SWM_VROOT = None;
  777. X    int i;
  778. X    Window rootReturn, parentReturn;
  779. X    Window* children;
  780. X    unsigned int numChildren;
  781. X
  782. X    root = RootWindowOfScreen( screenP );
  783. X
  784. X    /* Go look for a virtual root. */
  785. X    __SWM_VROOT = XInternAtom( dpy, "__SWM_VROOT", False );
  786. X    if ( XQueryTree(
  787. X         dpy, root, &rootReturn, &parentReturn, &children,
  788. X         &numChildren ) )
  789. X    {
  790. X    for ( i = 0; i < numChildren; ++i )
  791. X        {
  792. X        Atom actual_type;
  793. X        int actual_format;
  794. X        unsigned long nitems, bytesafter;
  795. X        Window* newRoot = (Window*) 0;
  796. X
  797. X        if ( XGetWindowProperty(
  798. X             dpy, children[i], __SWM_VROOT, 0, 1, False, XA_WINDOW,
  799. X             &actual_type, &actual_format, &nitems, &bytesafter,
  800. X             (unsigned char**) &newRoot ) == Success && newRoot )
  801. X        {
  802. X        root = *newRoot;
  803. X        break;
  804. X        }
  805. X        }
  806. X    if ( children )
  807. X        XFree( (char*) children );
  808. X    }
  809. X
  810. X    return root;
  811. X    }
  812. X
  813. X
  814. /* X resources stuff. */
  815. X
  816. static XrmDatabase rdb;
  817. X
  818. static XrmOptionDescRec x_options[] = {
  819. X    { "-forwards",       "*rotation",       XrmoptionNoArg,  (caddr_t) "f" },
  820. X    { "-backwards",      "*rotation",       XrmoptionNoArg,  (caddr_t) "b" },
  821. X    { "-maxcolors",      "*maxcolors",      XrmoptionSepArg, (caddr_t) 0 },
  822. X    { "-loops",          "*loops",          XrmoptionSepArg, (caddr_t) 0 },
  823. X    { "-id",             "*id",             XrmoptionNoArg,  (caddr_t) "on" },
  824. X    { "-name",           ".name",           XrmoptionSepArg, (caddr_t) 0 },
  825. X    { "-synchronous",    "*synchronous",    XrmoptionNoArg,  (caddr_t) "on" },
  826. X    { "-xrm",            (char*) 0,         XrmoptionResArg, (caddr_t) 0 },
  827. X    };
  828. X
  829. static void
  830. x_rdb_init( argcP, argv )
  831. X    int* argcP;
  832. X    char** argv;
  833. X    {
  834. X    char* resource_string;
  835. X    char* xenv;
  836. X    XrmDatabase xenv_rdb;
  837. X
  838. X    XrmInitialize();
  839. X
  840. X    /* Look for resource databases on server. */
  841. X    resource_string = XResourceManagerString( display );
  842. X    if ( resource_string != (char*) 0 )
  843. X    rdb = XrmGetStringDatabase( resource_string );
  844. X    else
  845. X    {
  846. X    /* No server databases, try ~/.Xdefaults */
  847. X    char* cp;
  848. X    char buf[500];
  849. X
  850. X    cp = getenv( "HOME" );
  851. X    if ( cp != (char*) 0 )
  852. X        (void) strcpy( buf, cp );
  853. X    else
  854. X        {
  855. X        struct passwd* pw;
  856. X
  857. X        cp = getenv( "USER" );
  858. X        if ( cp != (char*) 0 )
  859. X        pw = getpwnam( cp );
  860. X        else
  861. X        pw = getpwuid( getuid() );
  862. X        if ( pw != (struct passwd*) 0 )
  863. X        (void) strcpy( buf, pw->pw_dir );
  864. X        else
  865. X        (void) strcpy( buf, "." );    /* best we can do */
  866. X        }
  867. X    (void) strcat( buf, "/.Xdefaults" );
  868. X    rdb = XrmGetFileDatabase( buf );
  869. X    }
  870. X
  871. X    /* Merge in XENVIRONMENT, if any. */
  872. X    xenv = getenv( "XENVIRONMENT" );
  873. X    if ( xenv != (char*) 0 )
  874. X    {
  875. X    xenv_rdb = XrmGetFileDatabase( xenv );
  876. X    XrmMergeDatabases( xenv_rdb, &rdb );
  877. X    }
  878. X
  879. X    /* And add command line options. */
  880. X    XrmParseCommand(
  881. X    &rdb, x_options, sizeof(x_options) / sizeof(*x_options),
  882. X    app_name, argcP, argv );
  883. X    }
  884. X
  885. static char*
  886. x_get_resource( name, class )
  887. X    char* name;
  888. X    char* class;
  889. X    {
  890. X    char rname[500], rclass[500];
  891. X    char* type;
  892. X    XrmValue value;
  893. X
  894. X    (void) sprintf( rname, "%s.%s", app_name, name );
  895. X    (void) sprintf( rclass, "%s.%s", X_CLASS, class );
  896. X    if ( XrmGetResource( rdb, rname, rclass, &type, &value ) == True )
  897. X    if ( strcmp( type, XtRString ) == 0 )
  898. X        return (char*) value.addr;
  899. X    return (char*) 0;
  900. X    }
  901. X
  902. static int
  903. x_str_to_bool( str )
  904. X    char* str;
  905. X    {
  906. X    if ( strcmp( str, "True" ) == 0 ||
  907. X         strcmp( str, "true" ) == 0 ||
  908. X         strcmp( str, "Yes" ) == 0 ||
  909. X         strcmp( str, "yes" ) == 0 ||
  910. X         strcmp( str, "On" ) == 0 ||
  911. X         strcmp( str, "on" ) == 0 ||
  912. X         strcmp( str, "Si" ) == 0 ||
  913. X         strcmp( str, "si" ) == 0 ||
  914. X         strcmp( str, "Da" ) == 0 ||
  915. X         strcmp( str, "da" ) == 0 ||
  916. X         strcmp( str, "T" ) == 0 ||
  917. X         strcmp( str, "t" ) == 0 ||
  918. X         strcmp( str, "Y" ) == 0 ||
  919. X         strcmp( str, "y" ) == 0 ||
  920. X         strcmp( str, "1" ) == 0 )
  921. X    return True;
  922. X    return False;
  923. X    }
  924. X
  925. X
  926. /* Generic application stuff. */
  927. X
  928. static void
  929. stealth()
  930. X    {
  931. X    int pid, tty;
  932. X
  933. X    pid = fork();
  934. X    if ( pid < 0 )
  935. X    {
  936. X    perror( "fork" );
  937. X    exit( 1 );
  938. X    }
  939. X    else if ( pid > 0 )
  940. X    /* Parent just exits. */
  941. X    exit( 0 );
  942. X    (void) printf( "%d\n", getpid() );
  943. X    (void) fflush( stdout );
  944. X
  945. X    /* Go stealth (ditch our controlling tty). */
  946. X    tty = open( "/dev/tty", 0 );
  947. X    if ( tty < 0 )
  948. X    {
  949. X    /* ENXIO means that there is no controlling terminal, so we don't
  950. X    ** have to detach anything.
  951. X    */
  952. X        if ( errno != ENXIO )
  953. X        {
  954. X        (void) fprintf( stderr, "%s: ", argv0 );
  955. X        perror( "/dev/tty open" );
  956. X        exit( 1 );
  957. X        }
  958. X    }
  959. X    else
  960. X    {
  961. #ifdef TIOCNOTTY
  962. X    if ( ioctl( tty, TIOCNOTTY, 0 ) < 0 )
  963. X        {
  964. X        (void) fprintf( stderr, "%s: ", argv0 );
  965. X        perror( "TIOCNOTTY ioctl" );
  966. X        exit( 1 );
  967. X        }
  968. #endif /*TIOCNOTTY*/
  969. X    (void) close( tty );
  970. X    }
  971. X    }
  972. X
  973. static int goflag;
  974. static int loops;
  975. X
  976. static void
  977. sigcatch()
  978. X    {
  979. X    goflag = 0;
  980. X    }
  981. X
  982. static int then_loops;
  983. static time_t then;
  984. X
  985. static void
  986. init_timing()
  987. X    {
  988. X    then = time( (time_t*) 0 );
  989. X    then_loops = 0;
  990. X    }
  991. X
  992. static void
  993. timing()
  994. X    {
  995. X    float ratio;
  996. X    int t;
  997. X    time_t now;
  998. X
  999. X    if ( sleep_usecs > 0 && loops_per_sleep > 0 &&
  1000. X     loops % loops_per_sleep == 0 )
  1001. X    {
  1002. X    XFlush( display );
  1003. X    usleep( sleep_usecs );
  1004. X    if ( loops_per_second > 0 )
  1005. X        {
  1006. X        now = time( (time_t*) 0 );
  1007. X        if ( now != then )
  1008. X        {
  1009. X        if ( then_loops != 0 )
  1010. X            {
  1011. X            ratio = (float) ( loops - then_loops ) /
  1012. X                (float) loops_per_second;
  1013. X            if ( ratio > 1.0 )
  1014. X            {
  1015. X            /* We're going too fast. */
  1016. X            t = loops_per_sleep / ratio;
  1017. X            if ( t >= MIN_LOOPS_PER_SLEEP )
  1018. X                loops_per_sleep = t;
  1019. X            else
  1020. X                sleep_usecs *= ratio;
  1021. X            }
  1022. X            else if ( ratio < 1.0 )
  1023. X            {
  1024. X            /* We're going too slow. */
  1025. X            t = sleep_usecs * ratio;
  1026. X            if ( t >= MIN_SLEEP_USECS )
  1027. X                sleep_usecs = t;
  1028. X            else
  1029. X                {
  1030. X                loops_per_sleep /= ratio;
  1031. X                if ( loops_per_sleep > 3 * loops_per_second )
  1032. X                loops_per_sleep = 0;    /* give up */
  1033. X                }
  1034. X            }
  1035. X            }
  1036. X        then_loops = loops;
  1037. X        then = now;
  1038. X        }
  1039. X        }
  1040. X    }
  1041. X    }
  1042. X
  1043. static void
  1044. main_loop()
  1045. X    {
  1046. X    /* Set up for signal catching. */
  1047. X    goflag = 1;
  1048. X    (void) signal( SIGHUP, sigcatch );
  1049. X    (void) signal( SIGINT, sigcatch );
  1050. X    (void) signal( SIGTERM, sigcatch );
  1051. X
  1052. X    /* Do it. */
  1053. X    for ( loops = 1; goflag; ++loops )
  1054. X    {
  1055. X    move_splines();
  1056. X    timing();
  1057. X    }
  1058. X    }
  1059. X
  1060. X
  1061. /* Spline-fun smarts. */
  1062. X
  1063. static int x[POINTS], y[POINTS], dx[POINTS], dy[POINTS];
  1064. static int nred, ngreen, nblue, dred, dgreen, dblue;
  1065. static int color;
  1066. static XColor xcolors[DEFAULT_MAX_COLORS];
  1067. X
  1068. static void
  1069. init_splines()
  1070. X    {
  1071. X    int i;
  1072. X
  1073. X    /* Initialize points. */
  1074. X    for ( i = 0; i < POINTS; ++i )
  1075. X    {
  1076. X    x[i] = random() % width;
  1077. X    y[i] = random() % height;
  1078. X    dx[i] = random() % ( MAX_DELTA * 2 ) - MAX_DELTA;
  1079. X    if ( dx[i] <= 0 ) --dx[i];
  1080. X    dy[i] = random() % ( MAX_DELTA * 2 ) - MAX_DELTA;
  1081. X    if ( dy[i] <= 0 ) --dy[i];
  1082. X    }
  1083. X
  1084. X    /* Initalize colors. */
  1085. X    for ( color = 0; color < ncolors; ++color )
  1086. X    {
  1087. X    xcolors[color].red = xcolors[color].green = xcolors[color].blue = 0;
  1088. X    xcolors[color].pixel = pixels[color];
  1089. X    xcolors[color].flags = DoRed|DoGreen|DoBlue;
  1090. X    }
  1091. X    color = 0;
  1092. X    nred = ngreen = nblue = 0;
  1093. X    dred = random() % ( MAX_COLOR_DELTA * 2 ) - MAX_COLOR_DELTA;
  1094. X    if ( dred <= 0 ) --dred;
  1095. X    dgreen = random() % ( MAX_COLOR_DELTA * 2 ) - MAX_COLOR_DELTA;
  1096. X    if ( dgreen <= 0 ) --dgreen;
  1097. X    dblue = random() % ( MAX_COLOR_DELTA * 2 ) - MAX_COLOR_DELTA;
  1098. X    if ( dblue <= 0 ) --dblue;
  1099. X    }
  1100. X
  1101. static void
  1102. rotate_colormap()
  1103. X    {
  1104. X    int t, i;
  1105. X
  1106. X    if ( forwards )
  1107. X    {
  1108. X    t = xcolors[0].pixel;
  1109. X    for ( i = 0; i < ncolors - 1; ++i )
  1110. X        xcolors[i].pixel = xcolors[i + 1].pixel;
  1111. X    xcolors[ncolors - 1].pixel = t;
  1112. X    XStoreColors(display, cmap, xcolors, ncolors );
  1113. X    }
  1114. X    else if ( backwards )
  1115. X    {
  1116. X    t = xcolors[ncolors - 1].pixel;
  1117. X    for ( i = ncolors - 1; i > 0; --i )
  1118. X        xcolors[i].pixel = xcolors[i - 1].pixel;
  1119. X    xcolors[0].pixel = t;
  1120. X    XStoreColors(display, cmap, xcolors, ncolors );
  1121. X    }
  1122. X    }
  1123. X
  1124. static void
  1125. new_color()
  1126. X    {
  1127. X    int t;
  1128. X
  1129. X    for ( ; ; )
  1130. X    {
  1131. X    t = (int) nred + dred;
  1132. X    if ( t >= 0 && t < 65536 ) break;
  1133. X    dred = random() % ( MAX_COLOR_DELTA * 2 ) - MAX_COLOR_DELTA;
  1134. X    if ( dred <= 0 ) --dred;
  1135. X    }
  1136. X    xcolors[color].red = nred = t;
  1137. X    for ( ; ; )
  1138. X    {
  1139. X    t = (int) ngreen + dgreen;
  1140. X    if ( t >= 0 && t < 65536 ) break;
  1141. X    dgreen = random() % ( MAX_COLOR_DELTA * 2 ) - MAX_COLOR_DELTA;
  1142. X    if ( dgreen <= 0 ) --dgreen;
  1143. X    }
  1144. X    xcolors[color].green = ngreen = t;
  1145. X    for ( ; ; )
  1146. X    {
  1147. X    t = (int) nblue + dblue;
  1148. X    if ( t >= 0 && t < 65536 ) break;
  1149. X    dblue = random() % ( MAX_COLOR_DELTA * 2 ) - MAX_COLOR_DELTA;
  1150. X    if ( dblue <= 0 ) --dblue;
  1151. X    }
  1152. X    xcolors[color].blue = nblue = t;
  1153. X    XStoreColor(display, cmap, &(xcolors[color]) );
  1154. X    XSetForeground( display, gc, xcolors[color].pixel );
  1155. X    if ( ++color >= ncolors ) color -= ncolors;
  1156. X    }
  1157. X
  1158. static void
  1159. move_splines()
  1160. X    {
  1161. X    int i, t, px, py, zx, zy, nx, ny;
  1162. X
  1163. X    /* Rotate colormap if necessary. */
  1164. X    rotate_colormap();
  1165. X
  1166. X    /* Choose new color. */
  1167. X    new_color();
  1168. X
  1169. X    /* Backwards rotation requires two new colors each loop. */
  1170. X    if ( backwards )
  1171. X    new_color();
  1172. X
  1173. X    /* Move the points. */
  1174. X    for ( i = 0; i < POINTS; i++ )
  1175. X    {
  1176. X    for ( ; ; )
  1177. X        {
  1178. X        t = x[i] + dx[i];
  1179. X        if ( t >= 0 && t < width ) break;
  1180. X        dx[i] = random() % ( MAX_DELTA * 2 ) - MAX_DELTA;
  1181. X        if ( dx[i] <= 0 ) --dx[i];
  1182. X        }
  1183. X    x[i] = t;
  1184. X    for ( ; ; )
  1185. X        {
  1186. X        t = y[i] + dy[i];
  1187. X        if ( t >= 0 && t < height ) break;
  1188. X        dy[i] = random() % ( MAX_DELTA * 2 ) - MAX_DELTA;
  1189. X        if ( dy[i] <= 0 ) --dy[i];
  1190. X        }
  1191. X    y[i] = t;
  1192. X    }
  1193. X
  1194. X    /* Draw the figure. */
  1195. X    px = zx = ( x[0] + x[POINTS-1] ) / 2;
  1196. X    py = zy = ( y[0] + y[POINTS-1] ) / 2;
  1197. X    for ( i = 0; i < POINTS-1; ++i )
  1198. X    {
  1199. X    nx = ( x[i+1] + x[i] ) / 2;
  1200. X    ny = ( y[i+1] + y[i] ) / 2;
  1201. X    XDrawSpline( display, root, gc, px, py, x[i], y[i], nx, ny );
  1202. X    px = nx;
  1203. X    py = ny;
  1204. X    }
  1205. X    XDrawSpline(
  1206. X    display, root, gc, px, py, x[POINTS-1], y[POINTS-1], zx, zy );
  1207. X    }
  1208. X
  1209. X
  1210. /* X spline routine. */
  1211. X
  1212. #define abs(x) ((x) < 0 ? -(x) : (x))
  1213. X
  1214. static void
  1215. XXDrawSpline( display, d, gc, x0, y0, x1, y1, x2, y2 )
  1216. Display* display;
  1217. Drawable d;
  1218. GC gc;
  1219. int x0, y0, x1, y1, x2, y2;
  1220. X    {
  1221. X    register int xa, ya, xb, yb, xc, yc, xp, yp;
  1222. X
  1223. X    xa = ( x0 + x1 ) / 2;
  1224. X    ya = ( y0 + y1 ) / 2;
  1225. X    xc = ( x1 + x2 ) / 2;
  1226. X    yc = ( y1 + y2 ) / 2;
  1227. X    xb = ( xa + xc ) / 2;
  1228. X    yb = ( ya + yc ) / 2;
  1229. X
  1230. X    xp = ( x0 + xb ) / 2;
  1231. X    yp = ( y0 + yb ) / 2;
  1232. X    if ( abs( xa - xp ) + abs( ya - yp ) > SPLINE_THRESH )
  1233. X    XDrawSpline( display, d, gc, x0, y0, xa, ya, xb, yb );
  1234. X    else
  1235. X    XDrawLine( display, d, gc, x0, y0, xb, yb );
  1236. X
  1237. X    xp = ( x2 + xb ) / 2;
  1238. X    yp = ( y2 + yb ) / 2;
  1239. X    if ( abs( xc - xp ) + abs( yc - yp ) > SPLINE_THRESH )
  1240. X    XDrawSpline( display, d, gc, xb, yb, xc, yc, x2, y2 );
  1241. X    else
  1242. X    XDrawLine( display, d, gc, xb, yb, x2, y2 );
  1243. X    }
  1244. X
  1245. X
  1246. #ifdef SYSV
  1247. X
  1248. /* Most SysV's don't have a usleep.  Sone of them have select. */
  1249. X
  1250. usleep( usecs )
  1251. int usecs;
  1252. X    {
  1253. X    struct timeval timeout;
  1254. X
  1255. X    timeout.tv_sec = usecs / 1000000;
  1256. X    timeout.tv_usec = usecs % 1000000;
  1257. X    select( 0, 0, 0, 0, &timeout );
  1258. X    }
  1259. X
  1260. #endif /*SYSV*/
  1261. SHAR_EOF
  1262. chmod 0644 xsplinefun.c ||
  1263. echo 'restore of xsplinefun.c failed'
  1264. Wc_c="`wc -c < 'xsplinefun.c'`"
  1265. test 17478 -eq "$Wc_c" ||
  1266.     echo 'xsplinefun.c: original size 17478, current size' "$Wc_c"
  1267. rm -f _shar_wnt_.tmp
  1268. fi
  1269. # ============= xsplinefun.man ==============
  1270. if test -f 'xsplinefun.man' -a X"$1" != X"-c"; then
  1271.     echo 'x - skipping xsplinefun.man (File already exists)'
  1272.     rm -f _shar_wnt_.tmp
  1273. else
  1274. > _shar_wnt_.tmp
  1275. echo 'x - extracting xsplinefun.man (Text)'
  1276. sed 's/^X//' << 'SHAR_EOF' > 'xsplinefun.man' &&
  1277. .TH xsplinefun 1 "2 May 1992"
  1278. .SH NAME
  1279. xsplinefun - display colorful moving splines in the X11 root window
  1280. .SH SYNOPSIS
  1281. .B xsplinefun
  1282. .RB [ -display
  1283. .IR d ]
  1284. .RB [ -forwards | -backwards ]
  1285. .RB [ -maxcolors
  1286. .IR n ]
  1287. .RB [ -loops
  1288. .IR n ]
  1289. .RB [ -id ]
  1290. .SH DESCRIPTION
  1291. .PP
  1292. .I Xsplinefun
  1293. displays colorful moving splines in the root window.
  1294. .SH OPTIONS
  1295. .PP
  1296. .I Xsplinefun
  1297. accepts all the usual X flags and resources, such as
  1298. .BR -display ,
  1299. .BR -sync ,
  1300. and
  1301. .BR -xrm .
  1302. .PP
  1303. .I Xsplinefun
  1304. also accepts the following flags:
  1305. .TP
  1306. .B -forwards
  1307. Rotates the colormap forwards.
  1308. XX resource:
  1309. .BR "rotation: f" .
  1310. .TP
  1311. .B -backwards
  1312. Rotates the colormap backwards.
  1313. XX resource:
  1314. .BR "rotation: b" .
  1315. .TP
  1316. .B -maxcolors
  1317. Specifies the maximum number of colormap entries that will be used.
  1318. If this many are not available, fewer will be used, but if more than
  1319. this many are available they will be left free for other applications.
  1320. XX resource:
  1321. .BR maxcolors .
  1322. Default: 256.
  1323. .TP
  1324. .B -loops
  1325. Specifies the desired number of loops per second.
  1326. .I Xsplinefun
  1327. attempts to maintain this speed by adaptively varying the duration
  1328. and freqency of sleeps.
  1329. If your X server is not capable of the requested speed, it will do the
  1330. best it can.
  1331. XX resource:
  1332. .BR loops .
  1333. Default: 50.
  1334. .TP
  1335. .B -id
  1336. Forks a background process and prints the process-id to stdout.
  1337. Useful if you want to make a menu command to kill
  1338. .IR xsplinefun .
  1339. XX resource:
  1340. .BR id .
  1341. Default: off.
  1342. .SH "SEE ALSO"
  1343. .IR xsetroot (1)
  1344. .SH AUTHOR
  1345. Copyright (C) 1992 by Jef Poskanzer
  1346. .\" Permission to use, copy, modify, and distribute this software and its
  1347. .\" documentation for any purpose and without fee is hereby granted, provided
  1348. .\" that the above copyright notice appear in all copies and that both that
  1349. .\" copyright notice and this permission notice appear in supporting
  1350. .\" documentation.  This software is provided "as is" without express or
  1351. .\" implied warranty.
  1352. SHAR_EOF
  1353. chmod 0644 xsplinefun.man ||
  1354. echo 'restore of xsplinefun.man failed'
  1355. Wc_c="`wc -c < 'xsplinefun.man'`"
  1356. test 1878 -eq "$Wc_c" ||
  1357.     echo 'xsplinefun.man: original size 1878, current size' "$Wc_c"
  1358. rm -f _shar_wnt_.tmp
  1359. fi
  1360. exit 0
  1361. -- 
  1362. --
  1363. mail: dcmartin@msi.com            Senior Systems Scientist
  1364. uucp: uunet!dcmartin            Molecular Simulations, Inc.
  1365. at&t: 408/522-9236            796 N. Pastoria Avenue
  1366.