A Java Swing-based interactive fractal visualizer created in 2020 during senior year of high school. This program generates and renders Julia sets in real-time with user-adjustable parameters.
A Julia set is a fractal created by iterating a complex function. For each point in the complex plane, the function is applied repeatedly, and the point is colored based on whether it "escapes" to infinity or remains bounded. The Julia set consists of the boundary between points that escape and those that don't.
This implementation uses the iteration formula:
z(n+1) = z(n)² + c
Where:
zis a complex number representing a point in the complex plane (zx + zy*i)cis a complex constant (a + b*i) that determines the shape of the Julia set- The iteration continues until either the magnitude exceeds a threshold or max iterations is reached
The program is built as a single class JuliaSetProgram that extends JPanel and implements two listener interfaces:
JuliaSetProgram
├── extends JPanel (for custom rendering)
├── implements AdjustmentListener (for scrollbar controls)
└── implements ActionListener (for toggle button)
-
GUI Components (JuliaSetProgram.java:8-17)
- Main frame and panels for layout
- Seven scrollbars for parameter control
- Toggle button for pixelation mode
- Eight labels for displaying current values
-
Fractal Parameters (JuliaSetProgram.java:10, 14)
a, b: Complex constant c = a + bi that defines the Julia set shapezoom: Magnification level for exploring detailsdx, dy: Pan offsets for navigating the fractalmaxIter: Maximum iterations before considering a point boundedhueAdjust: Color palette rotation multiplierpixels: Rendering resolution (1 for full quality, 5 for faster preview)
-
Image Generation (JuliaSetProgram.java:121-150)
- Creates a
BufferedImageof the fractal - Iterates through each pixel and maps it to the complex plane
- Applies the Julia set iteration formula
- Colors pixels using HSB color space based on escape time
- Creates a
┌─────────────────────────────────────┐
│ │
│ Fractal Canvas │
│ (1000 x 700) │
│ │
├─────────────────────────────────────┤
│ A: │ Scrollbars: │ ZOOM: │
│ B: │ [aBar] [zoomBar] │ ITER: │
│ DX: │ [bBar] [iBar] │ HUE: │
│ DY: │ [adjX] [hueBar] │ PIXEL: │
│ │ [adjY] [pixelBtn] │ │
└─────────────────────────────────────┘
The core algorithm (JuliaSetProgram.java:134-140) implements the iteration:
- Map screen coordinates (x, y) to complex plane coordinates (zx, zy)
- Iterate:
z = z² + cwhere:- Real part:
zx_new = zx² - zy² + a - Imaginary part:
zy_new = 2*zx*zy + b
- Real part:
- Check if
|z|² = zx² + zy² < 6(escape criterion) - Count iterations until escape or max iterations reached
The screen-to-complex-plane transformation (JuliaSetProgram.java:130-131):
zx = 1.5 * (x - w/2) / (0.5 * zoom * w) + dx
zy = (y - h/2) / (0.5 * zoom * h) + dyThis formula:
- Centers the origin at the screen center
- Applies zoom scaling
- Adds pan offsets (dx, dy)
- Uses 1.5 aspect ratio multiplier for the real axis
Colors are assigned based on escape time (JuliaSetProgram.java:142-146):
-
Escaped points: HSB color where hue varies with iteration count
hue = hueAdjust * (maxIter / i) % 1- Creates smooth color gradients
-
Bounded points: Black (part of the actual Julia set)
- When
i == 0, the point never escaped
- When
| Control | Range | Function |
|---|---|---|
| A Slider | -3.0 to 3.0 | Real part of complex constant |
| B Slider | -3.0 to 3.0 | Imaginary part of complex constant |
| Zoom | 0 to ~2.0 | Magnification level |
| Iterations | 1 to 1000 | Detail level (higher = more accurate) |
| X/Y Adjust | -0.5 to 0.5 | Pan position horizontally/vertically |
| Hue Adjust | 0 to 1.0 | Rotate color palette |
| Pixelation | Toggle | 5x5 pixel blocks for faster preview |
- Real-time Rendering: Fractal regenerates on every parameter change
- Color Cycling: HSB color space creates smooth, psychedelic gradients
- Performance Mode: Pixelation toggle reduces resolution for faster exploration
- Zoom & Pan: Navigate and explore fractal details
- Default Preset: Initializes with interesting values (a=0, b=0)
- Language: Java (JDK 8+)
- Framework: Swing for GUI, AWT for rendering
- Image Type:
BufferedImagewith RGB color model - Rendering: Synchronous (blocks UI during generation)
- Window Size: 1000x800 pixels (700 for canvas, 100 for controls)
javac JuliaSetProgram.java
java JuliaSetProgramTry these values for compelling fractals:
- Default:
a=0, b=0- Classic dendrite fractal - Commented Original:
a=-0.7, b=0.27015- Douady's rabbit fractal - Dragon:
a=-0.8, b=0.156 - Siegel Disk:
a=-0.391, b=-0.587
Experiment with the sliders to discover unique patterns!
- Escape Radius: Uses
< 6instead of the typical< 4for wider boundary detection - Zoom Math: The zoom calculation at JuliaSetProgram.java:167 uses
(0.99/49)to map scrollbar range to useful zoom values - Label Precision: Values rounded to 3 decimal places for display clarity (JuliaSetProgram.java:197-201)
- Comment at Line 56:
JRadioButtonmistakenly used instead ofJToggleButton(though functionality works)
Written as a high school project exploring complex dynamics and fractal geometry through interactive visualization.