45 : base(new
ScriptNode[] { z, f, dr, Palette, DimX, DimY },
56 : base(new
ScriptNode[] { z, f, dr, Palette, DimX },
88 return new string[] {
"z",
"f",
"dr",
"Palette",
"DimX",
"DimY" };
97 string ColorExpression =
null;
108 Obj =
Arguments[i++].AssociatedObjectValue;
109 if (Obj is Complex z)
123 Obj =
Arguments[i].AssociatedObjectValue;
126 fDef = this.Arguments[i++];
128 if (f.NrArguments != 2)
129 throw new ScriptRuntimeException(
"Lambda expression in calls to MandelbrotFractal() must be of two variables (z,c).",
this);
147 ColorExpression = this.Arguments[i].SubExpression;
152 Palette = ColorModels.RandomLinearAnalogousHSL.CreatePalette(1024, 16, out
int Seed,
this,
Variables);
153 ColorExpression =
"RandomLinearAnalogousHSL(1024,16," + Seed.ToString() +
")";
155 if (i < c && this.Arguments[i] is
null)
171 throw new ScriptRuntimeException(
"Parameter mismatch in call to MandelbrotFractal(r,c,dr[,Palette][,dimx[,dimy]]).",
175 if (dimx <= 0 || dimx > 5000 || dimy <= 0 || dimy > 5000)
180 return CalcMandelbrot(rc, ic, dr, f,
Variables, Palette, dimx, dimy,
this, this.FractalZoomScript,
181 new object[] { Palette, dimx, dimy, ColorExpression, fDef });
186 new object[] { Palette, dimx, dimy, ColorExpression, fDef });
190 private string FractalZoomScript(
double r,
double i,
double Size,
object State)
192 object[] Parameters = (
object[])State;
193 int DimX = (int)Parameters[1];
194 int DimY = (int)Parameters[2];
195 string ColorExpression = (string)Parameters[3];
198 StringBuilder sb =
new StringBuilder();
200 sb.Append(
"MandelbrotFractal((");
212 if (!
string.IsNullOrEmpty(ColorExpression))
215 sb.Append(ColorExpression);
219 sb.Append(DimX.ToString());
221 sb.Append(DimY.ToString());
224 return sb.ToString();
231 SKColor[] Palette,
int Width,
int Height,
ScriptNode Node, FractalZoomScript FractalZoomScript,
object State)
236 double r0, i0, r1, i1;
239 double zr, zi, zrt, zr2, zi2;
248 greens =
new byte[N];
251 for (x = 0; x < N; x++)
255 greens[x] = cl.Green;
259 int size = Width * Height * 4;
260 byte[] rgb =
new byte[size];
263 r0 = rCenter - rDelta;
264 r1 = rCenter + rDelta;
266 aspect = ((double)Width) / Height;
268 i0 = iCenter - rDelta / aspect;
269 i1 = iCenter + rDelta / aspect;
271 dr = (r1 - r0) / Width;
272 di = (i1 - i0) / Height;
274 for (y = 0, i = i0, index = 0; y < Height; y++, i += di)
276 for (x = 0, r = r0; x < Width; x++, r += dr)
285 while (zr2 + zi2 < 9 && n < N)
289 zi = 2 * zr * zi + i;
304 rgb[index++] = blues[n];
305 rgb[index++] = greens[n];
306 rgb[index++] = reds[n];
314 return new FractalGraph(
Variables, Pixels, r0, i0, r1, i1, rDelta * 2,
true, Node,
FractalZoomScript, State);
322 ScriptNode Node, FractalZoomScript FractalZoomScript,
object State)
327 double r0, i0, r1, i1;
337 greens =
new byte[N];
340 for (x = 0; x < N; x++)
344 greens[x] = cl.Green;
348 int size = Width * Height * 4;
349 byte[] rgb =
new byte[size];
356 r0 = rCenter - rDelta;
357 r1 = rCenter + rDelta;
359 aspect = ((double)Width) / Height;
361 i0 = iCenter - rDelta / aspect;
362 i1 = iCenter + rDelta / aspect;
364 dr = (r1 - r0) / Width;
365 di = (i1 - i0) / Height;
367 for (y = 0, i = i0; y < Height; y++, i += di)
369 Complex[] Row =
new Complex[Width];
370 Complex[] Row0 =
new Complex[Width];
371 int[] Offset =
new int[Width];
374 for (x = 0, x2 = y * Width * 4, r = r0; x < Width; x++, r += dr, x2 += 4)
376 Row[x] = Row0[x] =
new Complex(r, i);
384 while (n < N && c > 0)
390 Row = Obj.AssociatedObjectValue as Complex[];
395 "and return complex vectors of equal length. Type returned: " +
396 Obj.GetType().FullName, Node);
398 else if (Row.Length != c)
401 "and return complex vectors of equal length. Length returned: " +
402 Row.Length.ToString() +
". Expected: " + c.ToString(), Node);
405 for (x = x2 = 0; x < c; x++)
434 rgb[j++] = greens[n];
444 Array.Resize(ref Row, x2);
445 Array.Resize(ref Row0, x2);
446 Array.Resize(ref Offset, x2);
453 for (x = 0; x < c; x++)
467 return new FractalGraph(
Variables, Pixels, r0, i0, r1, i1, rDelta * 2,
true, Node,
FractalZoomScript, State);
Script runtime exception.
Class managing a script expression.
static IElement Encapsulate(object Value)
Encapsulates an object.
static double ToDouble(object Object)
Converts an object to a double value.
static string ToString(double Value)
Converts a value to a string, that can be parsed as part of an expression.
Calculates a Mandelbrot Fractal Image
override IElement Evaluate(IElement[] Arguments, Variables Variables)
TODO
static FractalGraph CalcMandelbrot(double rCenter, double iCenter, double rDelta, ILambdaExpression f, Variables Variables, SKColor[] Palette, int Width, int Height, ScriptNode Node, FractalZoomScript FractalZoomScript, object State)
TODO
override string FunctionName
TODO
MandelbrotFractal(ScriptNode z, ScriptNode f, ScriptNode dr, ScriptNode Palette, int Start, int Length, Expression Expression)
TODO
MandelbrotFractal(ScriptNode z, ScriptNode f, ScriptNode dr, int Start, int Length, Expression Expression)
TODO
static FractalGraph CalcMandelbrot(Variables Variables, double rCenter, double iCenter, double rDelta, SKColor[] Palette, int Width, int Height, ScriptNode Node, FractalZoomScript FractalZoomScript, object State)
TODO
MandelbrotFractal(ScriptNode z, ScriptNode f, ScriptNode dr, ScriptNode Palette, ScriptNode DimX, int Start, int Length, Expression Expression)
TODO
override string[] DefaultArgumentNames
TODO
MandelbrotFractal(ScriptNode z, ScriptNode f, ScriptNode dr, ScriptNode Palette, ScriptNode DimX, ScriptNode DimY, int Start, int Length, Expression Expression)
TODO
Defines a clickable fractal graph in the complex plane.
static SKColor[] ToPalette(ObjectVector Vector)
TODO
Base class for multivariate funcions.
ScriptNode[] Arguments
Function arguments.
Base class for all nodes in a parsed script tree.
int Length
Length of expression covered by node.
string SubExpression
Sub-expression defining the node.
Expression Expression
Expression of which the node is a part.
int Start
Start position in script expression.
void CopyTo(Variables Variables)
Copies available variables to another variable collection.
Basic interface for all types of elements.
Base interface for lambda expressions.
IElement Evaluate(IElement[] Arguments, Variables Variables)
Evaluates the lambda expression.
delegate string FractalZoomScript(double r, double i, double Size, object State)
Generates new script when zoomed.
ArgumentType
Type of parameter used in a function definition or a lambda definition.