UNPKG

@prachwal/mandelbrot-generator

Version:

Professional Mandelbrot fractal generator with TypeScript support, interactive web interface, and multiple output formats

62 lines 2.17 kB
/** * @fileoverview Base abstract class for all fractal algorithms * @module BaseFractal */ /** * Abstract base class for all fractal algorithms * Provides common interface and functionality for fractal generation */ export class BaseFractal { /** * Generate fractal data for given configuration * @param config - Generation configuration * @returns Image data array */ generateData(config) { const { width, height } = config; const imageData = new Uint8ClampedArray(width * height * 4); const bounds = this.calculateBounds(config); for (let y = 0; y < height; y++) { for (let x = 0; x < width; x++) { const point = this.screenToComplex(x, y, bounds, config); const result = this.iterate(point, config); const color = this.getColor(result, config); const index = (y * width + x) * 4; imageData[index] = color[0]; // R imageData[index + 1] = color[1]; // G imageData[index + 2] = color[2]; // B imageData[index + 3] = 255; // A } } return imageData; } /** * Convert screen coordinates to complex plane */ screenToComplex(x, y, bounds, config) { const real = bounds.minX + (x / config.width) * (bounds.maxX - bounds.minX); const imag = bounds.minY + (y / config.height) * (bounds.maxY - bounds.minY); return { real, imag }; } /** * Calculate bounds of complex plane for given config */ calculateBounds(config) { const { centerX, centerY, zoom, width, height } = config; const aspectRatio = width / height; const range = 4 / zoom; return { minX: centerX - range * aspectRatio / 2, maxX: centerX + range * aspectRatio / 2, minY: centerY - range / 2, maxY: centerY + range / 2 }; } /** * Validate configuration for this fractal type */ validateConfig(_config) { return true; // Override in subclasses if needed } } //# sourceMappingURL=base-fractal.js.map