Example: Julia set

Published 2014-03-28 | Authors: Christian Feuersänger, Stefan Kottwitz

This is a picture of a Julia set, named after the French mathematician Gaston Julia. Computing requires a lot of iterations, that’s why we use Lua. The function for the set is z -> z^2 - 0.742 + 0.1i.

The example is very similar to the Mandelbrot example . One small difference is that we use a different color map.

Again, the sampling is done via \addplot3. surf and shader=interp do the coloring. Run with LuaLaTeX and have a coffee.

It was posted on: Fraktale mit pgfplots

Download as: [PDF] [TEX]  •  [Open in Overleaf]

Julia set

Do you have a question regarding this example, TikZ or LaTeX in general? Just ask in the LaTeX Forum.
Oder frag auf Deutsch auf TeXwelt.de.

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.8}
\usepackage{luacode}
\begin{luacode}
  function julia(cx,cy, max_iter, max)
    local x,y,xtemp,ytemp,squaresum,iter
    squaresum = 0
    x = cx
    y = cy
    iter = 0
    while (squaresum <= max) and (iter < max_iter)  do
      xtemp = x * x - y * y - 0.742
      ytemp = 2 * x * y + 0.1
      x = xtemp
      y = ytemp
      iter = iter + 1
      squaresum = x * x + y * y
    end
    local result = 0
    if (iter < max_iter) then
        result = iter
    end
    -- result = squaresum
    -- io.write("" .. cx .. ", " .. cy .. " = " .. result .. " (iter " .. iter .. " squaresum " .. squaresum .. ") \string\n")
    tex.print(result);
  end
\end{luacode}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    colormap/hot2,
    colorbar,
    axis equal,
    point meta max=50,
    tick label style={font=\tiny},
    view={0}{90}]
    \addplot3 [surf, domain = -1.82:1.82, shader = interp,
      domain y = -1.5:1.5, samples = 350] 
      {\directlua{julia(\pgfmathfloatvalueof\x,\pgfmathfloatvalueof\y,10000,4)}
    };
  \end{axis}
\end{tikzpicture}
\end{document}

Comments

Adding comments is currently not enabled.

There are currently 0 comments on this entry.

Features
Tags
Scientific and technical areas
Other areas

Creative Commons License