summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTanner Robison <[email protected]>2026-08-24 16:24:31 -0700
committerTanner Robison <[email protected]>2026-08-24 16:24:31 -0700
commit831468eeddf99937514e30beaba560d00044baa8 (patch)
tree7c693adcadbdd8820bc3c8fcf5adb65d6c85e398
parentd84c42d5df0fb2dc8cd213f3f251e413345b22d6 (diff)
added color
-rwxr-xr-xmandelbrot_setbin16704 -> 16848 bytes
-rw-r--r--mandelbrot_set.c28
2 files changed, 28 insertions, 0 deletions
diff --git a/mandelbrot_set b/mandelbrot_set
index f802f7e..444b3e7 100755
--- a/mandelbrot_set
+++ b/mandelbrot_set
Binary files differ
diff --git a/mandelbrot_set.c b/mandelbrot_set.c
index 4420372..32c38bc 100644
--- a/mandelbrot_set.c
+++ b/mandelbrot_set.c
@@ -58,6 +58,16 @@ int main(void)
return -1;
}
+ if (has_colors()) {
+ start_color();
+ use_default_colors(); // keeps terminal background color
+
+ // gradient pairs
+ init_pair(1, COLOR_BLUE, COLOR_BLACK);
+ init_pair(2, COLOR_CYAN, COLOR_BLACK);
+ init_pair(3, COLOR_WHITE, COLOR_BLACK);
+ }
+
cbreak();
noecho();
keypad(stdscr, true);
@@ -223,7 +233,25 @@ static void draw_mandelbrot(const struct viewer *viewer)
char pixel = iteration_character(
iteration, viewer->max_iterations);
+ int color_pair = 0;
+ if (iteration < viewer->max_iterations) {
+ // Group iterations into bands of 8 for a smooth
+ // ripple effect
+ int band = (iteration / 8) % 3;
+ if (band == 0)
+ color_pair = 1; // Deep Blue
+ else if (band == 1)
+ color_pair = 2; // Bright Cyan
+ else
+ color_pair = 3; // White highlight
+ }
+
+ // Apply color, draw pixel, remove color
+ if (color_pair > 0)
+ attron(COLOR_PAIR(color_pair));
mvaddch(screen_y, screen_x, pixel);
+ if (color_pair > 0)
+ attroff(COLOR_PAIR(color_pair));
}
}