1 /* -*- Mode: C; tab-width: 4 -*-
2 * fadeplot.c --- some easy plotting stuff, by Bas van Gaalen, Holland, PD
4 #if !defined( lint ) && !defined( SABER )
5 static const char sccsid[] = "@(#)fadeplot.c 4.04 97/07/26 xlockmore";
8 /* Converted for xlock by Charles Vidal
9 * See xlock.c for copying information.
11 * Permission to use, copy, modify, and distribute this software and its
12 * documentation for any purpose and without fee is hereby granted,
13 * provided that the above copyright notice appear in all copies and that
14 * both that copyright notice and this permission notice appear in
15 * supporting documentation.
17 * This file is provided AS IS with no warranties of any kind. The author
18 * shall have no liability with respect to the infringement of copyrights,
19 * trade secrets or any patents by this file or any part thereof. In no
20 * event will the author be liable for any lost revenue or profits or
21 * other special, indirect and consequential damages.
25 1) Not random enough, i.e. always same starting position.
26 2) Needs to be less flashy
30 # define PROGCLASS "Fadeplot"
31 # define HACK_INIT init_fadeplot
32 # define HACK_DRAW draw_fadeplot
33 # define fadeplot_opts xlockmore_opts
34 # define DEFAULTS "*count: 10 \n" \
38 # define BRIGHT_COLORS
39 # define UNIFORM_COLORS
40 # include "xlockmore.h" /* from the xscreensaver distribution */
41 #else /* STANDALONE */
42 # include "xlock.h" /* from the xlockmore distribution */
43 #endif /* STANDALONE */
45 ModeSpecOpt fadeplot_opts = {
46 0, NULL, 0, NULL, NULL };
52 XPoint speed, step, factor, st;
53 int temps, maxpts, nbstep;
61 static fadeplotstruct *fadeplots = NULL;
64 initSintab(ModeInfo * mi)
66 fadeplotstruct *fp = &fadeplots[MI_SCREEN(mi)];
70 for (i = 0; i < ANGLES; i++) {
71 x = SINF(i * 2 * M_PI / ANGLES);
72 fp->stab[i] = (int) (x * ABS(x) * fp->min) + fp->min;
77 init_fadeplot(ModeInfo * mi)
81 if (fadeplots == NULL) {
82 if ((fadeplots = (fadeplotstruct *) calloc(MI_NUM_SCREENS(mi),
83 sizeof (fadeplotstruct))) == NULL)
86 fp = &fadeplots[MI_SCREEN(mi)];
88 fp->width = MI_WIN_WIDTH(mi);
89 fp->height = MI_WIN_HEIGHT(mi);
90 fp->min = MAX(MIN(fp->width, fp->height) / 2, 1);
97 fp->factor.x = MAX(fp->width / (2 * fp->min), 1);
98 fp->factor.y = MAX(fp->height / (2 * fp->min), 1);
100 fp->nbstep = MI_BATCHCOUNT(mi);
101 if (fp->nbstep < -MINSTEPS) {
102 fp->nbstep = NRAND(-fp->nbstep - MINSTEPS + 1) + MINSTEPS;
103 } else if (fp->nbstep < MINSTEPS)
104 fp->nbstep = MINSTEPS;
106 fp->maxpts = MI_CYCLES(mi);
111 fp->pts = (XPoint *) calloc(fp->maxpts, sizeof (XPoint));
112 if (MI_NPIXELS(mi) > 2)
113 fp->pix = NRAND(MI_NPIXELS(mi));
117 XClearWindow(MI_DISPLAY(mi), MI_WINDOW(mi));
121 draw_fadeplot(ModeInfo * mi)
123 fadeplotstruct *fp = &fadeplots[MI_SCREEN(mi)];
124 Display *display = MI_DISPLAY(mi);
125 Window window = MI_WINDOW(mi);
130 XSetForeground(display, gc, MI_WIN_BLACK_PIXEL(mi));
131 XDrawPoints(display, window, gc, fp->pts, fp->maxpts, CoordModeOrigin);
133 if (MI_NPIXELS(mi) > 2) {
134 XSetForeground(display, gc, MI_PIXEL(mi, fp->pix));
135 if (++fp->pix >= MI_NPIXELS(mi))
138 XSetForeground(display, gc, MI_WIN_WHITE_PIXEL(mi));
140 for (temp = fp->nbstep - 1; temp >= 0; temp--) {
142 for (i = 0; i < fp->maxpts / fp->nbstep; i++) {
143 fp->pts[temp * i + i].x =
144 fp->stab[(fp->st.x + fp->speed.x * j + i * fp->step.x) % ANGLES] *
145 fp->factor.x + fp->width / 2 - fp->min;
146 fp->pts[temp * i + i].y =
147 fp->stab[(fp->st.y + fp->speed.y * j + i * fp->step.y) % ANGLES] *
148 fp->factor.y + fp->height / 2 - fp->min;
151 XDrawPoints(display, window, gc, fp->pts, fp->maxpts, CoordModeOrigin);
153 fp->st.x = (fp->st.x + fp->speed.x) % ANGLES;
154 fp->st.y = (fp->st.y + fp->speed.y) % ANGLES;
156 if ((fp->temps % (ANGLES / 2)) == 0) {
157 fp->temps = fp->temps % ANGLES * 5;
158 if ((fp->temps % (ANGLES)) == 0)
159 fp->speed.y = (fp->speed.y++) % 30 + 1;
160 if ((fp->temps % (ANGLES * 2)) == 0)
161 fp->speed.x = (fp->speed.x) % 20;
162 if ((fp->temps % (ANGLES * 3)) == 0)
163 fp->step.y = (fp->step.y++) % 2 + 1;
164 XClearWindow(display, window);
168 refresh_fadeplot(ModeInfo * mi)
174 release_fadeplot(ModeInfo * mi)
176 /* Do nothing, it will refresh by itself */