Skip to content

Bmogul/Julia_set

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Julia Set Visualizer

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.

What is a Julia Set?

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:

  • z is a complex number representing a point in the complex plane (zx + zy*i)
  • c is 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

High-Level Structure

Class Architecture

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)

Core Components

  1. 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
  2. Fractal Parameters (JuliaSetProgram.java:10, 14)

    • a, b: Complex constant c = a + bi that defines the Julia set shape
    • zoom: Magnification level for exploring details
    • dx, dy: Pan offsets for navigating the fractal
    • maxIter: Maximum iterations before considering a point bounded
    • hueAdjust: Color palette rotation multiplier
    • pixels: Rendering resolution (1 for full quality, 5 for faster preview)
  3. Image Generation (JuliaSetProgram.java:121-150)

    • Creates a BufferedImage of 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

UI Layout

┌─────────────────────────────────────┐
│                                     │
│         Fractal Canvas              │
│         (1000 x 700)                │
│                                     │
├─────────────────────────────────────┤
│ A:      │ Scrollbars:              │ ZOOM:      │
│ B:      │ [aBar]    [zoomBar]      │ ITER:      │
│ DX:     │ [bBar]    [iBar]         │ HUE:       │
│ DY:     │ [adjX]    [hueBar]       │ PIXEL:     │
│         │ [adjY]    [pixelBtn]     │            │
└─────────────────────────────────────┘

Mathematical Theory

Complex Number Iteration

The core algorithm (JuliaSetProgram.java:134-140) implements the iteration:

  1. Map screen coordinates (x, y) to complex plane coordinates (zx, zy)
  2. Iterate: z = z² + c where:
    • Real part: zx_new = zx² - zy² + a
    • Imaginary part: zy_new = 2*zx*zy + b
  3. Check if |z|² = zx² + zy² < 6 (escape criterion)
  4. Count iterations until escape or max iterations reached

Coordinate Mapping

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) + dy

This 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

Coloring Algorithm

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

Interactive Controls

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

Key Features

  1. Real-time Rendering: Fractal regenerates on every parameter change
  2. Color Cycling: HSB color space creates smooth, psychedelic gradients
  3. Performance Mode: Pixelation toggle reduces resolution for faster exploration
  4. Zoom & Pan: Navigate and explore fractal details
  5. Default Preset: Initializes with interesting values (a=0, b=0)

Technical Notes

  • Language: Java (JDK 8+)
  • Framework: Swing for GUI, AWT for rendering
  • Image Type: BufferedImage with RGB color model
  • Rendering: Synchronous (blocks UI during generation)
  • Window Size: 1000x800 pixels (700 for canvas, 100 for controls)

Running the Program

javac JuliaSetProgram.java
java JuliaSetProgram

Interesting Parameter Sets

Try 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!

Code Highlights

  • Escape Radius: Uses < 6 instead of the typical < 4 for 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: JRadioButton mistakenly used instead of JToggleButton (though functionality works)

Written as a high school project exploring complex dynamics and fractal geometry through interactive visualization.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages