46 : base(new
ScriptNode[] { z, dr, R, Coefficients, Palette, DimX, DimY },
57 : base(new
ScriptNode[] { z, dr, R, Coefficients, Palette, DimX },
68 : base(new
ScriptNode[] { z, dr, R, Coefficients, Palette },
79 : base(new
ScriptNode[] { z, dr, R, Coefficients },
110 return new string[] {
"z",
"dr",
"R",
"Coefficients",
"Palette",
"DimX",
"DimY" };
119 string ColorExpression =
null;
121 double[] Coefficients =
null;
122 Complex[] CoefficientsZ =
null;
133 Obj =
Arguments[i++].AssociatedObjectValue;
134 if (Obj is Complex z)
150 if (i < c && ((Obj =
Arguments[i].AssociatedObjectValue) is
double || Obj is Complex))
159 if (i < c && this.Arguments[i] is
null)
166 Coefficients = (
double[])
Arguments[i++].AssociatedObjectValue;
168 CoefficientsZ = (Complex[])
Arguments[i++].AssociatedObjectValue;
178 CoefficientsZ =
new Complex[d];
179 for (j = 0; j < d; j++)
186 throw new ScriptRuntimeException(
"Lambda expression in calls to HalleyTopographyFractal() must be of one variable.",
this);
188 fDef = this.Arguments[i++];
193 " in call to HalleyTopographyFractal has to be a vector of numbers, containing coefficients " +
194 "of the polynomial to use. Now it was of type " +
Arguments[i].GetType().FullName,
203 ColorExpression = this.Arguments[i].SubExpression;
208 Palette = ColorModels.RandomLinearAnalogousHSL.CreatePalette(128, 4, out
int Seed,
this,
Variables);
209 ColorExpression =
"RandomLinearAnalogousHSL(128,4," + Seed.ToString() +
")";
211 if (i < c && this.Arguments[i] is
null)
227 throw new ScriptRuntimeException(
"Parameter mismatch in call to HalleyTopographyFractal(z,dr[,R][,Coefficients][,Palette][,dimx[,dimy]]).",
231 if (dimx <= 0 || dimx > 5000 || dimy <= 0 || dimy > 5000)
236 return CalcHalley(rc, ic, dr, R, f,
Variables, Palette, dimx, dimy,
this, this.FractalZoomScript,
237 new object[] { Palette, dimx, dimy, R, fDef, ColorExpression });
239 else if (!(CoefficientsZ is
null))
242 this, this.FractalZoomScript,
243 new object[] { Palette, dimx, dimy, R, CoefficientsZ, ColorExpression });
248 this, this.FractalZoomScript,
249 new object[] { Palette, dimx, dimy, R, Coefficients, ColorExpression });
253 private string FractalZoomScript(
double r,
double i,
double Size,
object State)
255 object[] Parameters = (
object[])State;
256 int DimX = (int)Parameters[1];
257 int DimY = (int)Parameters[2];
258 Complex R = (Complex)Parameters[3];
259 double[] Coefficients = Parameters[4] as
double[];
260 string ColorExpression = (string)Parameters[5];
262 StringBuilder sb =
new StringBuilder();
264 sb.Append(
"HalleyTopographyFractal((");
275 sb.Append(fDef.SubExpression);
276 else if (Parameters[4] is Complex[] CoefficientsZ)
281 if (!
string.IsNullOrEmpty(ColorExpression))
284 sb.Append(ColorExpression);
288 sb.Append(DimX.ToString());
290 sb.Append(DimY.ToString());
293 return sb.ToString();
300 double[] Coefficients, SKColor[] Palette,
int Width,
int Height,
ScriptNode Node,
301 FractalZoomScript FractalZoomScript,
object State)
304 double RIm = R.Imaginary;
305 double r0, i0, r1, i1;
308 double zr, zi, zr2, zi2, zr3, zi3, zr4, zi4, zr5, zi5, zr6, zi6;
314 int Degree = Coefficients.Length - 1;
320 Array.Resize(ref Coefficients, 4);
322 Coefficients[++Degree] = 0;
325 double[] Prim =
new double[Degree];
326 for (x = 1; x <= Degree; x++)
327 Prim[x - 1] = x * Coefficients[x];
329 double[] Bis =
new double[Degree - 1];
330 for (x = 1; x < Degree; x++)
331 Bis[x - 1] = x * Prim[x];
335 Coefficients = (
double[])Coefficients.Clone();
336 Array.Reverse(Coefficients);
338 int size = Width * Height;
339 int[] ColorIndex =
new int[size];
344 r0 = rCenter - rDelta;
345 r1 = rCenter + rDelta;
347 aspect = ((double)Width) / Height;
349 i0 = iCenter - rDelta / aspect;
350 i1 = iCenter + rDelta / aspect;
352 dr = (r1 - r0) / Width;
353 di = (i1 - i0) / Height;
355 for (y = 0, i = i0, index = 0; y < Height; y++, i += di)
357 for (x = 0, r = r0; x < Width; x++, r += dr)
367 foreach (
double C
in Coefficients)
369 Temp = zr2 * zr - zi2 * zi + C;
370 zi2 = zr2 * zi + zi2 * zr;
376 foreach (
double C
in Prim)
378 Temp = zr3 * zr - zi3 * zi + C;
379 zi3 = zr3 * zi + zi3 * zr;
385 foreach (
double C
in Bis)
387 Temp = zr4 * zr - zi4 * zi + C;
388 zi4 = zr4 * zi + zi4 * zr;
394 zr5 = 2 * (zr2 * zr3 - zi2 * zi3);
395 zi5 = 2 * (zr2 * zi3 + zi2 * zr3);
399 zr6 = 2 * (zr3 * zr3 - zi3 * zi3) - (zr2 * zr4 - zi2 * zi4);
400 zi6 = 4 * zr3 * zi3 - (zr2 * zi4 + zr4 * zi2);
404 Temp = 1.0 / (zr6 * zr6 + zi6 * zi6);
405 zr4 = (zr5 * zr6 + zi5 * zi6) * Temp;
406 zi4 = (zi5 * zr6 - zr5 * zi6) * Temp;
409 Temp = zr4 * RRe - zi4 * RIm;
410 zi4 = zr4 * RIm + zi4 * RRe;
416 Temp = Math.Sqrt(zr4 * zr4 + zi4 * zi4);
418 while ((Temp > Conv) && (Temp < Div) && (n++ < N));
420 if (Temp < Conv && n < N)
421 ColorIndex[index++] = n;
423 ColorIndex[index++] = N;
437 Complex[] Coefficients, SKColor[] Palette,
int Width,
int Height,
ScriptNode Node, FractalZoomScript FractalZoomScript,
441 double RIm = R.Imaginary;
442 double r0, i0, r1, i1;
445 double zr, zi, zr2, zi2, zr3, zi3, zr4, zi4, zr5, zi5, zr6, zi6;
451 int Degree = Coefficients.Length - 1;
457 Array.Resize(ref Coefficients, 4);
459 Coefficients[++Degree] = Complex.Zero;
462 Complex[] Prim =
new Complex[Degree];
463 for (x = 1; x <= Degree; x++)
464 Prim[x - 1] = x * Coefficients[x];
466 Complex[] Bis =
new Complex[Degree - 1];
467 for (x = 1; x < Degree; x++)
468 Bis[x - 1] = x * Prim[x];
472 Coefficients = (Complex[])Coefficients.Clone();
473 Array.Reverse(Coefficients);
475 int j, c = Prim.Length;
477 double[] ReC =
new double[c + 1];
478 double[] ImC =
new double[c + 1];
479 double[] RePrim =
new double[c];
480 double[] ImPrim =
new double[c];
481 double[] ReBis =
new double[c2];
482 double[] ImBis =
new double[c2];
485 for (j = 0; j < c; j++)
489 ImC[j] = z.Imaginary;
493 ImPrim[j] = z.Imaginary;
499 ImBis[j] = z.Imaginary;
505 ImC[j] = z.Imaginary;
507 int size = Width * Height;
508 int[] ColorIndex =
new int[size];
513 r0 = rCenter - rDelta;
514 r1 = rCenter + rDelta;
516 aspect = ((double)Width) / Height;
518 i0 = iCenter - rDelta / aspect;
519 i1 = iCenter + rDelta / aspect;
521 dr = (r1 - r0) / Width;
522 di = (i1 - i0) / Height;
524 for (y = 0, i = i0, index = 0; y < Height; y++, i += di)
526 for (x = 0, r = r0; x < Width; x++, r += dr)
536 for (j = 0; j <= c; j++)
538 Temp = zr2 * zr - zi2 * zi + ReC[j];
539 zi2 = zr2 * zi + zi2 * zr + ImC[j];
545 for (j = 0; j < c; j++)
547 Temp = zr3 * zr - zi3 * zi + RePrim[j];
548 zi3 = zr3 * zi + zi3 * zr + ImPrim[j];
554 for (j = 0; j < c2; j++)
556 Temp = zr4 * zr - zi4 * zi + ReBis[j];
557 zi4 = zr4 * zi + zi4 * zr + ImBis[j];
563 zr5 = 2 * (zr2 * zr3 - zi2 * zi3);
564 zi5 = 2 * (zr2 * zi3 + zi2 * zr3);
568 zr6 = 2 * (zr3 * zr3 - zi3 * zi3) - (zr2 * zr4 - zi2 * zi4);
569 zi6 = 4 * zr3 * zi3 - (zr2 * zi4 + zr4 * zi2);
573 Temp = 1.0 / (zr6 * zr6 + zi6 * zi6);
574 zr4 = (zr5 * zr6 + zi5 * zi6) * Temp;
575 zi4 = (zi5 * zr6 - zr5 * zi6) * Temp;
578 Temp = zr4 * RRe - zi4 * RIm;
579 zi4 = zr4 * RIm + zi4 * RRe;
585 Temp = Math.Sqrt(zr4 * zr4 + zi4 * zi4);
587 while ((Temp > Conv) && (Temp < Div) && (n++ < N));
589 if (Temp < Conv && n < N)
590 ColorIndex[index++] = n;
592 ColorIndex[index++] = N;
607 ScriptNode Node, FractalZoomScript FractalZoomScript,
object State)
610 double RIm = R.Imaginary;
611 double r0, i0, r1, i1;
623 string ParameterName;
625 !(Differentiable.Differentiate(ParameterName = Differentiable.DefaultVariableName, v) is
ILambdaExpression fPrim))
636 int size = Width * Height;
637 int[] ColorIndex =
new int[size];
654 r0 = rCenter - rDelta;
655 r1 = rCenter + rDelta;
657 aspect = ((double)Width) / Height;
659 i0 = iCenter - rDelta / aspect;
660 i1 = iCenter + rDelta / aspect;
662 dr = (r1 - r0) / Width;
663 di = (i1 - i0) / Height;
665 for (y = 0, i = i0; y < Height; y++, i += di)
667 Row =
new Complex[Width];
668 Offset =
new int[Width];
671 for (x = 0, x2 = y * Width, r = r0; x < Width; x++, r += dr, x2++)
673 Row[x] =
new Complex(r, i);
678 while (n < N && c > 0)
683 Obj2 = fPrim.Evaluate(P, v);
684 Obj3 = fBis.Evaluate(P, v);
685 Row2 = Obj.AssociatedObjectValue as Complex[];
686 Row3 = Obj2.AssociatedObjectValue as Complex[];
687 Row4 = Obj3.AssociatedObjectValue as Complex[];
689 if (Row2 is
null || Row3 is
null || Row4 is
null)
691 throw new ScriptRuntimeException(
"Lambda expression (and its first and second derivative) must be able to accept complex vectors, " +
692 "and return complex vectors of equal length. Type returned: " +
693 Obj.GetType().FullName +
", " + Obj2.GetType().FullName +
" and " + Obj3.GetType().FullName,
696 else if (Row2.Length != c || Row3.Length != c)
698 throw new ScriptRuntimeException(
"Lambda expression (and its first and second derivative) must be able to accept complex vectors, " +
699 "and return complex vectors of equal length. Length returned: " +
700 Row2.Length.ToString() +
", " + Row3.Length.ToString() +
" and " + Row4.Length.ToString() +
701 ". Expected: " + c.ToString(), Node);
704 for (x = x2 = 0; x < c; x++)
711 z = R2 * z * z2 / (2 * z2 * z2 - z * z3);
716 if (Mod > Conv && Mod < Div)
734 Array.Resize(ref Row, x2);
735 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
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.