@prachwal/mandelbrot-generator
Version:
Professional Mandelbrot fractal generator with TypeScript support, interactive web interface, and multiple output formats
177 lines • 6.63 kB
TypeScript
/**
* @fileoverview Color palette generation and management for Mandelbrot fractal visualization
* @module colors
* @version 1.0.0
* @author Prachwal
* @since 1.0.0
*
* This module provides sophisticated color palette systems for visualizing Mandelbrot fractals.
* It includes multiple predefined palettes, color interpolation algorithms, and utilities
* for mapping iteration counts to visually appealing colors.
*
* @example
* ```typescript
* import { getColor, COLOR_PALETTES } from './colors.js';
*
* // Get color for a specific iteration count
* const [r, g, b] = getColor(50, 100, 'classic');
*
* // Use different palettes
* const hotColor = getColor(75, 200, 'hot');
* const coolColor = getColor(75, 200, 'cool');
*
* // Access palette data directly
* const classicPalette = COLOR_PALETTES.classic;
* ```
*/
import type { RGBColor, PaletteType, ColorPalettes } from './types.js';
/**
* Collection of predefined color palettes optimized for Mandelbrot fractal visualization
*
* Each palette is carefully crafted to highlight different aspects of the fractal structure:
* - **rainbow**: Classic multi-color palette showing intricate details
* - **fire**: Warm palette emphasizing heat-like patterns
* - **cool**: Cool blues and greens for serene visualization
* - **classic**: Traditional black-to-white gradient
* - **hot**: Intense reds, oranges, and yellows
* - **electric**: High-contrast neon colors
* - **ocean**: Deep blues with white highlights
* - **sunset**: Warm oranges, pinks, and purples
*
* @example
* ```typescript
* import { colorPalettes } from './colors.js';
*
* // Access specific palettes
* const rainbowColors = colorPalettes.rainbow;
* const fireColors = colorPalettes.fire;
*
* // Use in configuration
* const config = {
* // ...other settings
* colorPalette: 'fire' as const
* };
*
* // Iterate through all available palettes
* Object.keys(colorPalettes).forEach(paletteName => {
* console.log(`${paletteName}: ${colorPalettes[paletteName].length} colors`);
* });
* ```
*
* @see {@link PaletteType} for available palette names
* @see {@link getColor} for using palettes in fractal generation
* @since 1.0.0
*/
export declare const colorPalettes: ColorPalettes;
/**
* Maps iteration count to RGB color using the specified palette
*
* This is the primary function for converting Mandelbrot iteration results into
* visual colors. It handles both set membership (black) and iteration-based coloring
* with smooth palette transitions.
*
* @param iterations - Number of iterations before the point escaped (0 to maxIterations)
* @param maxIterations - Maximum iterations used in the fractal calculation
* @param paletteType - Name of the color palette to use (default: 'rainbow')
* @returns RGB color as [red, green, blue] array with values 0-255
*
* @example
* ```typescript
* import { getColor } from './colors.js';
*
* // Points in the set are black
* const setColor = getColor(1000, 1000, 'rainbow'); // [0, 0, 0]
*
* // Points outside get colored by iteration count
* const escapeColor = getColor(50, 1000, 'fire'); // Warm color
* const quickEscape = getColor(5, 1000, 'cool'); // Cool color
*
* // Different palettes for same iteration
* const rainbow = getColor(100, 500, 'rainbow');
* const fire = getColor(100, 500, 'fire');
* const ocean = getColor(100, 500, 'ocean');
* ```
*
* @algorithm
* 1. If iterations >= maxIterations, return black (point in set)
* 2. Calculate normalized position in palette (0.0 to 1.0)
* 3. Map to palette index and return corresponding color
* 4. Handle edge cases and palette boundaries
*
* @performance O(1) - constant time color lookup
* @see {@link colorPalettes} for available palette options
* @see {@link getColorHex} for hexadecimal color output
* @since 1.0.0
*/
export declare function getColor(iterations: number, maxIterations: number, paletteType?: PaletteType): RGBColor;
/**
* Converts RGB color values to hexadecimal color string format
*
* This utility function transforms individual red, green, and blue components
* into a standard web-compatible hex color string for use in CSS, HTML,
* or other systems that expect hex color notation.
*
* @param r - Red component value (0-255)
* @param g - Green component value (0-255)
* @param b - Blue component value (0-255)
* @returns Hexadecimal color string in format "#RRGGBB"
*
* @example
* ```typescript
* import { rgbToHex } from './colors.js';
*
* // Convert primary colors
* const red = rgbToHex(255, 0, 0); // "#ff0000"
* const green = rgbToHex(0, 255, 0); // "#00ff00"
* const blue = rgbToHex(0, 0, 255); // "#0000ff"
*
* // Convert custom colors
* const purple = rgbToHex(128, 0, 128); // "#800080"
* const orange = rgbToHex(255, 165, 0); // "#ffa500"
*
* // Use in web contexts
* element.style.backgroundColor = rgbToHex(200, 150, 100);
* ```
*
* @algorithm Uses bit shifting for efficient hex conversion
* @complexity O(1) - constant time operation
* @see {@link getColorHex} for direct fractal iteration to hex conversion
* @since 1.0.0
*/
export declare function rgbToHex(r: number, g: number, b: number): string;
/**
* Maps iteration count directly to hexadecimal color string
*
* Convenience function that combines getColor() and rgbToHex() for direct
* conversion from Mandelbrot iteration results to web-compatible hex colors.
* Ideal for web applications, CSS generation, and HTML canvas operations.
*
* @param iterations - Number of iterations before the point escaped
* @param maxIterations - Maximum iterations used in fractal calculation
* @param paletteType - Name of the color palette to use (default: 'rainbow')
* @returns Hexadecimal color string in format "#RRGGBB"
*
* @example
* ```typescript
* import { getColorHex } from './colors.js';
*
* // Get hex colors for fractal points
* const setColor = getColorHex(1000, 1000, 'fire'); // "#000000" (black)
* const escapeColor = getColorHex(50, 200, 'ocean'); // "#1e3f5c" (blue)
*
* // Use directly in web contexts
* canvas.style.backgroundColor = getColorHex(75, 100, 'sunset');
*
* // Generate CSS color arrays
* const cssColors = Array.from({length: 10}, (_, i) =>
* getColorHex(i * 10, 100, 'rainbow')
* );
* ```
*
* @complexity O(1) - constant time operation
* @see {@link getColor} for RGB color output
* @see {@link rgbToHex} for RGB to hex conversion details
* @since 1.0.0
*/
export declare function getColorHex(iterations: number, maxIterations: number, paletteType?: PaletteType): string;
//# sourceMappingURL=colors.d.ts.map