546N/A/*
546N/A * Copyright (c) 1988-91 by Patrick J. Naughton.
546N/A *
546N/A * Permission to use, copy, modify, and distribute this software and its
546N/A * documentation for any purpose and without fee is hereby granted,
546N/A * provided that the above copyright notice appear in all copies and that
546N/A * both that copyright notice and this permission notice appear in
546N/A * supporting documentation.
546N/A *
546N/A * This file is provided AS IS with no warranties of any kind. The author
546N/A * shall have no liability with respect to the infringement of copyrights,
546N/A * trade secrets or any patents by this file or any part thereof. In no
546N/A * event will the author be liable for any lost revenue or profits or
546N/A * other special, indirect and consequential damages.
546N/A */
546N/A
546N/A/*
943N/A * Copyright (c) 1988, 1994, Oracle and/or its affiliates. All rights reserved.
546N/A *
546N/A * Permission is hereby granted, free of charge, to any person obtaining a
919N/A * copy of this software and associated documentation files (the "Software"),
919N/A * to deal in the Software without restriction, including without limitation
919N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense,
919N/A * and/or sell copies of the Software, and to permit persons to whom the
919N/A * Software is furnished to do so, subject to the following conditions:
546N/A *
919N/A * The above copyright notice and this permission notice (including the next
919N/A * paragraph) shall be included in all copies or substantial portions of the
919N/A * Software.
546N/A *
919N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
919N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
919N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
919N/A * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
919N/A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
919N/A * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
919N/A * DEALINGS IN THE SOFTWARE.
546N/A */
546N/A
546N/A/*-
546N/A * hopalong.c - Real Plane Fractals for xlock, the X Window System lockscreen.
546N/A *
546N/A * Copyright (c) 1991 by Patrick J. Naughton.
546N/A *
546N/A * See xlock.c for copying information.
546N/A *
546N/A * Revision History:
546N/A * 29-Oct-90: fix bad (int) cast.
546N/A * 29-Jul-90: support for multiple screens.
546N/A * 08-Jul-90: new timing and colors and new algorithm for fractals.
546N/A * 15-Dec-89: Fix for proper skipping of {White,Black}Pixel() in colors.
546N/A * 08-Oct-89: Fixed long standing typo bug in RandomInitHop();
546N/A * Fixed bug in memory allocation in inithop();
546N/A * Moved seconds() to an extern.
546N/A * Got rid of the % mod since .mod is slow on a sparc.
546N/A * 20-Sep-89: Lint.
546N/A * 31-Aug-88: Forked from xlock.c for modularity.
546N/A * 23-Mar-88: Coded HOPALONG routines from Scientific American Sept. 86 p. 14.
546N/A */
546N/A
546N/A#include "xlock.h"
546N/A#include <math.h>
546N/A
546N/Atypedef struct {
546N/A int centerx;
546N/A int centery; /* center of the screen */
546N/A double a;
546N/A double b;
546N/A double c;
546N/A double i;
546N/A double j; /* hopalong parameters */
546N/A int inc;
546N/A int pix;
546N/A long startTime;
546N/A} hopstruct;
546N/A
546N/Aextern XColor ssblack[];
546N/Aextern XColor sswhite[];
546N/A
546N/Astatic hopstruct hops[MAXSCREENS];
546N/Astatic XPoint *pointBuffer = 0; /* pointer for XDrawPoints */
546N/A
546N/A#define TIMEOUT 30
546N/A
546N/Avoid
546N/Ainithop(win)
546N/A Window win;
546N/A{
546N/A double range;
546N/A XWindowAttributes xgwa;
546N/A hopstruct *hp = &hops[screen];
546N/A
546N/A
546N/A XGetWindowAttributes(dsp, win, &xgwa);
546N/A hp->centerx = xgwa.width / 2;
546N/A hp->centery = xgwa.height / 2;
546N/A range = sqrt((double) hp->centerx * hp->centerx +
546N/A (double) hp->centery * hp->centery) /
546N/A (10.0 + random() % 10);
546N/A
546N/A hp->pix = 0;
546N/A hp->inc = (int) ((random() / MAXRAND) * 200) - 100;
546N/A hp->a = (random() / MAXRAND) * range - range / 2.0;
546N/A hp->b = (random() / MAXRAND) * range - range / 2.0;
546N/A hp->c = (random() / MAXRAND) * range - range / 2.0;
546N/A if (!(random() % 2))
546N/A hp->c = 0.0;
546N/A
546N/A hp->i = hp->j = 0.0;
546N/A
546N/A if (!pointBuffer)
546N/A pointBuffer = (XPoint *) malloc(batchcount * sizeof(XPoint));
546N/A
546N/A XSetForeground(dsp, Scr[screen].gc, ssblack[screen].pixel);
546N/A XFillRectangle(dsp, win, Scr[screen].gc, 0, 0,
546N/A hp->centerx * 2, hp->centery * 2);
546N/A XSetForeground(dsp, Scr[screen].gc, sswhite[screen].pixel);
546N/A hp->startTime = seconds();
546N/A}
546N/A
546N/A
546N/Avoid
546N/Adrawhop(win)
546N/A Window win;
546N/A{
546N/A double oldj;
546N/A int k = batchcount;
546N/A XPoint *xp = pointBuffer;
546N/A hopstruct *hp = &hops[screen];
546N/A
546N/A hp->inc++;
546N/A if (!mono && Scr[screen].npixels > 2) {
546N/A XSetForeground(dsp, Scr[screen].gc, Scr[screen].pixels[hp->pix]);
546N/A if (++hp->pix >= Scr[screen].npixels)
546N/A hp->pix = 0;
546N/A }
546N/A while (k--) {
546N/A oldj = hp->j;
546N/A hp->j = hp->a - hp->i;
546N/A hp->i = oldj + (hp->i < 0
546N/A ? sqrt(fabs(hp->b * (hp->i + hp->inc) - hp->c))
546N/A : -sqrt(fabs(hp->b * (hp->i + hp->inc) - hp->c)));
546N/A xp->x = hp->centerx + (int) (hp->i + hp->j);
546N/A xp->y = hp->centery - (int) (hp->i - hp->j);
546N/A xp++;
546N/A }
546N/A XDrawPoints(dsp, win, Scr[screen].gc,
546N/A pointBuffer, batchcount, CoordModeOrigin);
546N/A if (seconds() - hp->startTime > TIMEOUT)
546N/A inithop(win);
546N/A}