The Circles-and-Squares fractal is produced by iteration of the equation

$\quad \quad z_{n+1}=z_n^2\ ({\rm mod}\; m)$

which results in a Moiré-like pattern:


Source: Wolfram MathWorld

In another place I found the same pattern, but the equation said ${\rm modulo}\ n$ instead of $m$. Either way, this equation is very similar to the one generating the Mandelbrot set. How can it be plotted?

  • 1
    $\begingroup$ No doubt there are more concise ways but try With[{r = Range[-50, 50]^2}, Image@Rescale@Mod[Outer[Plus, r, r], 100]] $\endgroup$ – Simon Woods Sep 19 '14 at 13:37
  • $\begingroup$ In this way we get a low-res picture that's not scalable. The result should be plot or other similar constructs that are vectorial and can be exported as such (like in *.svg). $\endgroup$ – Bo C. Sep 19 '14 at 14:12
  • 2
    $\begingroup$ @BoC. you can double the numbers and change Image to ArrayPlot in Simon's code to get a plot and higher resolution. E.g. With[{r = Range[-100, 100]^2}, ArrayPlot@(1 - Rescale@Mod[Outer[Plus, r, r], 200])] $\endgroup$ – kglr Sep 19 '14 at 17:57
  • $\begingroup$ You should state your requirements in the question. I doubt you'll get a vectorial representation of a fractal image, though, unless it is something procedurally generated (e.g. by an L-System or such). $\endgroup$ – Yves Klett Sep 20 '14 at 7:21

The image taken from MathWorld appears to be something like this:

Image @ Rescale @ Table[Mod[x^2 + y^2, 100], {x, -50, 50}, {y, -50, 50}]

enter image description here

In my opinion this is not a fractal, and it certainly isn't produced by iteration. You described it as "Moiré-like", which is a far better description. It is simply a uniformly sampled 2D parabola, modulo some number. The pattern arises from the interaction between the fixed frequency of the sampling and the increasing frequency of the underlying function.

It's clearer in 1D:

Plot[Mod[x^2, 100], {x, -50, 50}, Exclusions -> None, PlotPoints -> 200, 
 PlotStyle -> Opacity[0.5], AspectRatio -> 0.3, 
 Epilog -> {PointSize[Medium], Point[{#, Mod[#^2, 100]} & /@ Range[-50, 50]]}]

enter image description here

So I don't really understand your comment about it being low-res and wanting a vectorial representation. The pattern appears because of the finite spatial sampling. Zooming into the function is very boring - you will just see the underlying wrapped parabola, not the never ending detail that a fractal provides:

enter image description here

Something prettier

Ignoring the picture in the question, and looking at the iteration $z_{n+1}=z_n^2\ ({\rm mod}\; m)$ gives something much nicer (in my opinion). Here it is with $m=2$ and 1 to 4 iterations:

z0 = Table[x + I y, {x, -3.001, 3, 0.01}, {y, -3.002, 3, 0.01}];
results = Rest @ NestList[Mod[#^2, 2] &, z0, 4];   
GraphicsGrid[Partition[Image @ Rescale @ Abs @ # & /@ results, 2]]

enter image description here

| improve this answer | |
  • $\begingroup$ That's an answer. (Crocodile Dundee voice) $\endgroup$ – Mr.Wizard Sep 20 '14 at 12:06
  • 2
    $\begingroup$ That is something prettier. 1970s version: WatershedComponents[Image@Rescale@Abs@results[[4]]] // Colorize (better if resolution is doubled). $\endgroup$ – Michael E2 Sep 20 '14 at 12:15
  • 2
    $\begingroup$ @MichaelE2, love it! Try this one: {b,h}=Rescale@#@results[[3]]&/@{Abs,Arg}; Image[{h,1-0b,1-b},Interleaving->False,ColorSpace->"HSB"] $\endgroup$ – Simon Woods Sep 20 '14 at 12:35
  • $\begingroup$ How about only one set of concentric circles? Which part of the equation defines the ratios of successive circles' radius? $\endgroup$ – Bo C. Sep 20 '14 at 17:18
  • $\begingroup$ @SimonWoods Oh that hurts my eyes! $\endgroup$ – Michael E2 Sep 20 '14 at 19:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.