Star-shaped implicit contour plot

I saw tomoq’s star-shaped plot on X (Twitter), together with a pretty big implicit function definition:

Star shaped plot with function equation

How to plot this?

An easy way is to consider the left side as a function z=f(x,y) in three dimensions, and that equation would be a contour line at height z=1. So, let’s plot it together with contour lines at different heights, to see how they run.

Run the files with -enable-write18 or –shell-escape or similar option enabled, because contour plots run the external gnuplot program in the background. The won’t run withe the online compiler TeXlive.net here, for security reasons.

% !TEX lualatex
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}[
  declare function = {
    f(\x,\y) = x^6 + y^6 + 3*x^4*y^2 + 3*x^2*y^4
                   - 5*x^4*y + 10*x^2*y^3 - y^5; } ]
  \begin{axis}[
     axis lines = middle,
     domain     = -2:2,
     samples    = 80,
     samples y  = 80,
     enlargelimits ]
   \addplot3 [
     contour lua =
       { levels = {0.001, 0.1, 1, 4, 8, 16, 32},
         labels = false} ]
     { f(x,y) };
   \addplot3 [surf,
     thick,  colormap/violet,
     opacity = 0.2 ]
     { f(x,y) };
  \end{axis}
\end{tikzpicture}
\end{document}

3D plot with contour lines

To get the final two-dimensional plot, we can choose a viewing angle from above, and plot only the contour line at height level 1.

% !TEX lualatex
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}[
  declare function = {
    f(\x,\y) = x^6 + y^6 + 3*x^4*y^2 + 3*x^2*y^4
                   - 5*x^4*y + 10*x^2*y^3 - y^5; } ]
  \begin{axis}[
     axis lines = middle,
     domain     = -2:2,
     samples    = 80,
     samples y  = 80,
     enlargelimits,
     view = {0}{90} ]
   \addplot3 [
     thick,
     contour lua =
       { levels = {1},
         labels = false} ]
     { f(x,y) };
  \end{axis}
\end{tikzpicture}
\end{document}