GithubHelp home page GithubHelp logo

jabolol / julia Goto Github PK

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

A script to generate Julia set image representations effortlessly

License: MIT License

Haskell 100.00%
fractals haskell julia-set

julia's Introduction

Julia set

The Julia set is a fractal defined by the following equation:

$$z_{n+1} = z_n^2 + c$$

where $z$ and $c$ are complex numbers. The Julia set is the set of all complex numbers $z$ for which the sequence $z_n$ does not diverge to infinity. It is named after the French mathematician Gaston Julia who studied the set in the early 20th century.

The Julia set is usually visualized by coloring the complex plane. Each pixel in the image corresponds to a complex number $z$. The color of the pixel is determined by the number of iterations it takes for the sequence $z_n$ to diverge to infinity. If the sequence does not diverge to infinity, the pixel is colored black.

The Julia set is a fractal because it is self-similar. If you zoom in on any part of the image, you will see the same pattern repeating itself.

How is it calculated?

The calcJulia function calculates the number of iterations it takes for the sequence $z_n$ to diverge to infinity. If the sequence does not diverge to infinity, the function returns $0$.

calcJulia :: Complex Double -> Int
calcJulia z0 = iterateJulia z0 0
  where
    iterateJulia z n
      | n == maxIterations || magnitude z > 2.0 = n
      | otherwise = iterateJulia (z * z + c) (n + 1)

The steps of the calculation are as follows:

  1. Start with a complex number $z_0$.
  2. Calculate the next value of the sequence $z_n$ using the $f$ function.
  3. Repeat step 2 until the sequence diverges to infinity or the maximum number of iterations is reached.

The iterateJulia function uses the f function to calculate the next value of the sequence $z_n$. The $f$ function takes one parameter: the current value of the sequence $z_n$. The function returns the next value of the sequence $z_n$.

The $f$ function is defined as follows:

$$f(z) = z^2 + c$$

The $c$ parameter is a complex number. The $c$ parameter is the same for all pixels in the image. Modify this parameter to get different images. It is defined as follows.

$$c = -0.8 + 0.156i$$

How to run

  1. Install Haskell.
  2. Install the dependencies: cabal install --only-dependencies.
  3. Compile the program: cabal build.
  4. Run the program: cabal run.
  5. Open the julia_set.png file to see the result.

julia's People

Contributors

jabolol 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.