- Display *display = MI_DISPLAY(mi);
- Window window = MI_WINDOW(mi);
- GC gc = MI_GC(mi);
- short x_1, y_1, x_2, y_2;
- float a1, a2;
-
- /* left */
-
- a1 = a + as + DEGTORAD(NRAND(2 * RANDANGLE) - RANDANGLE);
-
- x_1 = x + (short) (COSF(a1) * ((float) len));
- y_1 = y + (short) (SINF(a1) * ((float) len));
-
- /* right */
-
- a2 = a - as + DEGTORAD(NRAND(2 * RANDANGLE) - RANDANGLE);
-
- x_2 = x + (short) (COSF(a2) * ((float) len));
- y_2 = y + (short) (SINF(a2) * ((float) len));
-
- if (MI_NPIXELS(mi) > 2) {
- XSetForeground(display, gc, MI_PIXEL(mi, c));
- c = (c + COLORSPEED) % MI_NPIXELS(mi);
- } else
- XSetForeground(display, gc, MI_WIN_WHITE_PIXEL(mi));
-
- XDrawLine(display, window, gc, x, y, x_1, y_1);
- XDrawLine(display, window, gc, x, y, x_2, y_2);
-
- if (level < 2) {
- XDrawLine(display, window, gc, x + 1, y, x_1 + 1, y_1);
- XDrawLine(display, window, gc, x + 1, y, x_2 + 1, y_2);
- }
- len = (len * REDUCE * 10) / 1000;
-
- if (level < ITERLEVEL) {
- draw_tree(mi, x_1, y_1, len, a1, as, c, level + 1);
- draw_tree(mi, x_2, y_2, len, a2, as, c, level + 1);
- }
+ unsigned long pixels[20];
+ treestruct *tree;
+ Display *display = MI_DISPLAY(mi);
+ GC gc = MI_GC(mi);
+ int i;
+
+ if (trees == NULL) {
+ trees = (treestruct *) calloc(MI_NUM_SCREENS(mi), sizeof (treestruct));
+ if (trees == NULL) {
+ return;
+ }
+
+ if (mi->npixels > 20) {
+ printf("%d colors selected. Setting limit to 20...\n", mi->npixels);
+ mi->npixels = 20;
+ }
+
+ if (mi->npixels < 4) {
+ for (i = 0; i < mi->npixels; i++) {
+ colors[i].red = 65535 * (i & 1);
+ colors[i].green = 65535 * (i & 1);
+ colors[i].blue = 65535 * (i & 1);
+ colors[i].flags = DoRed | DoGreen | DoBlue;
+ }
+ } else {
+ if (mi->npixels < 8) {
+ for (i = 0; i < mi->npixels; i++) {
+ colors[i].red = 32768 + 4096 * (i % 4);
+ colors[i].green = 32768 + 4096 * (i % 4);
+ colors[i].blue = 32768 + 4096 * (i % 4);
+ colors[i].flags = DoRed | DoGreen | DoBlue;
+ }
+ } else {
+ for (i = 0; i < mi->npixels; i++) {
+ colors[i].red = 24576 + 4096 * (i % 4);
+ colors[i].green = 10240 + 2048 * (i % 4);
+ colors[i].blue = 0;
+ colors[i].flags = DoRed | DoGreen | DoBlue;
+ }
+ }
+ }
+
+ for (i = 0; i < mi->npixels; i++)
+ if (!XAllocColor(display, mi->xgwa.colormap, &colors[i])) break;
+ color = i;
+
+ XSetForeground(display, gc, colors[1].pixel);
+ }
+
+ XClearWindow(display, MI_WINDOW(mi));
+ XSetLineAttributes(display, gc, 2, LineSolid, CapButt, JoinMiter);
+ tree = &trees[MI_SCREEN(mi)];
+ tree->toDo = 25;
+ tree->season = NRAND(12);
+
+ for (i = 4; i < mi->npixels; i++) {
+ int sIndex = (tree->season + (i-4) / 4) % 12;
+ long color = colorM[sIndex] - 2 * colorV[sIndex] * (i % 4);
+ colors[i].red = (color & 0xff0000) / 256;
+ colors[i].green = (color & 0x00ff00);
+ colors[i].blue = (color & 0x0000ff) * 256;
+ colors[i].flags = DoRed | DoGreen | DoBlue;
+ }
+
+ for (i = 0; i < color; i++)
+ pixels[i] = colors[i].pixel;
+
+ XFreeColors(display, mi->xgwa.colormap, pixels, mi->npixels, 0L);
+
+ for (i = 0; i < mi->npixels; i++)
+ if (!XAllocColor(display, mi->xgwa.colormap, &colors[i])) break;
+
+ color = i;