48 : base(new
ScriptNode[] { z, dr, R, c, Palette, DimX, DimY },
60 : base(new
ScriptNode[] { z, dr, R, c, Palette, DimX },
72 : base(new
ScriptNode[] { z, dr, R, c, Palette },
86 ArgumentType.Normal },
98 return new string[] {
"z",
"dr",
"R",
"c",
"Palette",
"DimX",
"DimY" };
107 string ColorExpression =
null;
109 double[] Coefficients =
null;
110 Complex[] CoefficientsZ =
null;
121 Obj =
Arguments[i++].AssociatedObjectValue;
122 if (Obj is Complex z)
138 if (i < c && ((Obj =
Arguments[i].AssociatedObjectValue) is
double || Obj is Complex))
147 if (i < c && this.Arguments[i] is
null)
154 Coefficients = (
double[])
Arguments[i++].AssociatedObjectValue;
156 CoefficientsZ = (Complex[])
Arguments[i++].AssociatedObjectValue;
166 CoefficientsZ =
new Complex[d];
167 for (j = 0; j < d; j++)
174 throw new ScriptRuntimeException(
"Lambda expression in calls to NewtonTopographyFractal() must be of one variable.",
this);
176 fDef = this.Arguments[i++];
181 " in call to NewtonTopographyFractal has to be a vector of numbers, containing coefficients " +
182 "of the polynomial to use. Now it was of type " +
Arguments[i].GetType().FullName,
191 ColorExpression = this.Arguments[i].SubExpression;
196 Palette = ColorModels.RandomLinearAnalogousHSL.CreatePalette(128, 4, out
int Seed,
this,
Variables);
197 ColorExpression =
"RandomLinearAnalogousHSL(128,4," + Seed.ToString() +
")";
199 if (i < c && this.Arguments[i] is
null)
215 throw new ScriptRuntimeException(
"Parameter mismatch in call to NewtonTopographyFractal(r,c,dr,Coefficients[,Palette][,dimx[,dimy]]).",
219 if (dimx <= 0 || dimx > 5000 || dimy <= 0 || dimy > 5000)
224 return CalcNewtonTopography(rc, ic, dr, R, f,
Variables, Palette, dimx, dimy,
this, this.FractalZoomScript,
225 new object[] { Palette, dimx, dimy, R, fDef, ColorExpression });
227 else if (!(CoefficientsZ is
null))
229 return CalcNewtonTopography(
Variables, rc, ic, dr, R, CoefficientsZ, Palette, dimx, dimy,
this, this.FractalZoomScript,
230 new object[] { Palette, dimx, dimy, R, CoefficientsZ, ColorExpression });
234 return CalcNewtonTopography(
Variables, rc, ic, dr, R, Coefficients, Palette, dimx, dimy,
this, this.FractalZoomScript,
235 new object[] { Palette, dimx, dimy, R, Coefficients, ColorExpression });
239 private string FractalZoomScript(
double r,
double i,
double Size,
object State)
241 object[] Parameters = (
object[])State;
242 int DimX = (int)Parameters[1];
243 int DimY = (int)Parameters[2];
244 Complex R = (Complex)Parameters[3];
245 double[] Coefficients = Parameters[4] as
double[];
246 string ColorExpression = (string)Parameters[5];
248 StringBuilder sb =
new StringBuilder();
250 sb.Append(
"NewtonTopographyFractal((");
261 sb.Append(fDef.SubExpression);
262 else if (Parameters[4] is Complex[] CoefficientsZ)
267 if (!
string.IsNullOrEmpty(ColorExpression))
270 sb.Append(ColorExpression);
274 sb.Append(DimX.ToString());
276 sb.Append(DimY.ToString());
279 return sb.ToString();
286 double[] Coefficients, SKColor[] Palette,
int Width,
int Height,
ScriptNode Node, FractalZoomScript FractalZoomScript,
object State)
289 double RIm = R.Imaginary;
290 double r0, i0, r1, i1;
293 double zr, zi, zr2, zi2, zr3, zi3, zr4, zi4;
298 int Degree = Coefficients.Length - 1;
304 Array.Resize(ref Coefficients, 3);
306 Coefficients[++Degree] = 0;
309 if (Width <= 2 || Height <= 2)
312 double[] Prim =
new double[Degree];
313 for (x = 1; x <= Degree; x++)
314 Prim[x - 1] = x * Coefficients[x];
317 Coefficients = (
double[])Coefficients.Clone();
318 Array.Reverse(Coefficients);
320 int Size = Width * Height;
323 int[] ColorIndex =
new int[Size];
327 r0 = rCenter - rDelta;
328 r1 = rCenter + rDelta;
330 aspect = ((double)Width) / Height;
332 i0 = iCenter - rDelta / aspect;
333 i1 = iCenter + rDelta / aspect;
335 dr = (r1 - r0) / Width;
336 di = (i1 - i0) / Height;
338 for (y = 0, i = i0; y < Height; y++, i += di)
340 for (x = 0, r = r0; x < Width; x++, r += dr)
350 foreach (
double C
in Coefficients)
352 Temp = zr2 * zr - zi2 * zi + C;
353 zi2 = zr2 * zi + zi2 * zr;
359 foreach (
double C
in Prim)
361 Temp = zr3 * zr - zi3 * zi + C;
362 zi3 = zr3 * zi + zi3 * zr;
368 Temp = 1.0 / (zr3 * zr3 + zi3 * zi3);
369 zr4 = (zr2 * zr3 + zi2 * zi3) * Temp;
370 zi4 = (zi2 * zr3 - zr2 * zi3) * Temp;
373 Temp = zr4 * RRe - zi4 * RIm;
374 zi4 = zr4 * RIm + zi4 * RRe;
380 Temp = Math.Sqrt(zr4 * zr4 + zi4 * zi4);
382 while ((Temp > Conv) && (Temp < Div) && (n++ < N));
384 if (Temp < Conv && n < N)
385 ColorIndex[Index++] = n;
387 ColorIndex[Index++] = N;
401 Complex[] Coefficients, SKColor[] Palette,
int Width,
int Height,
ScriptNode Node, FractalZoomScript FractalZoomScript,
405 double RIm = R.Imaginary;
406 double r0, i0, r1, i1;
409 double zr, zi, zr2, zi2, zr3, zi3, zr4, zi4;
414 int Degree = Coefficients.Length - 1;
420 Array.Resize(ref Coefficients, 3);
422 Coefficients[++Degree] = Complex.Zero;
425 if (Width <= 2 || Height <= 2)
428 Complex[] Prim =
new Complex[Degree];
429 for (x = 1; x <= Degree; x++)
430 Prim[x - 1] = x * Coefficients[x];
433 Coefficients = (Complex[])Coefficients.Clone();
434 Array.Reverse(Coefficients);
436 int j, c = Prim.Length;
437 double[] ReC =
new double[c + 1];
438 double[] ImC =
new double[c + 1];
439 double[] RePrim =
new double[c];
440 double[] ImPrim =
new double[c];
443 for (j = 0; j < c; j++)
447 ImC[j] = z.Imaginary;
451 ImPrim[j] = z.Imaginary;
456 ImC[j] = z.Imaginary;
458 int Size = Width * Height;
461 int[] ColorIndex =
new int[Size];
465 r0 = rCenter - rDelta;
466 r1 = rCenter + rDelta;
468 aspect = ((double)Width) / Height;
470 i0 = iCenter - rDelta / aspect;
471 i1 = iCenter + rDelta / aspect;
473 dr = (r1 - r0) / Width;
474 di = (i1 - i0) / Height;
476 for (y = 0, i = i0; y < Height; y++, i += di)
478 for (x = 0, r = r0; x < Width; x++, r += dr)
488 for (j = 0; j <= c; j++)
490 Temp = zr2 * zr - zi2 * zi + ReC[j];
491 zi2 = zr2 * zi + zi2 * zr + ImC[j];
497 for (j = 0; j < c; j++)
499 Temp = zr3 * zr - zi3 * zi + RePrim[j];
500 zi3 = zr3 * zi + zi3 * zr + ImPrim[j];
506 Temp = 1.0 / (zr3 * zr3 + zi3 * zi3);
507 zr4 = (zr2 * zr3 + zi2 * zi3) * Temp;
508 zi4 = (zi2 * zr3 - zr2 * zi3) * Temp;
511 Temp = zr4 * RRe - zi4 * RIm;
512 zi4 = zr4 * RIm + zi4 * RRe;
518 Temp = Math.Sqrt(zr4 * zr4 + zi4 * zi4);
520 while ((Temp > Conv) && (Temp < Div) && (n++ < N));
522 if (Temp < Conv && n < N)
523 ColorIndex[Index++] = n;
525 ColorIndex[Index++] = N;
540 ScriptNode Node, FractalZoomScript FractalZoomScript,
object State)
543 double RIm = R.Imaginary;
544 double r0, i0, r1, i1;
553 if (Width <= 2 || Height <= 2)
560 !(Differentiable.Differentiate(Differentiable.DefaultVariableName, v) is
ILambdaExpression fPrim))
565 int Size = Width * Height;
568 int[] ColorIndex =
new int[Size];
582 r0 = rCenter - rDelta;
583 r1 = rCenter + rDelta;
585 aspect = ((double)Width) / Height;
587 i0 = iCenter - rDelta / aspect;
588 i1 = iCenter + rDelta / aspect;
590 dr = (r1 - r0) / Width;
591 di = (i1 - i0) / Height;
593 for (y = 0, i = i0; y < Height; y++, i += di)
595 Row =
new Complex[Width];
596 Offset =
new int[Width];
599 for (x = 0, x2 = y * Width, r = r0; x < Width; x++, r += dr, x2++)
601 Row[x] =
new Complex(r, i);
606 while (n < N && c > 0)
611 Obj2 = fPrim.Evaluate(P, v);
612 Row2 = Obj.AssociatedObjectValue as Complex[];
613 Row3 = Obj2.AssociatedObjectValue as Complex[];
615 if (Row2 is
null || Row3 is
null)
617 throw new ScriptRuntimeException(
"Lambda expression (and its first derivative) must be able to accept complex vectors, " +
618 "and return complex vectors of equal length. Type returned: " +
619 Obj.GetType().FullName +
" and " + Obj2.GetType().FullName, Node);
621 else if (Row2.Length != c || Row3.Length != c)
623 throw new ScriptRuntimeException(
"Lambda expression (and its first derivative) must be able to accept complex vectors, " +
624 "and return complex vectors of equal length. Length returned: " +
625 Row2.Length.ToString() +
" and " + Row3.Length.ToString() +
626 ". Expected: " + c.ToString(), Node);
629 for (x = x2 = 0; x < c; x++)
632 z = R * Row2[x] / Row3[x];
637 if (Mod > Conv && Mod < Div)
647 ColorIndex[Index++] = N;
655 Array.Resize(ref Row, x2);
656 Array.Resize(ref Offset, x2);
Script runtime exception.
Class managing a script expression.
static Complex ToComplex(object Object)
Converts an object to a complex value.
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 Newton Fractal Image, and extracts the topography lines from it.
static FractalGraph CalcNewtonTopography(Variables Variables, double rCenter, double iCenter, double rDelta, Complex R, Complex[] Coefficients, SKColor[] Palette, int Width, int Height, ScriptNode Node, FractalZoomScript FractalZoomScript, object State)
TODO
NewtonTopographyFractal(ScriptNode z, ScriptNode dr, ScriptNode R, ScriptNode c, ScriptNode Palette, ScriptNode DimX, int Start, int Length, Expression Expression)
TODO
override string[] DefaultArgumentNames
TODO
NewtonTopographyFractal(ScriptNode z, ScriptNode dr, ScriptNode R, ScriptNode c, ScriptNode Palette, ScriptNode DimX, ScriptNode DimY, int Start, int Length, Expression Expression)
TODO
override string FunctionName
TODO
override IElement Evaluate(IElement[] Arguments, Variables Variables)
TODO
NewtonTopographyFractal(ScriptNode z, ScriptNode dr, ScriptNode R, ScriptNode c, int Start, int Length, Expression Expression)
TODO
static FractalGraph CalcNewtonTopography(double rCenter, double iCenter, double rDelta, Complex R, ILambdaExpression f, Variables Variables, SKColor[] Palette, int Width, int Height, ScriptNode Node, FractalZoomScript FractalZoomScript, object State)
TODO
NewtonTopographyFractal(ScriptNode z, ScriptNode dr, ScriptNode R, ScriptNode c, ScriptNode Palette, int Start, int Length, Expression Expression)
TODO
static FractalGraph CalcNewtonTopography(Variables Variables, double rCenter, double iCenter, double rDelta, Complex R, double[] Coefficients, SKColor[] Palette, int Width, int Height, ScriptNode Node, FractalZoomScript FractalZoomScript, object State)
TODO
Defines a clickable fractal graph in the complex plane.
static PixelInformation ToPixels(double[] ColorIndex, int Width, int Height, SKColor[] Palette)
TODO
static SKColor[] ToPalette(ObjectVector Vector)
TODO
static double[] FindBoundaries(double[] ColorIndex, int Width, int Height)
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.
override string ToString()
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.
object AssociatedObjectValue
Associated object value.
Basic interface for vectors.
int Dimension
Dimension of vector.
IElement GetElement(int Index)
Gets an element of the vector.
Base interface for lambda expressions.
Base interface for lambda expressions.
IElement Evaluate(IElement[] Arguments, Variables Variables)
Evaluates the lambda expression.
int NrArguments
Number of arguments.
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.