In my code, I have something like this
1 2 3 4 5 6
|
//assign Z
for (int i = 0; i < Iterations; i++)
{
Z = Z * Z + C; // Your classic fractal
//test for divergence of Z
}
|
This works fine, but I wanted to expand the potential of all the different things that could be done inside that for loop. What I've been working on is trying to move expressions like these to a file that would be read at run-time.
So for example, the contents of the file would be
Z = Z * Z + C
I worked on a "parser" for this type of equation, implementing the algorithm suggested here
http://stackoverflow.com/a/47717 using a stack.
Basically my hypothetical code now looks like this:
1 2 3
|
//for each pixel:
for (int i = 0; i < Iterations; i++)
Z = evaluate_file_expression(Z, C)
|
...where the evaluate function would have to re-do all the pops and pushes each time, for each iteration... for each pixel.
Is there any way to do the equivalent of the above code
without having to re-parse the equation each time? I hope that makes sense, it probably doesn't.
As an aside,
It'd be amazing to see the inner-workings of something like
Mathematica, where one can do
f[x_,y_] = x^2 + 2 y
and then evaluate
f[2, 3]
on the fly. Although now that I've typed this, the more I doubt there is a way to not have to re-parse the expression each time and do all the pops and pushes.
Perhaps I should also make data to quantify just how much slower
Z = evaluate_file_expression(Z, C);
is from
Z = Z * Z + C;