47 : base(new
ScriptNode[] { z, dr, R, Coefficients, Palette, DimX, DimY },
58 : base(new
ScriptNode[] { z, dr, R, Coefficients, Palette, DimX },
69 : base(new
ScriptNode[] { z, dr, R, Coefficients, Palette },
80 : base(new
ScriptNode[] { z, dr, R, Coefficients },
111 return new string[] {
"z",
"dr",
"R",
"Coefficients",
"Palette",
"DimX",
"DimY" };
120 string ColorExpression =
null;
122 double[] Coefficients =
null;
123 Complex[] CoefficientsZ =
null;
134 Obj =
Arguments[i++].AssociatedObjectValue;
135 if (Obj is Complex z)
151 if (i < c && ((Obj =
Arguments[i].AssociatedObjectValue) is
double || Obj is Complex))
160 if (i < c && this.Arguments[i] is
null)
167 Coefficients = (
double[])
Arguments[i++].AssociatedObjectValue;
169 CoefficientsZ = (Complex[])
Arguments[i++].AssociatedObjectValue;
179 CoefficientsZ =
new Complex[d];
180 for (j = 0; j < d; j++)
187 throw new ScriptRuntimeException(
"Lambda expression in calls to HalleyTopographyFractal() must be of one variable.",
this);
189 fDef = this.Arguments[i++];
194 " in call to HalleyTopographyFractal has to be a vector of numbers, containing coefficients " +
195 "of the polynomial to use. Now it was of type " +
Arguments[i].GetType().FullName,
204 ColorExpression = this.Arguments[i].SubExpression;
209 Palette = ColorModels.RandomLinearAnalogousHSL.CreatePalette(128, 4, out
int Seed,
this,
Variables);
210 ColorExpression =
"RandomLinearAnalogousHSL(128,4," + Seed.ToString() +
")";
212 if (i < c && this.Arguments[i] is
null)
228 throw new ScriptRuntimeException(
"Parameter mismatch in call to HalleyTopographyFractal(z,dr[,R][,Coefficients][,Palette][,dimx[,dimy]]).",
232 if (dimx <= 0 || dimx > 5000 || dimy <= 0 || dimy > 5000)
237 return CalcHalley(rc, ic, dr, R, f,
Variables, Palette, dimx, dimy,
this, this.FractalZoomScript,
238 new object[] { Palette, dimx, dimy, R, fDef, ColorExpression });
240 else if (!(CoefficientsZ is
null))
243 this, this.FractalZoomScript,
244 new object[] { Palette, dimx, dimy, R, CoefficientsZ, ColorExpression });
249 this, this.FractalZoomScript,
250 new object[] { Palette, dimx, dimy, R, Coefficients, ColorExpression });
254 private string FractalZoomScript(
double r,
double i,
double Size,
object State)
256 object[] Parameters = (
object[])State;
257 int DimX = (int)Parameters[1];
258 int DimY = (int)Parameters[2];
259 Complex R = (Complex)Parameters[3];
260 double[] Coefficients = Parameters[4] as
double[];
261 string ColorExpression = (string)Parameters[5];
263 StringBuilder sb =
new StringBuilder();
265 sb.Append(
"HalleyTopographyFractal((");
276 sb.Append(fDef.SubExpression);
277 else if (Parameters[4] is Complex[] CoefficientsZ)
282 if (!
string.IsNullOrEmpty(ColorExpression))
285 sb.Append(ColorExpression);
289 sb.Append(DimX.ToString());
291 sb.Append(DimY.ToString());
294 return sb.ToString();
301 double[] Coefficients, SKColor[] Palette,
int Width,
int Height,
ScriptNode Node,
302 FractalZoomScript FractalZoomScript,
object State)
305 double RIm = R.Imaginary;
306 double r0, i0, r1, i1;
309 double zr, zi, zr2, zi2, zr3, zi3, zr4, zi4, zr5, zi5, zr6, zi6;
315 int Degree = Coefficients.Length - 1;
321 Array.Resize(ref Coefficients, 4);
323 Coefficients[++Degree] = 0;
326 double[] Prim =
new double[Degree];
327 for (x = 1; x <= Degree; x++)
328 Prim[x - 1] = x * Coefficients[x];
330 double[] Bis =
new double[Degree - 1];
331 for (x = 1; x < Degree; x++)
332 Bis[x - 1] = x * Prim[x];
336 Coefficients = (
double[])Coefficients.Clone();
337 Array.Reverse(Coefficients);
339 int size = Width * Height;
340 int[] ColorIndex =
new int[size];
345 r0 = rCenter - rDelta;
346 r1 = rCenter + rDelta;
348 aspect = ((double)Width) / Height;
350 i0 = iCenter - rDelta / aspect;
351 i1 = iCenter + rDelta / aspect;
353 dr = (r1 - r0) / Width;
354 di = (i1 - i0) / Height;
356 for (y = 0, i = i0, index = 0; y < Height; y++, i += di)
358 for (x = 0, r = r0; x < Width; x++, r += dr)
368 foreach (
double C
in Coefficients)
370 Temp = zr2 * zr - zi2 * zi + C;
371 zi2 = zr2 * zi + zi2 * zr;
377 foreach (
double C
in Prim)
379 Temp = zr3 * zr - zi3 * zi + C;
380 zi3 = zr3 * zi + zi3 * zr;
386 foreach (
double C
in Bis)
388 Temp = zr4 * zr - zi4 * zi + C;
389 zi4 = zr4 * zi + zi4 * zr;
395 zr5 = 2 * (zr2 * zr3 - zi2 * zi3);
396 zi5 = 2 * (zr2 * zi3 + zi2 * zr3);
400 zr6 = 2 * (zr3 * zr3 - zi3 * zi3) - (zr2 * zr4 - zi2 * zi4);
401 zi6 = 4 * zr3 * zi3 - (zr2 * zi4 + zr4 * zi2);
405 Temp = 1.0 / (zr6 * zr6 + zi6 * zi6);
406 zr4 = (zr5 * zr6 + zi5 * zi6) * Temp;
407 zi4 = (zi5 * zr6 - zr5 * zi6) * Temp;
410 Temp = zr4 * RRe - zi4 * RIm;
411 zi4 = zr4 * RIm + zi4 * RRe;
417 Temp = Math.Sqrt(zr4 * zr4 + zi4 * zi4);
419 while ((Temp > Conv) && (Temp < Div) && (n++ < N));
421 if (Temp < Conv && n < N)
422 ColorIndex[index++] = n;
424 ColorIndex[index++] = N;
438 Complex[] Coefficients, SKColor[] Palette,
int Width,
int Height,
ScriptNode Node, FractalZoomScript FractalZoomScript,
442 double RIm = R.Imaginary;
443 double r0, i0, r1, i1;
446 double zr, zi, zr2, zi2, zr3, zi3, zr4, zi4, zr5, zi5, zr6, zi6;
452 int Degree = Coefficients.Length - 1;
458 Array.Resize(ref Coefficients, 4);
460 Coefficients[++Degree] = Complex.Zero;
463 Complex[] Prim =
new Complex[Degree];
464 for (x = 1; x <= Degree; x++)
465 Prim[x - 1] = x * Coefficients[x];
467 Complex[] Bis =
new Complex[Degree - 1];
468 for (x = 1; x < Degree; x++)
469 Bis[x - 1] = x * Prim[x];
473 Coefficients = (Complex[])Coefficients.Clone();
474 Array.Reverse(Coefficients);
476 int j, c = Prim.Length;
478 double[] ReC =
new double[c + 1];
479 double[] ImC =
new double[c + 1];
480 double[] RePrim =
new double[c];
481 double[] ImPrim =
new double[c];
482 double[] ReBis =
new double[c2];
483 double[] ImBis =
new double[c2];
486 for (j = 0; j < c; j++)
490 ImC[j] = z.Imaginary;
494 ImPrim[j] = z.Imaginary;
500 ImBis[j] = z.Imaginary;
506 ImC[j] = z.Imaginary;
508 int size = Width * Height;
509 int[] ColorIndex =
new int[size];
514 r0 = rCenter - rDelta;
515 r1 = rCenter + rDelta;
517 aspect = ((double)Width) / Height;
519 i0 = iCenter - rDelta / aspect;
520 i1 = iCenter + rDelta / aspect;
522 dr = (r1 - r0) / Width;
523 di = (i1 - i0) / Height;
525 for (y = 0, i = i0, index = 0; y < Height; y++, i += di)
527 for (x = 0, r = r0; x < Width; x++, r += dr)
537 for (j = 0; j <= c; j++)
539 Temp = zr2 * zr - zi2 * zi + ReC[j];
540 zi2 = zr2 * zi + zi2 * zr + ImC[j];
546 for (j = 0; j < c; j++)
548 Temp = zr3 * zr - zi3 * zi + RePrim[j];
549 zi3 = zr3 * zi + zi3 * zr + ImPrim[j];
555 for (j = 0; j < c2; j++)
557 Temp = zr4 * zr - zi4 * zi + ReBis[j];
558 zi4 = zr4 * zi + zi4 * zr + ImBis[j];
564 zr5 = 2 * (zr2 * zr3 - zi2 * zi3);
565 zi5 = 2 * (zr2 * zi3 + zi2 * zr3);
569 zr6 = 2 * (zr3 * zr3 - zi3 * zi3) - (zr2 * zr4 - zi2 * zi4);
570 zi6 = 4 * zr3 * zi3 - (zr2 * zi4 + zr4 * zi2);
574 Temp = 1.0 / (zr6 * zr6 + zi6 * zi6);
575 zr4 = (zr5 * zr6 + zi5 * zi6) * Temp;
576 zi4 = (zi5 * zr6 - zr5 * zi6) * Temp;
579 Temp = zr4 * RRe - zi4 * RIm;
580 zi4 = zr4 * RIm + zi4 * RRe;
586 Temp = Math.Sqrt(zr4 * zr4 + zi4 * zi4);
588 while ((Temp > Conv) && (Temp < Div) && (n++ < N));
590 if (Temp < Conv && n < N)
591 ColorIndex[index++] = n;
593 ColorIndex[index++] = N;
608 ScriptNode Node, FractalZoomScript FractalZoomScript,
object State)
611 double RIm = R.Imaginary;
612 double r0, i0, r1, i1;
624 string ParameterName;
626 !(Differentiable.Differentiate(ParameterName = Differentiable.DefaultVariableName, v) is
ILambdaExpression fPrim))
637 int size = Width * Height;
638 int[] ColorIndex =
new int[size];
655 r0 = rCenter - rDelta;
656 r1 = rCenter + rDelta;
658 aspect = ((double)Width) / Height;
660 i0 = iCenter - rDelta / aspect;
661 i1 = iCenter + rDelta / aspect;
663 dr = (r1 - r0) / Width;
664 di = (i1 - i0) / Height;
666 for (y = 0, i = i0; y < Height; y++, i += di)
668 Row =
new Complex[Width];
669 Offset =
new int[Width];
672 for (x = 0, x2 = y * Width, r = r0; x < Width; x++, r += dr, x2++)
674 Row[x] =
new Complex(r, i);
679 while (n < N && c > 0)
684 Obj2 = fPrim.Evaluate(P, v);
685 Obj3 = fBis.Evaluate(P, v);
686 Row2 = Obj.AssociatedObjectValue as Complex[];
687 Row3 = Obj2.AssociatedObjectValue as Complex[];
688 Row4 = Obj3.AssociatedObjectValue as Complex[];
690 if (Row2 is
null || Row3 is
null || Row4 is
null)
692 throw new ScriptRuntimeException(
"Lambda expression (and its first and second derivative) must be able to accept complex vectors, " +
693 "and return complex vectors of equal length. Type returned: " +
694 Obj.GetType().FullName +
", " + Obj2.GetType().FullName +
" and " + Obj3.GetType().FullName,
697 else if (Row2.Length != c || Row3.Length != c)
699 throw new ScriptRuntimeException(
"Lambda expression (and its first and second derivative) must be able to accept complex vectors, " +
700 "and return complex vectors of equal length. Length returned: " +
701 Row2.Length.ToString() +
", " + Row3.Length.ToString() +
" and " + Row4.Length.ToString() +
702 ". Expected: " + c.ToString(), Node);
705 for (x = x2 = 0; x < c; x++)
712 z = R2 * z * z2 / (2 * z2 * z2 - z * z3);
717 if (Mod > Conv && Mod < Div)
735 Array.Resize(ref Row, x2);
736 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 Halley Topography Fractal Image
HalleyTopographyFractal(ScriptNode z, ScriptNode dr, ScriptNode R, ScriptNode Coefficients, int Start, int Length, Expression Expression)
TODO
HalleyTopographyFractal(ScriptNode z, ScriptNode dr, int Start, int Length, Expression Expression)
TODO
HalleyTopographyFractal(ScriptNode z, ScriptNode dr, ScriptNode R, ScriptNode Coefficients, ScriptNode Palette, ScriptNode DimX, ScriptNode DimY, int Start, int Length, Expression Expression)
TODO
override IElement Evaluate(IElement[] Arguments, Variables Variables)
TODO
override string FunctionName
TODO
HalleyTopographyFractal(ScriptNode z, ScriptNode dr, ScriptNode R, ScriptNode Coefficients, ScriptNode Palette, ScriptNode DimX, int Start, int Length, Expression Expression)
TODO
static FractalGraph CalcHalley(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
override string[] DefaultArgumentNames
TODO
HalleyTopographyFractal(ScriptNode z, ScriptNode dr, ScriptNode R, ScriptNode Coefficients, ScriptNode Palette, int Start, int Length, Expression Expression)
TODO
static FractalGraph CalcHalley(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
static FractalGraph CalcHalley(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
HalleyTopographyFractal(ScriptNode z, ScriptNode dr, ScriptNode R, int Start, int Length, Expression Expression)
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.