+/* Golden Ratio
+ * Suppose you're dividing a rectangle of length A+B
+ * into two parts, of length A and B respectively. You want the ratio of
+ * A to B to be the same as the ratio of the whole (A+B) to A. The golden
+ * ratio (phi) is that ratio. Supposed to be visually pleasing. */
+#define PHI 1.61803
+#define PHI1 (1.0/PHI)
+#define PHI2 (1.0 - PHI1)
+
+/* copied from make_random_colormap in colors.c */
+static void
+make_mondrian_colormap (Screen *screen, Visual *visual, Colormap cmap,
+ XColor *colors, int *ncolorsP,
+ Bool allocate_p,
+ Bool *writable_pP,
+ Bool verbose_p)
+{
+ Display *dpy = DisplayOfScreen (screen);
+ Bool wanted_writable = (allocate_p && writable_pP && *writable_pP);
+ int ncolors = 8;
+ int i;
+
+ if (*ncolorsP <= 0) return;
+
+ /* If this visual doesn't support writable cells, don't bother trying. */
+ if (wanted_writable && !has_writable_cells(screen, visual))
+ *writable_pP = False;
+
+ for (i = 0; i < ncolors; i++)
+ {
+ colors[i].flags = DoRed|DoGreen|DoBlue;
+ colors[i].red = 0;
+ colors[i].green = 0;
+ colors[i].blue = 0;
+
+ switch(i) {
+ case 0: case 1: case 2: case 3: case 7: /* white */
+ colors[i].red = 0xE800;
+ colors[i].green = 0xE800;
+ colors[i].blue = 0xE800;
+ break;
+ case 4:
+ colors[i].red = 0xCFFF; break; /* red */
+ case 5:
+ colors[i].red = 0x2000;
+ colors[i].blue = 0xCFFF; break; /* blue */
+ case 6:
+ colors[i].red = 0xDFFF; /* yellow */
+ colors[i].green = 0xCFFF; break;
+ }
+ }
+
+ if (!allocate_p)
+ return;
+
+ RETRY_NON_WRITABLE:
+ if (writable_pP && *writable_pP)
+ {
+ unsigned long *pixels = (unsigned long *)
+ malloc(sizeof(*pixels) * (ncolors + 1));
+
+ allocate_writable_colors (screen, cmap, pixels, &ncolors);
+ if (ncolors > 0)
+ for (i = 0; i < ncolors; i++)
+ colors[i].pixel = pixels[i];
+ free (pixels);
+ if (ncolors > 0)
+ XStoreColors (dpy, cmap, colors, ncolors);
+ }
+ else
+ {
+ for (i = 0; i < ncolors; i++)
+ {
+ XColor color;
+ color = colors[i];
+ if (!XAllocColor (dpy, cmap, &color))
+ break;
+ colors[i].pixel = color.pixel;
+ }
+ ncolors = i;
+ }
+
+ /* If we tried for writable cells and got none, try for non-writable. */
+ if (allocate_p && ncolors == 0 && writable_pP && *writable_pP)
+ {
+ ncolors = *ncolorsP;
+ *writable_pP = False;
+ goto RETRY_NON_WRITABLE;
+ }
+
+#if 0
+ /* I don't think we need to bother copying or linking to the complain
+ function. */
+ if (verbose_p)
+ complain(*ncolorsP, ncolors, wanted_writable,
+ wanted_writable && *writable_pP);
+#endif
+
+ *ncolorsP = ncolors;
+}
+
+static void
+mondrian_set_sizes (struct state *st, int w, int h)
+{
+ if (w > h) {
+ st->line_width = w/50;
+ st->min_height = st->min_width = w/8;
+ } else {
+ st->line_width = h/50;
+ st->min_height = st->min_width = h/8;
+ }
+}
+