Giter Site home page Giter Site logo

snowy-the-arctic-fox / fractal-generator Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 188 KB

Uses the Julia Fractal Sets

License: GNU General Public License v3.0

Jupyter Notebook 100.00%
fractal python computer-graphics data-visualization matpotlib numbers numerical-analysis visualization workflow fractal-generation

fractal-generator's Introduction

Julia Fractal Generator


The Julia set fractal is a fascinating mathematical construct that exhibits intricate and infinitely complex patterns. It is generated by iteratively applying a simple mathematical formula to complex numbers. The resulting fractal image reveals mesmerizing visual structures and delicate details.

The code begins by installing the necessary libraries, namely numpy and matplotlib. These libraries provide powerful tools for numerical computations and visualizations, respectively. By installing them, we ensure that the code can utilize their functionalities.

Next, the code defines the function generate_julia, which is responsible for generating the Julia set fractal. This function takes several parameters: width and height determine the dimensions of the resulting fractal image, max_iter specifies the maximum number of iterations for the fractal generation process, and c represents a complex constant that influences the shape and characteristics of the Julia set.

Within the generate_julia function, a grid of complex numbers is created using numpy. The grid is constructed by defining ranges for the real and imaginary parts of the complex plane. Each point on this grid corresponds to a unique complex number.

The function then initializes an array called fractal to store the iteration count for each complex number. Additionally, it creates another array, z, which is a copy of the grid of complex numbers. The z array will be manipulated during the fractal generation process.

A loop is executed for a maximum of max_iter times. In each iteration, a mask is generated by checking whether the absolute value of each complex number in z is less than 2. This mask identifies the points that have not diverged beyond a certain threshold.

The complex numbers in z that satisfy the mask are then updated using the Julia set formula: z = z**2 + c. This formula iteratively applies a quadratic function to each complex number, incorporating the constant c to determine the behavior of the fractal. The values that have already diverged beyond the threshold are not modified in subsequent iterations.

The fractal array is incremented using the mask, accumulating the number of iterations taken for each point to diverge or reach the maximum iteration limit. This accumulation produces a numerical representation of the fractal pattern.

Moving to the next cell, the code imports the matplotlib.pyplot module as plt. This module provides a collection of functions for creating visualizations.

Following that, the code sets the dimensions of the fractal image to a fixed size of 640x480 pixels. This fixed size allows for consistent and easily reproducible fractal images.

The max_iter parameter determines the maximum number of iterations to be performed during fractal generation. Adjusting this value can result in different levels of detail and intricacy in the fractal pattern.

Next, a complex constant c is defined. This constant influences the shape and characteristics of the Julia set fractal. Modifying the value of c can yield diverse and unique fractal shapes.

The code then calls the generate_julia function with the provided parameters, resulting in the generation of the Julia set fractal.

Finally, the generated fractal is displayed using the imshow function from matplotlib.pyplot. The imshow function visualizes the fractal array as an image, with colors representing the iteration count at each point. The cmap='hot' parameter sets the color map to a scheme that ranges from hot (red) to cold (black) colors, enhancing the visual contrast of the fractal. The extent parameter sets the range of the x and y axes based on the minimum and maximum values defined earlier. The remaining lines of code set the title, labels, and color bar for the plot. The title function sets the title of the plot to "Julia Set Fractal", providing a descriptive heading for the generated image. The xlabel and ylabel functions set the labels for the x-axis and y-axis, respectively, indicating the real and imaginary parts of the complex plane. The colorbar function adds a color bar to the plot, which provides a visual representation of the iteration counts corresponding to the colors in the fractal image.

Once all the plot settings are defined, the show function is called to display the fractal image plot. Running the code will generate a Julia set fractal with the specified parameters and display it in the output.

By adjusting the parameters such as width, height, max_iter, and c, you can explore a wide range of Julia set fractals. Each unique combination of parameters will produce a distinct fractal pattern, revealing the infinite complexity and beauty of fractal mathematics.

Feel free to experiment with different parameter values and observe the diverse and captivating patterns that emerge from the Julia set fractal generator.


Example

image_2023-05-10_191938970.png

fractal-generator's People

Contributors

snowy-the-arctic-fox avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.