49 : base(new
ScriptNode[] { z, dr, R, c, Palette, DimX, DimY },
61 : base(new
ScriptNode[] { z, dr, R, c, Palette, DimX },
73 : base(new
ScriptNode[] { z, dr, R, c, Palette },
87 ArgumentType.Normal },
99 return new string[] {
"z",
"dr",
"R",
"c",
"Palette",
"DimX",
"DimY" };
108 string ColorExpression =
null;
110 double[] Coefficients =
null;
111 Complex[] CoefficientsZ =
null;
122 Obj =
Arguments[i++].AssociatedObjectValue;
123 if (Obj is Complex z)
139 if (i < c && ((Obj =
Arguments[i].AssociatedObjectValue) is
double || Obj is Complex))
148 if (i < c && this.Arguments[i] is
null)
155 Coefficients = (
double[])
Arguments[i++].AssociatedObjectValue;
157 CoefficientsZ = (Complex[])
Arguments[i++].AssociatedObjectValue;
167 CoefficientsZ =
new Complex[d];
168 for (j = 0; j < d; j++)
175 throw new ScriptRuntimeException(
"Lambda expression in calls to NewtonTopographyFractal() must be of one variable.",
this);
177 fDef = this.Arguments[i++];
182 " in call to NewtonTopographyFractal has to be a vector of numbers, containing coefficients " +
183 "of the polynomial to use. Now it was of type " +
Arguments[i].GetType().FullName,
192 ColorExpression = this.Arguments[i].SubExpression;
197 Palette = ColorModels.RandomLinearAnalogousHSL.CreatePalette(128, 4, out
int Seed,
this,
Variables);
198 ColorExpression =
"RandomLinearAnalogousHSL(128,4," + Seed.ToString() +
")";
200 if (i < c && this.Arguments[i] is
null)
216 throw new ScriptRuntimeException(
"Parameter mismatch in call to NewtonTopographyFractal(r,c,dr,Coefficients[,Palette][,dimx[,dimy]]).",
220 if (dimx <= 0 || dimx > 5000 || dimy <= 0 || dimy > 5000)
225 return CalcNewtonTopography(rc, ic, dr, R, f,
Variables, Palette, dimx, dimy,
this, this.FractalZoomScript,
226 new object[] { Palette, dimx, dimy, R, fDef, ColorExpression });
228 else if (!(CoefficientsZ is
null))
230 return CalcNewtonTopography(
Variables, rc, ic, dr, R, CoefficientsZ, Palette, dimx, dimy,
this, this.FractalZoomScript,
231 new object[] { Palette, dimx, dimy, R, CoefficientsZ, ColorExpression });
235 return CalcNewtonTopography(
Variables, rc, ic, dr, R, Coefficients, Palette, dimx, dimy,
this, this.FractalZoomScript,
236 new object[] { Palette, dimx, dimy, R, Coefficients, ColorExpression });
240 private string FractalZoomScript(
double r,
double i,
double Size,
object State)
242 object[] Parameters = (
object[])State;
243 int DimX = (int)Parameters[1];
244 int DimY = (int)Parameters[2];
245 Complex R = (Complex)Parameters[3];
246 double[] Coefficients = Parameters[4] as
double[];
247 string ColorExpression = (string)Parameters[5];
249 StringBuilder sb =
new StringBuilder();
251 sb.Append(
"NewtonTopographyFractal((");
262 sb.Append(fDef.SubExpression);
263 else if (Parameters[4] is Complex[] CoefficientsZ)
268 if (!
string.IsNullOrEmpty(ColorExpression))
271 sb.Append(ColorExpression);
275 sb.Append(DimX.ToString());
277 sb.Append(DimY.ToString());
280 return sb.ToString();
287 double[] Coefficients, SKColor[] Palette,
int Width,
int Height,
ScriptNode Node, FractalZoomScript FractalZoomScript,
object State)
290 double RIm = R.Imaginary;
291 double r0, i0, r1, i1;
294 double zr, zi, zr2, zi2, zr3, zi3, zr4, zi4;
299 int Degree = Coefficients.Length - 1;
305 Array.Resize(ref Coefficients, 3);
307 Coefficients[++Degree] = 0;
310 if (Width <= 2 || Height <= 2)
313 double[] Prim =
new double[Degree];
314 for (x = 1; x <= Degree; x++)
315 Prim[x - 1] = x * Coefficients[x];
318 Coefficients = (
double[])Coefficients.Clone();
319 Array.Reverse(Coefficients);
321 int Size = Width * Height;
324 int[] ColorIndex =
new int[Size];
328 r0 = rCenter - rDelta;
329 r1 = rCenter + rDelta;
331 aspect = ((double)Width) / Height;
333 i0 = iCenter - rDelta / aspect;
334 i1 = iCenter + rDelta / aspect;
336 dr = (r1 - r0) / Width;
337 di = (i1 - i0) / Height;
339 for (y = 0, i = i0; y < Height; y++, i += di)
341 for (x = 0, r = r0; x < Width; x++, r += dr)
351 foreach (
double C
in Coefficients)
353 Temp = zr2 * zr - zi2 * zi + C;
354 zi2 = zr2 * zi + zi2 * zr;
360 foreach (
double C
in Prim)
362 Temp = zr3 * zr - zi3 * zi + C;
363 zi3 = zr3 * zi + zi3 * zr;
369 Temp = 1.0 / (zr3 * zr3 + zi3 * zi3);
370 zr4 = (zr2 * zr3 + zi2 * zi3) * Temp;
371 zi4 = (zi2 * zr3 - zr2 * zi3) * Temp;
374 Temp = zr4 * RRe - zi4 * RIm;
375 zi4 = zr4 * RIm + zi4 * RRe;
381 Temp = Math.Sqrt(zr4 * zr4 + zi4 * zi4);
383 while ((Temp > Conv) && (Temp < Div) && (n++ < N));
385 if (Temp < Conv && n < N)
386 ColorIndex[Index++] = n;
388 ColorIndex[Index++] = N;
402 Complex[] Coefficients, SKColor[] Palette,
int Width,
int Height,
ScriptNode Node, FractalZoomScript FractalZoomScript,
406 double RIm = R.Imaginary;
407 double r0, i0, r1, i1;
410 double zr, zi, zr2, zi2, zr3, zi3, zr4, zi4;
415 int Degree = Coefficients.Length - 1;
421 Array.Resize(ref Coefficients, 3);
423 Coefficients[++Degree] = Complex.Zero;
426 if (Width <= 2 || Height <= 2)
429 Complex[] Prim =
new Complex[Degree];
430 for (x = 1; x <= Degree; x++)
431 Prim[x - 1] = x * Coefficients[x];
434 Coefficients = (Complex[])Coefficients.Clone();
435 Array.Reverse(Coefficients);
437 int j, c = Prim.Length;
438 double[] ReC =
new double[c + 1];
439 double[] ImC =
new double[c + 1];
440 double[] RePrim =
new double[c];
441 double[] ImPrim =
new double[c];
444 for (j = 0; j < c; j++)
448 ImC[j] = z.Imaginary;
452 ImPrim[j] = z.Imaginary;
457 ImC[j] = z.Imaginary;
459 int Size = Width * Height;
462 int[] ColorIndex =
new int[Size];
466 r0 = rCenter - rDelta;
467 r1 = rCenter + rDelta;
469 aspect = ((double)Width) / Height;
471 i0 = iCenter - rDelta / aspect;
472 i1 = iCenter + rDelta / aspect;
474 dr = (r1 - r0) / Width;
475 di = (i1 - i0) / Height;
477 for (y = 0, i = i0; y < Height; y++, i += di)
479 for (x = 0, r = r0; x < Width; x++, r += dr)
489 for (j = 0; j <= c; j++)
491 Temp = zr2 * zr - zi2 * zi + ReC[j];
492 zi2 = zr2 * zi + zi2 * zr + ImC[j];
498 for (j = 0; j < c; j++)
500 Temp = zr3 * zr - zi3 * zi + RePrim[j];
501 zi3 = zr3 * zi + zi3 * zr + ImPrim[j];
507 Temp = 1.0 / (zr3 * zr3 + zi3 * zi3);
508 zr4 = (zr2 * zr3 + zi2 * zi3) * Temp;
509 zi4 = (zi2 * zr3 - zr2 * zi3) * Temp;
512 Temp = zr4 * RRe - zi4 * RIm;
513 zi4 = zr4 * RIm + zi4 * RRe;
519 Temp = Math.Sqrt(zr4 * zr4 + zi4 * zi4);
521 while ((Temp > Conv) && (Temp < Div) && (n++ < N));
523 if (Temp < Conv && n < N)
524 ColorIndex[Index++] = n;
526 ColorIndex[Index++] = N;
541 ScriptNode Node, FractalZoomScript FractalZoomScript,
object State)
544 double RIm = R.Imaginary;
545 double r0, i0, r1, i1;
554 if (Width <= 2 || Height <= 2)
561 !(Differentiable.Differentiate(Differentiable.DefaultVariableName, v) is
ILambdaExpression fPrim))
566 int Size = Width * Height;
569 int[] ColorIndex =
new int[Size];
583 r0 = rCenter - rDelta;
584 r1 = rCenter + rDelta;
586 aspect = ((double)Width) / Height;
588 i0 = iCenter - rDelta / aspect;
589 i1 = iCenter + rDelta / aspect;
591 dr = (r1 - r0) / Width;
592 di = (i1 - i0) / Height;
594 for (y = 0, i = i0; y < Height; y++, i += di)
596 Row =
new Complex[Width];
597 Offset =
new int[Width];
600 for (x = 0, x2 = y * Width, r = r0; x < Width; x++, r += dr, x2++)
602 Row[x] =
new Complex(r, i);
607 while (n < N && c > 0)
612 Obj2 = fPrim.Evaluate(P, v);
613 Row2 = Obj.AssociatedObjectValue as Complex[];
614 Row3 = Obj2.AssociatedObjectValue as Complex[];
616 if (Row2 is
null || Row3 is
null)
618 throw new ScriptRuntimeException(
"Lambda expression (and its first derivative) must be able to accept complex vectors, " +
619 "and return complex vectors of equal length. Type returned: " +
620 Obj.GetType().FullName +
" and " + Obj2.GetType().FullName, Node);
622 else if (Row2.Length != c || Row3.Length != c)
624 throw new ScriptRuntimeException(
"Lambda expression (and its first derivative) must be able to accept complex vectors, " +
625 "and return complex vectors of equal length. Length returned: " +
626 Row2.Length.ToString() +
" and " + Row3.Length.ToString() +
627 ". Expected: " + c.ToString(), Node);
630 for (x = x2 = 0; x < c; x++)
633 z = R * Row2[x] / Row3[x];
638 if (Mod > Conv && Mod < Div)
648 ColorIndex[Index++] = N;
656 Array.Resize(ref Row, x2);
657 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
Exception thrown if an image with invalid size is requested.
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.