- int x;
- int y;
- int thick;
- double size;
- long color;
- int toDo;
- int season;
-} treestruct;
-
-static treestruct *trees = NULL;
-
-XColor colors[20];
-int color;
-
-static long colorM[12] = {0xff0000, 0xff8000, 0xffff00, 0x80ff00,
- 0x00ff00, 0x00ff80, 0x00ffff, 0x0080ff,
- 0x0000ff, 0x8000ff, 0xff00ff, 0xff0080};
-
-static long colorV[12] = {0x0a0000, 0x0a0500, 0x0a0a00, 0x050a00,
- 0x000a00, 0x000a05, 0x000a0a, 0x00050a,
- 0x00000a, 0x05000a, 0x0a000a, 0x0a0005};
-
-void init_trees(ModeInfo * mi) {
- 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;
+ int width;
+ int height;
+ int time; /* up time */
+ int ntrees;
+} foreststruct;
+
+static foreststruct *forests = (foreststruct *) NULL;
+
+static void
+draw_tree(ModeInfo * mi,
+ short int x, short int y, short int len,
+ float a, float as, short int c, short int level)
+ /* Father's end */
+ /* Length */
+ /* color */
+ /* Height level */
+ /* Father's angle */
+ /* Father's angle step */
+{
+ 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_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);
+ }