Skip to content

okaragoz/fractal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mandelbrot Set Visualization

This project provides tools to visualize and explore the Mandelbrot set, allowing users to generate static images, zoom animations, and interact with the set through a Jupyter Notebook interface.

Installation

To run this project, you need to install the required Python libraries. You can install them using the following pip command:

pip install ipywidgets matplotlib numpy imageio imageio-ffmpeg tqdm

Getting Started

After installing the required libraries, you can start by importing them in your Jupyter Notebook:

import ipywidgets as widgets
from IPython.display import display, clear_output
import matplotlib.pyplot as plt
import numpy as np
import os
import imageio.v2 as imageio
from IPython.display import Video
from concurrent.futures import ThreadPoolExecutor
import time
from tqdm import tqdm
from PIL import Image
from IPython.display import HTML

Defining the Mandelbrot Set

The MandelbrotSet class is defined to handle the calculation and visualization of the Mandelbrot set:

class MandelbrotSet:
    def __init__(self, max_iterations: int, escape_radius: float = 2.0):
        ...
    def __contains__(self, c: complex) -> bool:
        ...
    def stability(self, c: complex, smooth=False, clamp=True) -> float:
        ...
    def escape_count(self, c: complex, smooth=False) -> float:
        ...

Generating Static Images

To generate a static image of the Mandelbrot set, you can use the plot_mandelbrot function:

def plot_mandelbrot(max_iterations, escape_radius, smooth, width=800, height=600, x_center=-0.5, y_center=0, zoom=1):
    ...

Interactive Exploration

Interactive widgets are provided for real-time exploration of the Mandelbrot set:

max_iterations_slider = widgets.IntSlider(...)
escape_radius_slider = widgets.FloatSlider(...)
smooth_checkbox = widgets.Checkbox(...)
plot_button = widgets.Button(...)
output_widget = widgets.Output()

def on_plot_button_clicked(b):
    ...

plot_button.on_click(on_plot_button_clicked)
widgets.VBox([...])

Creating Zoom Animations

The plot_zoomed_mandelbrot function allows you to create a series of frames zooming into a specific point of the Mandelbrot set:

def plot_zoomed_mandelbrot(center, zoom, frame_number, base_iterations=100):
    ...

Compiling Frames into a Video

Frames generated by plot_zoomed_mandelbrot can be compiled into a video file:

video_file = 'mandelbrot_zoom.mp4'
writer = imageio.get_writer(video_file, fps=frames / 10)

...

writer.close()

Displaying the Video in the Notebook

To display the generated video within the Jupyter Notebook:

# Set desired display dimensions
display_width = 800  # Adjust width as needed
display_height = 600  # Adjust height as needed, maintain aspect ratio

# Embed video with custom size
HTML(f"""
<video width="{display_width}" height="{display_height}" controls>
  <source src="{video_file}" type="video/mp4">
</video>
""")

Output Directory

Ensure the output directory exists for storing generated frames:

output_dir = 'viu_zoom'
os.makedirs(output_dir, exist_ok=True)

This README provides a quick overview and starting points for using the provided scripts and tools for Mandelbrot set visualization. For detailed explanations and more advanced usage, refer to the inline comments within the scripts.

About

Simple fractal project with Mandelbrot Set

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published