Change language

# Julia Fractal in Python

Equation for generating Julia’s fractal:

where c — complex parameter. Julia’s set for this system is a subset of the complex plane, defined as:

So, let’s now try to create one of the fractals in the image above.

For this we need the Python module Pillow, which makes it easier to work with images and so on.

To install a pillow via pip, enter the following command at the command line.

` pip install Pillow `

Now use this library to create a fractal image.

Output:

After understanding the code, try drawing other fractals by changing the value of the variables and post your link to github in the code in the comments section and I’ll be happy to help you if any error occurs.

This article is courtesy of Subhajit Saha . If you are as Python.Engineering and would like to contribute, you can also write an article using contribute.python.engineering or by posting an article contribute @ python.engineering. See my article appearing on the Python.Engineering homepage and help other geeks.

## Shop

Learn programming in R: courses

\$

Best Python online courses for 2022

\$

Best laptop for Fortnite

\$

Best laptop for Excel

\$

Best laptop for Solidworks

\$

Best laptop for Roblox

\$

Best computer for crypto mining

\$

Best laptop for Sims 4

\$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

NUMPYNUMPY

How to convert Nonetype to int or string?

NUMPYNUMPY

How to specify multiple return types using type-hints

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

## Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method

 ` # Python code for Julia Fractal ` ` from ` ` PIL ` ` import ` ` Image `   ` # dra function ivera ` ` if ` ` __ name__ ` ` = ` ` = ` ` "__ main__" ` `: `   ` # adjust width, height and scale ` ` # image to be generated ` ` w, h, zoom ` ` = ` ` 1920 ` `, ` ` 1080 ` `, ` ` 1 `   ` # create a new RGB image ` ` ` ` bitmap ` ` = ` ` Image.new (` ` "RGB" ` `, (w, h), ` `" white "` `) `   ` # Allocate storage for the image and ` ` # load pixel data. ` ` pix ` ` = ` ` bitmap.load () `   ` # installation variables according to ` ` # equation for creating a fractal ` ` cX, cY ` ` = ` ` - ` ` 0.7 ` `, ` ` 0.27015 ` ` moveX, moveY ` ` = ` ` 0.0 ` `, ` ` 0.0 ` ` maxIter ` ` = ` ` 255 `   ` for ` ` x ` ` in ` ` range ` ` (w ): ` ` for ` ` y ` ` in ` ` range ` ` (h): ` ` zx ` ` = ` ` 1.5 ` ` * ` ` (x ` ` - ` ` w ` ` / ` ` 2 ` `) ` ` / ` ` (` ` 0.5 ` ` * ` ` zoom ` ` * ` ` w) ` ` + ` ` moveX ` ` zy ` ` = ` ` 1.0 ` ` * ` ` (y ` ` - ` ` h ` ` / ` ` 2 ` `) ` ` / ` ` (` ` 0.5 ` ` * ` ` zoom ` ` * ` ` h) ` ` + ` ` moveY ` ` i ` ` = ` ` maxIter ` ` ` ` while ` ` zx ` ` * ` ` zx ` ` + ` ` zy ` ` * ` ` zy & lt; ` ` 4 ` ` and ` ` i" ` ` 1 ` `: ` ` tmp ` ` = ` ` zx ` ` * ` ` zx ` ` - ` ` zy ` ` * ` ` zy ` ` + ` ` cX ` ` zy, zx ` ` = ` ` 2.0 ` ` * ` ` zx ` ` * ` ` zy ` ` + ` ` cY, tmp ` ` i ` ` - ` ` = ` ` 1 `   ` ` ` # convert byte to RGB (3 bytes) like ` ` ` ` # magic to get nice colors ` ` pix [ x, y] ` ` = ` ` (i "& lt; ` ` 21 ` `) ` ` + ` ` (i ""` ` 10 ` `) ` ` + ` ` i ` ` * ` ` 8 `   ` # to display the created fractal ` ` bitmap.show () `