diff options
| author | Tanner Robison <[email protected]> | 2026-08-24 16:24:31 -0700 |
|---|---|---|
| committer | Tanner Robison <[email protected]> | 2026-08-24 16:24:31 -0700 |
| commit | 831468eeddf99937514e30beaba560d00044baa8 (patch) | |
| tree | 7c693adcadbdd8820bc3c8fcf5adb65d6c85e398 /mandelbrot_set.c | |
| parent | d84c42d5df0fb2dc8cd213f3f251e413345b22d6 (diff) | |
added color
Diffstat (limited to 'mandelbrot_set.c')
| -rw-r--r-- | mandelbrot_set.c | 28 |
1 files changed, 28 insertions, 0 deletions
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)); } } |
