+/* Set up colour map */
+ if (cryst->colors && cryst->ncolors && !cryst->no_colors)
+ free_colors(display, cryst->cmap, cryst->colors, cryst->ncolors);
+ if (cryst->colors)
+ (void) free((void *) cryst->colors);
+ cryst->colors = 0;
+#ifdef STANDALONE
+ cryst->ncolors = get_integer_resource("ncolors", "Integer");
+#else
+ cryst->ncolors = MI_NCOLORS(mi);
+#endif
+ if (cryst->ncolors < 2)
+ cryst->ncolors = 2;
+ if (cryst->ncolors <= 2)
+ cryst->mono_p = True;
+ else
+ cryst->mono_p = False;
+
+ if (cryst->mono_p)
+ cryst->colors = 0;
+ else
+ cryst->colors = (XColor *) malloc(sizeof (*cryst->colors) * (cryst->ncolors + 1));
+#ifdef STANDALONE
+ cryst->cycle_p = has_writable_cells(mi->xgwa.screen, mi->xgwa.visual);
+#else
+ cryst->cycle_p = has_writable_cells(mi);
+#endif
+ if (cryst->cycle_p) {
+ if (MI_IS_FULLRANDOM(mi)) {
+ if (NRAND(8) == 7)
+ cryst->cycle_p = False;
+ else
+ cryst->cycle_p = True;
+ } else {
+ cryst->cycle_p = cycle_p;
+ }
+ }
+ if (!cryst->mono_p) {
+ if (!(LRAND() % 10))
+ make_random_colormap(
+#ifdef STANDALONE
+ mi->dpy, mi->xgwa.visual,
+#else
+ mi,
+#endif
+ cryst->cmap, cryst->colors, &cryst->ncolors,
+ True, True, &cryst->cycle_p
+#ifdef STANDALONE
+ , False
+#endif
+ );
+ else if (!(LRAND() % 2))
+ make_uniform_colormap(
+#ifdef STANDALONE
+ mi->dpy, mi->xgwa.visual,
+#else
+ mi,
+#endif
+ cryst->cmap, cryst->colors, &cryst->ncolors,
+ True, &cryst->cycle_p
+#ifdef STANDALONE
+ , False
+#endif
+ );
+ else
+ make_smooth_colormap(
+#ifdef STANDALONE
+ mi->dpy, mi->xgwa.visual,
+#else
+ mi,
+#endif
+ cryst->cmap, cryst->colors, &cryst->ncolors,
+ True, &cryst->cycle_p
+#ifdef STANDALONE
+ , False
+#endif
+ );
+ }
+ XInstallColormap(display, cryst->cmap);
+ if (cryst->ncolors < 2) {
+ cryst->ncolors = 2;
+ cryst->no_colors = True;
+ } else
+ cryst->no_colors = False;
+ if (cryst->ncolors <= 2)
+ cryst->mono_p = True;
+
+ if (cryst->mono_p)
+ cryst->cycle_p = False;
+