http://www.jwz.org/xscreensaver/xscreensaver-5.11.tar.gz
[xscreensaver] / hacks / substrate.c
1 /*
2  *  Substrate (dragorn@kismetwireless.net)
3  *  Directly ported code from complexification.net Substrate art
4  *  http://complexification.net/gallery/machines/substrate/applet_s/substrate_s.pde
5  *
6  *  Substrate code:
7  *  j.tarbell   June, 2004
8  *  Albuquerque, New Mexico
9  *  complexification.net
10  *
11  *  CHANGES
12  *
13  *  1.1  dragorn  Jan 04 2005    Fixed some indenting, typo in errors for parsing
14  *                                cmdline args
15  *  1.1  dagraz   Jan 04 2005    Added option for circular cracks (David Agraz)
16  *                               Cleaned up issues with timeouts in start_crack (DA)
17  *  1.0  dragorn  Oct 10 2004    First port done
18  *
19  * Directly based the hacks of: 
20  * 
21  * xscreensaver, Copyright (c) 1997, 1998, 2002 Jamie Zawinski <jwz@jwz.org>
22  *
23  * Permission to use, copy, modify, distribute, and sell this software and its
24  * documentation for any purpose is hereby granted without fee, provided that
25  * the above copyright notice appear in all copies and that both that
26  * copyright notice and this permission notice appear in supporting
27  * documentation.  No representations are made about the suitability of this
28  * software for any purpose.  It is provided "as is" without express or 
29  * implied warranty.
30  */
31
32 #include <math.h>
33 #include "screenhack.h"
34
35 /* this program goes faster if some functions are inline.  The following is
36  * borrowed from ifs.c */
37 #if !defined( __GNUC__ ) && !defined(__cplusplus) && !defined(c_plusplus)
38 #undef inline
39 #define inline                  /* */
40 #endif
41
42 #define STEP 0.42
43
44 /* Raw colormap extracted from pollockEFF.gif */
45 static const char *rgb_colormap[] = {
46     "#201F21", "#262C2E", "#352626", "#372B27",
47     "#302C2E", "#392B2D", "#323229", "#3F3229",
48     "#38322E", "#2E333D", "#333A3D", "#473329",
49     "#40392C", "#40392E", "#47402C", "#47402E",
50     "#4E402C", "#4F402E", "#4E4738", "#584037",
51     "#65472D", "#6D5D3D", "#745530", "#755532",
52     "#745D32", "#746433", "#7C6C36", "#523152",
53     "#444842", "#4C5647", "#655D45", "#6D5D44",
54     "#6C5D4E", "#746C43", "#7C6C42", "#7C6C4B",
55     "#6B734B", "#73734B", "#7B7B4A", "#6B6C55",
56     "#696D5E", "#7B6C5D", "#6B7353", "#6A745D",
57     "#727B52", "#7B7B52", "#57746E", "#687466",
58     "#9C542B", "#9D5432", "#9D5B35", "#936B36",
59     "#AA7330", "#C45A27", "#D95223", "#D85A20",
60     "#DB5A23", "#E57037", "#836C4B", "#8C6B4B",
61     "#82735C", "#937352", "#817B63", "#817B6D",
62     "#927B63", "#D9893B", "#E49832", "#DFA133",
63     "#E5A037", "#F0AB3B", "#8A8A59", "#B29A58",
64     "#89826B", "#9A8262", "#888B7C", "#909A7A",
65     "#A28262", "#A18A69", "#A99968", "#99A160",
66     "#99A168", "#CA8148", "#EB8D43", "#C29160",
67     "#C29168", "#D1A977", "#C9B97F", "#F0E27B",
68     "#9F928B", "#C0B999", "#E6B88F", "#C8C187",
69     "#E0C886", "#F2CC85", "#F5DA83", "#ECDE9D",
70     "#F5D294", "#F5DA94", "#F4E784", "#F4E18A",
71     "#F4E193", "#E7D8A7", "#F1D4A5", "#F1DCA5",
72     "#F4DBAD", "#F1DCAE", "#F4DBB5", "#F5DBBD",
73     "#F4E2AD", "#F5E9AD", "#F4E3BE", "#F5EABE",
74     "#F7F0B6", "#D9D1C1", "#E0D0C0", "#E7D8C0",
75     "#F1DDC6", "#E8E1C0", "#F3EDC7", "#F6ECCE",
76     "#F8F2C7", "#EFEFD0", 0
77 };
78
79 typedef struct {
80     /* Synthesis of data from Crack:: and SandPainter:: */
81     float x, y;
82     float t;
83     float ys, xs, t_inc; /* for curvature calculations */
84
85     int curved;
86
87     unsigned long sandcolor;
88     float sandp, sandg;
89
90     float degrees_drawn;
91
92     int crack_num;
93
94 } crack;
95
96 struct field {
97     unsigned int height;
98     unsigned int width;
99
100     unsigned int initial_cracks;
101     
102     unsigned int num;
103     unsigned int max_num;
104
105     int grains; /* number of grains in the sand painting */
106
107     int circle_percent;
108
109     crack *cracks; /* grid of cracks */
110     int *cgrid; /* grid of actual crack placement */
111
112     /* Raw map of pixels we need to keep for alpha blending */
113     unsigned long int *off_img;
114    
115     /* color parms */
116     int numcolors;
117     unsigned long *parsedcolors;
118     unsigned long fgcolor;
119     unsigned long bgcolor;
120     int visdepth;
121
122     unsigned int cycles;
123
124     unsigned int wireframe;
125 };
126
127 struct state {
128   Display *dpy;
129   Window window;
130
131   struct field *f;
132   unsigned int max_cycles;
133   int growth_delay;
134   GC fgc;
135   XWindowAttributes xgwa;
136   XGCValues gcv;
137 };
138
139
140 static void 
141 *xrealloc(void *p, size_t size)
142 {
143     void *ret;
144     if ((ret = realloc(p, size)) == NULL) {
145         fprintf(stderr, "%s: out of memory\n", progname);
146         exit(1);
147     }
148     return ret;
149 }
150
151 static struct field 
152 *init_field(void)
153 {
154     struct field *f = xrealloc(NULL, sizeof(struct field));
155     f->height = 0;
156     f->width = 0;
157     f->initial_cracks = 0;
158     f->num = 0;
159     f->max_num = 0;
160     f->cracks = NULL;
161     f->cgrid = NULL;
162     f->off_img = NULL;
163     f->numcolors = 0;
164     f->parsedcolors = NULL;
165     f->cycles = 0;
166     f->wireframe = 0;
167     f->fgcolor = 0;
168     f->bgcolor = 0;
169     f->visdepth = 0;
170     f->grains = 0;
171     f->circle_percent = 0;
172     return f;
173 }
174
175 /* Quick references to pixels in the offscreen map and in the crack grid */
176 #define ref_pixel(f, x, y)   ((f)->off_img[(y) * (f)->width + (x)])
177 #define ref_cgrid(f, x, y)   ((f)->cgrid[(y) * (f)->width + (x)])
178
179 static inline void start_crack(struct field *f, crack *cr) 
180 {
181     /* synthesis of Crack::findStart() and crack::startCrack() */
182     int px = 0;
183     int py = 0;
184     int found = 0;
185     int timeout = 0;
186     float a;
187
188     /* shift until crack is found */
189     while ((!found) && (timeout++ < 10000)) {
190         px = (int) (random() % f->width);
191         py = (int) (random() % f->height);
192
193         if (ref_cgrid(f, px, py) < 10000)
194             found = 1;
195     }
196
197     if ( !found ) {
198         /* We timed out.  Use our default values */
199         px = cr->x;
200         py = cr->y;
201
202         /* Sanity check needed */
203         if (px < 0) px = 0;
204         if (px >= f->width) px = f->width - 1;
205         if (py < 0) py = 0;
206         if (py >= f->height) py = f->height - 1;
207
208         ref_cgrid(f, px, py) = cr->t;
209     }
210
211     /* start a crack */
212     a = ref_cgrid(f, px, py);
213
214     if ((random() % 100) < 50) {
215         /* conversion of the java int(random(-2, 2.1)) */
216         a -= 90 + (frand(4.1) - 2.0);
217     } else {
218         a += 90 + (frand(4.1) - 2.0);
219     }
220
221     if ((random() % 100) < f->circle_percent) {
222         float r; /* radius */
223         float radian_inc;
224
225         cr->curved = 1;
226         cr->degrees_drawn = 0;
227
228         r = 10 + (random() % ((f->width + f->height) / 2));
229
230         if ((random() % 100) < 50) {
231             r *= -1;
232         }
233
234         /* arc length = r * theta => theta = arc length / r */
235         radian_inc = STEP / r;
236         cr->t_inc = radian_inc * 360 / 2 / M_PI;
237
238         cr->ys = r * sin(radian_inc);
239         cr->xs = r * ( 1 - cos(radian_inc));
240
241     }
242     else {
243         cr->curved = 0;
244     }
245
246     /* Condensed from Crack::startCrack */
247     cr->x = px + ((float) 0.61 * cos(a * M_PI / 180));
248     cr->y = py + ((float) 0.61 * sin(a * M_PI / 180));
249     cr->t = a;
250
251 }
252
253 static inline void make_crack(struct field *f) 
254 {
255     crack *cr;
256
257     if (f->num < f->max_num) {
258         /* make a new crack */
259         f->cracks = (crack *) xrealloc(f->cracks, sizeof(crack) * (f->num + 1));
260
261         cr = &(f->cracks[f->num]);
262         /* assign colors */
263         cr->sandp = 0;
264         cr->sandg = (frand(0.2) - 0.01);
265         cr->sandcolor = f->parsedcolors[random() % f->numcolors];
266         cr->crack_num = f->num;
267         cr->curved = 0;
268         cr->degrees_drawn = 0;
269
270         /* We could use these values in the timeout case of start_crack */
271
272         cr->x = random() % f->width;
273         cr->y = random() % f->height;
274         cr->t = random() % 360;
275
276         /* start it */
277         start_crack(f, cr);
278
279         f->num++;
280     }
281 }
282
283 static inline void point2rgb(int depth, unsigned long c, int *r, int *g, int *b) 
284 {
285     switch(depth) {
286         case 32:
287         case 24:
288 #ifdef HAVE_COCOA
289             /* This program idiotically does not go through a color map, so
290                we have to hardcode in knowledge of how jwxyz.a packs pixels!
291                Fix it to go through st->colors[st->ncolors] instead!
292              */
293             *r = (c & 0x00ff0000) >> 16; 
294             *g = (c & 0x0000ffff) >>  8;
295             *b = (c & 0x000000ff); 
296 #else
297             *g = (c & 0xff00) >> 8; 
298             *r = (c & 0xff0000) >> 16; 
299             *b = c & 0xff; 
300 #endif
301             break;
302         case 16:
303             *g = ((c >> 5) & 0x3f) << 2;
304             *r = ((c >> 11) & 0x1f) << 3; 
305             *b = (c & 0x1f) << 3; 
306             break;
307         case 15:
308             *g = ((c >> 5) & 0x1f) << 3;
309             *r = ((c >> 10) & 0x1f) << 3;
310             *b = (c & 0x1f) << 3;
311             break;
312     }
313 }
314
315 static inline unsigned long rgb2point(int depth, int r, int g, int b) 
316 {
317     unsigned long ret = 0;
318
319     switch(depth) {
320         case 32:
321             ret = 0xff000000;
322         case 24:
323 #ifdef HAVE_COCOA
324             /* This program idiotically does not go through a color map, so
325                we have to hardcode in knowledge of how jwxyz.a packs pixels!
326                Fix it to go through st->colors[st->ncolors] instead!
327              */
328             ret = 0xFF000000 | (r << 16) | (g << 8) | b;
329 #else
330             ret |= (r << 16) | (g << 8) | b;
331 #endif
332             break;
333         case 16:
334             ret = ((r>>3) << 11) | ((g>>2)<<5) | (b>>3);
335             break;
336         case 15:
337             ret = ((r>>3) << 10) | ((g>>3)<<5) | (b>>3);
338             break;
339     }
340
341     return ret;
342 }
343
344 /* alpha blended point drawing -- this is Not Right and will likely fail on 
345  * non-intel platforms as it is now, needs fixing */
346 static inline unsigned long
347 trans_point(struct state *st,
348             int x1, int y1, unsigned long myc, float a, 
349             struct field *f) 
350 {
351     if ((x1 >= 0) && (x1 < f->width) && (y1 >= 0) && (y1 < f->height)) {
352         if (a >= 1.0) {
353             ref_pixel(f, x1, y1) = myc;
354         } else {
355             int or = 0, og = 0, ob = 0;
356             int r = 0, g = 0, b = 0;
357             int nr, ng, nb;
358             unsigned long c;
359
360             c = ref_pixel(f, x1, y1);
361
362             point2rgb(f->visdepth, c, &or, &og, &ob);
363             point2rgb(f->visdepth, myc, &r, &g, &b);
364
365             nr = or + (r - or) * a;
366             ng = og + (g - og) * a;
367             nb = ob + (b - ob) * a;
368
369             c = rgb2point(f->visdepth, nr, ng, nb);
370
371             ref_pixel(f, x1, y1) = c;
372
373             return c;
374         }
375     }
376
377     return f->bgcolor;
378 }
379
380 static inline void 
381 region_color(struct state *st, GC fgc, struct field *f, crack *cr) 
382 {
383     /* synthesis of Crack::regionColor() and SandPainter::render() */
384
385     float rx = cr->x;
386     float ry = cr->y;
387     int openspace = 1;
388     int cx, cy;
389     float maxg;
390     int grains, i;
391     float w;
392     float drawx, drawy;
393     unsigned long c;
394
395     while (openspace) {
396         /* move perpendicular to crack */
397         rx += (0.81 * sin(cr->t * M_PI/180));
398         ry -= (0.81 * cos(cr->t * M_PI/180));
399
400         cx = (int) rx;
401         cy = (int) ry;
402
403         if ((cx >= 0) && (cx < f->width) && (cy >= 0) && (cy < f->height)) {
404             /* safe to check */
405             if (f->cgrid[cy * f->width + cx] > 10000) {
406                 /* space is open */
407             } else {
408                 openspace = 0;
409             }
410         } else {
411             openspace = 0;
412         }
413     }
414
415     /* SandPainter stuff here */
416
417     /* Modulate gain */
418     cr->sandg += (frand(0.1) - 0.050);
419     maxg = 1.0;
420
421     if (cr->sandg < 0)
422         cr->sandg = 0;
423
424     if (cr->sandg > maxg)
425         cr->sandg = maxg;
426
427     grains = f->grains;
428
429     /* Lay down grains of sand */
430     w = cr->sandg / (grains - 1);
431
432     for (i = 0; i < grains; i++) {
433         drawx = (cr->x + (rx - cr->x) * sin(cr->sandp + sin((float) i * w)));
434         drawy = (cr->y + (ry - cr->y) * sin(cr->sandp + sin((float) i * w)));
435
436         /* Draw sand bit */
437         c = trans_point(st, drawx, drawy, cr->sandcolor, (0.1 - i / (grains * 10.0)), f);
438
439         XSetForeground(st->dpy, fgc, c);
440         XDrawPoint(st->dpy, st->window, fgc, (int) drawx, (int) drawy);
441         XSetForeground(st->dpy, fgc, f->fgcolor);
442     }
443 }
444
445 static void build_substrate(struct field *f) 
446 {
447     int tx;
448     /* int ty; */
449
450     f->cycles = 0;
451
452     if (f->cgrid) {
453         free(f->cgrid);
454         f->cgrid = NULL;
455     }
456
457     if (f->cracks) {
458         free(f->cracks);
459         f->cracks = NULL;
460     }
461
462     f->num = 0;
463
464     /* erase the crack grid */
465     f->cgrid = (int *) xrealloc(f->cgrid, sizeof(int) * f->height * f->width);
466     memset(f->cgrid, 10001, f->height * f->width * sizeof(int));
467
468     /* Not necessary now that make_crack ensures we have usable default
469      *  values in start_crack's timeout case 
470     * make random crack seeds *
471     for (tx = 0; tx < 16; tx++) {
472         ty = (int) (random() % (f->width * f->height - 1));
473         f->cgrid[ty] = (int) random() % 360;
474     }
475     */
476
477     /* make the initial cracks */
478     for (tx = 0; tx < f->initial_cracks; tx++)
479         make_crack(f);
480 }
481
482
483 static inline void
484 movedrawcrack(struct state *st, GC fgc, struct field *f, int cracknum) 
485 {
486     /* Basically Crack::move() */
487
488     int cx, cy;
489     crack *cr = &(f->cracks[cracknum]);
490
491     /* continue cracking */
492     if ( !cr->curved ) {
493         cr->x += ((float) STEP * cos(cr->t * M_PI/180));
494         cr->y += ((float) STEP * sin(cr->t * M_PI/180));
495     }
496     else {
497         float oldx, oldy;
498
499         oldx = cr->x;
500         oldy = cr->y;
501
502         cr->x += ((float) cr->ys * cos(cr->t * M_PI/180));
503         cr->y += ((float) cr->ys * sin(cr->t * M_PI/180));
504
505         cr->x += ((float) cr->xs * cos(cr->t * M_PI/180 - M_PI / 2));
506         cr->x += ((float) cr->xs * sin(cr->t * M_PI/180 - M_PI / 2));
507
508         cr->t += cr->t_inc;
509         cr->degrees_drawn += abs(cr->t_inc);
510     }
511
512     /* bounds check */
513     /* modification of random(-0.33,0.33) */
514     cx = (int) (cr->x + (frand(0.66) - 0.33));
515     cy = (int) (cr->y + (frand(0.66) - 0.33));
516
517
518     if ((cx >= 0) && (cx < f->width) && (cy >= 0) && (cy < f->height)) {
519         /* draw sand painter if we're not wireframe */
520         if (!f->wireframe)
521             region_color(st, fgc, f, cr);
522
523         /* draw fgcolor crack */
524         ref_pixel(f, cx, cy) = f->fgcolor;
525         XDrawPoint(st->dpy, st->window, fgc, cx, cy);
526
527         if ( cr->curved && (cr->degrees_drawn > 360) ) {
528             /* completed the circle, stop cracking */
529             start_crack(f, cr); /* restart ourselves */
530             make_crack(f); /* generate a new crack */
531         }
532         /* safe to check */
533         else if ((f->cgrid[cy * f->width + cx] > 10000) ||
534                  (abs(f->cgrid[cy * f->width + cx] - cr->t) < 5)) {
535             /* continue cracking */
536             f->cgrid[cy * f->width + cx] = (int) cr->t;
537         } else if (abs(f->cgrid[cy * f->width + cx] - cr->t) > 2) {
538             /* crack encountered (not self), stop cracking */
539             start_crack(f, cr); /* restart ourselves */
540             make_crack(f); /* generate a new crack */
541         }
542     } else {
543         /* out of bounds, stop cracking */
544
545         /* need these in case of timeout in start_crack */
546         cr->x = random() % f->width;
547         cr->y = random() % f->height;
548         cr->t = random() % 360;
549
550         start_crack(f, cr); /* restart ourselves */
551         make_crack(f); /* generate a new crack */
552     }
553
554 }
555
556
557 static void build_img(Display *dpy, Window window, XWindowAttributes xgwa, GC fgc, 
558                struct field *f) 
559 {
560     if (f->off_img) {
561         free(f->off_img);
562         f->off_img = NULL;
563     }
564
565     f->off_img = (unsigned long *) xrealloc(f->off_img, sizeof(unsigned long) * 
566                                             f->width * f->height);
567
568     memset(f->off_img, f->bgcolor, sizeof(unsigned long) * f->width * f->height);
569 }
570
571
572 static void *
573 substrate_init (Display *dpy, Window window)
574 {
575     struct state *st = (struct state *) calloc (1, sizeof(*st));
576     XColor tmpcolor;
577
578     st->dpy = dpy;
579     st->window = window;
580     st->f = init_field();
581
582     st->growth_delay = (get_integer_resource(st->dpy, "growthDelay", "Integer"));
583     st->max_cycles = (get_integer_resource(st->dpy, "maxCycles", "Integer"));
584     st->f->initial_cracks = (get_integer_resource(st->dpy, "initialCracks", "Integer"));
585     st->f->max_num = (get_integer_resource(st->dpy, "maxCracks", "Integer"));
586     st->f->wireframe = (get_boolean_resource(st->dpy, "wireFrame", "Boolean"));
587     st->f->grains = (get_integer_resource(st->dpy, "sandGrains", "Integer"));
588     st->f->circle_percent = (get_integer_resource(st->dpy, "circlePercent", "Integer"));
589
590     if (st->f->initial_cracks <= 2) {
591         fprintf(stderr, "%s: Initial cracks must be greater than 2\n", progname);
592         exit (1);
593     }
594
595     if (st->f->max_num <= 10) {
596         fprintf(stderr, "%s: Maximum number of cracks must be less than 10\n", 
597                 progname);
598         exit (1);
599     }
600
601     if (st->f->circle_percent < 0) {
602         fprintf(stderr, "%s: circle percent must be at least 0\n", progname);
603         exit (1);
604     }
605
606     if (st->f->circle_percent > 100) {
607         fprintf(stderr, "%s: circle percent must be less than 100\n", progname);
608         exit (1);
609     }
610     
611     XGetWindowAttributes(st->dpy, st->window, &st->xgwa);
612
613     st->f->height = st->xgwa.height;
614     st->f->width = st->xgwa.width;
615     st->f->visdepth = st->xgwa.depth;
616  
617     /* Count the colors in our map and assign them in a horrifically inefficient 
618      * manner but it only happens once */
619     while (rgb_colormap[st->f->numcolors] != NULL) {
620         st->f->parsedcolors = (unsigned long *) xrealloc(st->f->parsedcolors, 
621                                                      sizeof(unsigned long) * 
622                                                      (st->f->numcolors + 1));
623         if (!XParseColor(st->dpy, st->xgwa.colormap, rgb_colormap[st->f->numcolors], &tmpcolor)) {
624             fprintf(stderr, "%s: couldn't parse color %s\n", progname,
625                     rgb_colormap[st->f->numcolors]);
626             exit(1);
627         }
628
629         if (!XAllocColor(st->dpy, st->xgwa.colormap, &tmpcolor)) {
630             fprintf(stderr, "%s: couldn't allocate color %s\n", progname,
631                     rgb_colormap[st->f->numcolors]);
632             exit(1);
633         }
634
635         st->f->parsedcolors[st->f->numcolors] = tmpcolor.pixel;
636
637         st->f->numcolors++;
638     }
639
640     st->gcv.foreground = get_pixel_resource(st->dpy, st->xgwa.colormap,
641                                         "foreground", "Foreground");
642     st->gcv.background = get_pixel_resource(st->dpy, st->xgwa.colormap,
643                                         "background", "Background");
644     st->fgc = XCreateGC(st->dpy, st->window, GCForeground, &st->gcv);
645
646     st->f->fgcolor = st->gcv.foreground;
647     st->f->bgcolor = st->gcv.background;
648
649     /* Initialize stuff */
650     build_img(st->dpy, st->window, st->xgwa, st->fgc, st->f);
651     build_substrate(st->f);
652     
653     return st;
654 }
655
656 static unsigned long
657 substrate_draw (Display *dpy, Window window, void *closure)
658 {
659   struct state *st = (struct state *) closure;
660   int tempx;
661
662   if ((st->f->cycles % 10) == 0) {
663
664     /* Restart if the window size changes */
665     XGetWindowAttributes(st->dpy, st->window, &st->xgwa);
666
667     if (st->f->height != st->xgwa.height || st->f->width != st->xgwa.width) {
668       st->f->height = st->xgwa.height;
669       st->f->width = st->xgwa.width;
670       st->f->visdepth = st->xgwa.depth;
671
672       build_substrate(st->f);
673       build_img(st->dpy, st->window, st->xgwa, st->fgc, st->f);
674       XSetForeground(st->dpy, st->fgc, st->gcv.background);
675       XFillRectangle(st->dpy, st->window, st->fgc, 0, 0, st->xgwa.width, st->xgwa.height);
676       XSetForeground(st->dpy, st->fgc, st->gcv.foreground);
677     }
678   }
679
680   for (tempx = 0; tempx < st->f->num; tempx++) {
681     movedrawcrack(st, st->fgc, st->f, tempx);
682   }
683
684   st->f->cycles++;
685
686   if (st->f->cycles >= st->max_cycles && st->max_cycles != 0) {
687     build_substrate(st->f);
688     build_img(st->dpy, st->window, st->xgwa, st->fgc, st->f);
689     XSetForeground(st->dpy, st->fgc, st->gcv.background);
690     XFillRectangle(st->dpy, st->window, st->fgc, 0, 0, st->xgwa.width, st->xgwa.height);
691     XSetForeground(st->dpy, st->fgc, st->gcv.foreground);
692   }
693
694   return st->growth_delay;
695 }
696
697
698 static void
699 substrate_reshape (Display *dpy, Window window, void *closure, 
700                  unsigned int w, unsigned int h)
701 {
702 }
703
704 static Bool
705 substrate_event (Display *dpy, Window window, void *closure, XEvent *event)
706 {
707   return False;
708 }
709
710 static void
711 substrate_free (Display *dpy, Window window, void *closure)
712 {
713   struct state *st = (struct state *) closure;
714   free (st);
715 }
716
717 static const char *substrate_defaults[] = {
718     ".background: white",
719     ".foreground: black",
720     "*fpsSolid: true",
721     "*wireFrame: false",
722     "*maxCycles: 10000",
723     "*growthDelay: 18000",
724     "*initialCracks: 3",
725     "*maxCracks: 100",
726     "*sandGrains: 64",
727     "*circlePercent: 33",
728     0
729 };
730
731 static XrmOptionDescRec substrate_options[] = {
732     {"-background", ".background", XrmoptionSepArg, 0},
733     {"-foreground", ".foreground", XrmoptionSepArg, 0},
734     {"-wireframe", ".wireFrame", XrmoptionNoArg, "true"},
735     {"-max-cycles", ".maxCycles", XrmoptionSepArg, 0},
736     {"-growth-delay", ".growthDelay", XrmoptionSepArg, 0},
737     {"-initial-cracks", ".initialCracks", XrmoptionSepArg, 0},
738     {"-max-cracks", ".maxCracks", XrmoptionSepArg, 0},
739     {"-sand-grains", ".sandGrains", XrmoptionSepArg, 0},
740     {"-circle-percent", ".circlePercent", XrmoptionSepArg, 0},
741     {0, 0, 0, 0}
742 };
743
744 XSCREENSAVER_MODULE ("Substrate", substrate)