See Wiki and the description here . enter image description here

Here is my attempt to realize the pseudocode in p.3:

F[0][x_, y_] := {x/2, y/2}
F[1][x_, y_] := {x/2 + 1/2, y/2}
F[2][x_, y_] := {x/2, y/2 + 1/2}
Do[Do[x = Random[];y = Random[]; {x, y} = F[RandomInteger[2]][x, y],
  20]; Print[x, y], 5] 

Set::write: Tag CompoundExpression in x=Random[]; is Protected. General::stop: Further output of Set::write will be suppressed during this calculation.






  • $\begingroup$ I think you are just missing a y in your second initial definition within Do. i.e. x = Random[]; = Random[]; should be x = Random[]; y = Random[]; $\endgroup$
    – MarcoB
    Aug 1, 2017 at 18:24
  • $\begingroup$ @MarcoB: Thank you. Fixed. $\endgroup$
    – user64494
    Aug 1, 2017 at 18:25
  • $\begingroup$ You will also want to use Sow and Reap rather than Print to collect your results. Try e.g. Reap[Do[Do[x = Random[]; y = Random[]; {x, y} = F[RandomInteger[2]][x, y], 20]; Sow[{x, y}], 1000]][[2, 1]]; ListPlot[%] This generates this plot with no errors, but I am not sure whether that's what you want. $\endgroup$
    – MarcoB
    Aug 1, 2017 at 18:28
  • $\begingroup$ @MarkoB: It's kind of you. Many thanks from me to you. Your plot is not it. The Serpinski carpet should be produced. It would be nice to create a general procedure to produce a fractal flame. Unfortunately, my skills are not sufficient to this end. $\endgroup$
    – user64494
    Aug 1, 2017 at 18:33
  • $\begingroup$ +1 because it looks like the mathematica logo almost in the center $\endgroup$
    – William
    Aug 1, 2017 at 18:51

1 Answer 1


Using your own definitions of F[i] from OP, here is a literal implementation of the algorithm you pointed to on page 3 of the linked paper. it does not seem to produce a flame, but rather a Sierpinski triangle, as far as I understand it.

Module[{x, y},
  {x, y} = RandomReal[{-1, 1}, 2];
   Do[Sow[{x, y} = F[RandomInteger[{0, 2}]][x, y]], 10000]
  ][[2, 1, 21 ;;]] (*take only iterations after the first 20*)


Here is a more idiomatic implementation of the same algorithm in Mathematica:

 NestList[F[RandomInteger[{0, 2}]] @@ # &, RandomReal[{-1, 1}, 2], 10000][[21;;]]

Mathematica graphics

Here are some examples of other functions that were in the original paper:

v[0][{x_, y_}] := {x, y}
v[1][{x_, y_}] := {Sin[x], Cos[x]}
v[2][{x_, y_}] := Normalize[{x, y}]
v[3][{x_, y_}] := With[{rsquare = SquaredEuclideanDistance[x, y]}, {x Sin[rsquare] - y Cos[rsquare], x Cos[rsquare] + y Sin[rsquare]}]
v[4][{x_, y_}] := {x^2 - y^2, 2 x y}/EuclideanDistance[x, y]

NestList[v[RandomInteger[{0, 4}]][#] &, RandomReal[{-1, 1}, 2], 150000][[20 ;;]];

ListPlot[%, PlotRange -> {-10, 10}]

Mathematica graphics

It is now up to you to define "interesting" functions and try them out, them find an appropriate coloring scheme, etc.

  • $\begingroup$ +1. How about the general case? $\endgroup$
    – user64494
    Aug 1, 2017 at 18:41
  • $\begingroup$ @user64494 What do you mean by "general" here? $\endgroup$
    – MarcoB
    Aug 1, 2017 at 18:42
  • $\begingroup$ I have in mind arbitrary functions $F[i]$ and more complicated flames. $\endgroup$
    – user64494
    Aug 1, 2017 at 18:45
  • $\begingroup$ @user64494 I added some more functions from the paper, page 5. However, there is much more to making those beautiful images than just generating some points: you will have to choose an appropriate coloring scheme, perhaps some filtering of results, etc. $\endgroup$
    – MarcoB
    Aug 1, 2017 at 19:00
  • 2
    $\begingroup$ @user64494 I'd say that it is completely unsurprising that a single-purpose software package will do its only purpose better than a general purpose tool like Mathematica. In fact, if it didn't, there would be no point in its existence at all! Note also that all the formatting decisions have already been pre-implemented there. However, I'm sure that Mathematica beats Apophysis handily at, say, numerical and symbolic integration, formula manipulation, and cluster analysis, to name but a few random things... ;-) $\endgroup$
    – MarcoB
    Aug 1, 2017 at 19:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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