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 HalleySmoothFractal() must be of one variable.",
this);
189 fDef = this.Arguments[i++];
194 " in call to HalleySmoothFractal 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 HalleySmoothFractal(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))
242 return CalcHalley(rc, ic, dr, R, CoefficientsZ, Palette, dimx, dimy,
244 new object[] { Palette, dimx, dimy, R, CoefficientsZ, ColorExpression });
248 return CalcHalley(rc, ic, dr, R, Coefficients, Palette, dimx, dimy,
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;
258 int DimX = (int)Parameters[1];
259 int DimY = (int)Parameters[2];
260 Complex R = (Complex)Parameters[3];
261 string ColorExpression = (string)Parameters[5];
263 StringBuilder sb =
new StringBuilder();
265 sb.Append(
"HalleySmoothFractal((");
276 sb.Append(fDef.SubExpression);
277 else if (Parameters[4] is Complex[] CoefficientsZ)
279 else if (Parameters[4] is
double[] Coefficients)
282 if (!
string.IsNullOrEmpty(ColorExpression))
285 sb.Append(ColorExpression);
289 sb.Append(DimX.ToString());
291 sb.Append(DimY.ToString());
294 return sb.ToString();
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 double[] ColorIndex =
new double[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;
442 FractalZoomScript FractalZoomScript,
object State)
445 double RIm = R.Imaginary;
446 double r0, i0, r1, i1;
449 double zr, zi, zr2, zi2, zr3, zi3, zr4, zi4, zr5, zi5, zr6, zi6;
455 int Degree = Coefficients.Length - 1;
461 Array.Resize(ref Coefficients, 4);
463 Coefficients[++Degree] = Complex.Zero;
466 Complex[] Prim =
new Complex[Degree];
467 for (x = 1; x <= Degree; x++)
468 Prim[x - 1] = x * Coefficients[x];
470 Complex[] Bis =
new Complex[Degree - 1];
471 for (x = 1; x < Degree; x++)
472 Bis[x - 1] = x * Prim[x];
476 Coefficients = (Complex[])Coefficients.Clone();
477 Array.Reverse(Coefficients);
479 int j, c = Prim.Length;
481 double[] ReC =
new double[c + 1];
482 double[] ImC =
new double[c + 1];
483 double[] RePrim =
new double[c];
484 double[] ImPrim =
new double[c];
485 double[] ReBis =
new double[c2];
486 double[] ImBis =
new double[c2];
489 for (j = 0; j < c; j++)
493 ImC[j] = z.Imaginary;
497 ImPrim[j] = z.Imaginary;
503 ImBis[j] = z.Imaginary;
509 ImC[j] = z.Imaginary;
511 int size = Width * Height;
512 double[] ColorIndex =
new double[size];
517 r0 = rCenter - rDelta;
518 r1 = rCenter + rDelta;
520 aspect = ((double)Width) / Height;
522 i0 = iCenter - rDelta / aspect;
523 i1 = iCenter + rDelta / aspect;
525 dr = (r1 - r0) / Width;
526 di = (i1 - i0) / Height;
528 for (y = 0, i = i0, index = 0; y < Height; y++, i += di)
530 for (x = 0, r = r0; x < Width; x++, r += dr)
540 for (j = 0; j <= c; j++)
542 Temp = zr2 * zr - zi2 * zi + ReC[j];
543 zi2 = zr2 * zi + zi2 * zr + ImC[j];
549 for (j = 0; j < c; j++)
551 Temp = zr3 * zr - zi3 * zi + RePrim[j];
552 zi3 = zr3 * zi + zi3 * zr + ImPrim[j];
558 for (j = 0; j < c2; j++)
560 Temp = zr4 * zr - zi4 * zi + ReBis[j];
561 zi4 = zr4 * zi + zi4 * zr + ImBis[j];
567 zr5 = 2 * (zr2 * zr3 - zi2 * zi3);
568 zi5 = 2 * (zr2 * zi3 + zi2 * zr3);
572 zr6 = 2 * (zr3 * zr3 - zi3 * zi3) - (zr2 * zr4 - zi2 * zi4);
573 zi6 = 4 * zr3 * zi3 - (zr2 * zi4 + zr4 * zi2);
577 Temp = 1.0 / (zr6 * zr6 + zi6 * zi6);
578 zr4 = (zr5 * zr6 + zi5 * zi6) * Temp;
579 zi4 = (zi5 * zr6 - zr5 * zi6) * Temp;
582 Temp = zr4 * RRe - zi4 * RIm;
583 zi4 = zr4 * RIm + zi4 * RRe;
589 Temp = Math.Sqrt(zr4 * zr4 + zi4 * zi4);
591 while ((Temp > Conv) && (Temp < Div) && (n++ < N));
593 if (Temp < Conv && n < N)
594 ColorIndex[index++] = n;
596 ColorIndex[index++] = N;
614 ScriptNode Node, FractalZoomScript FractalZoomScript,
object State)
617 double RIm = R.Imaginary;
618 double r0, i0, r1, i1;
630 string ParameterName;
632 !(Differentiable.Differentiate(ParameterName = Differentiable.DefaultVariableName, v) is
ILambdaExpression fPrim))
643 int size = Width * Height;
644 double[] ColorIndex =
new double[size];
661 r0 = rCenter - rDelta;
662 r1 = rCenter + rDelta;
664 aspect = ((double)Width) / Height;
666 i0 = iCenter - rDelta / aspect;
667 i1 = iCenter + rDelta / aspect;
669 dr = (r1 - r0) / Width;
670 di = (i1 - i0) / Height;
672 for (y = 0, i = i0; y < Height; y++, i += di)
674 Row =
new Complex[Width];
675 Offset =
new int[Width];
678 for (x = 0, x2 = y * Width, r = r0; x < Width; x++, r += dr, x2++)
680 Row[x] =
new Complex(r, i);
685 while (n < N && c > 0)
690 Obj2 = fPrim.Evaluate(P, v);
691 Obj3 = fBis.Evaluate(P, v);
692 Row2 = Obj.AssociatedObjectValue as Complex[];
693 Row3 = Obj2.AssociatedObjectValue as Complex[];
694 Row4 = Obj3.AssociatedObjectValue as Complex[];
696 if (Row2 is
null || Row3 is
null || Row4 is
null)
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. Type returned: " +
700 Obj.GetType().FullName +
", " + Obj2.GetType().FullName +
" and " + Obj3.GetType().FullName,
703 else if (Row2.Length != c || Row3.Length != c)
705 throw new ScriptRuntimeException(
"Lambda expression (and its first and second derivative) must be able to accept complex vectors, " +
706 "and return complex vectors of equal length. Length returned: " +
707 Row2.Length.ToString() +
", " + Row3.Length.ToString() +
" and " + Row4.Length.ToString() +
708 ". Expected: " + c.ToString(), Node);
711 for (x = x2 = 0; x < c; x++)
718 z = R2 * z * z2 / (2 * z2 * z2 - z * z3);
723 if (Mod > Conv && Mod < Div)
741 Array.Resize(ref Row, x2);
742 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 Smooth Fractal Image
HalleySmoothFractal(ScriptNode z, ScriptNode dr, ScriptNode R, ScriptNode Coefficients, ScriptNode Palette, int Start, int Length, Expression Expression)
TODO
HalleySmoothFractal(ScriptNode z, ScriptNode dr, ScriptNode R, ScriptNode Coefficients, int Start, int Length, Expression Expression)
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
HalleySmoothFractal(ScriptNode z, ScriptNode dr, int Start, int Length, Expression Expression)
TODO
override string[] DefaultArgumentNames
TODO
HalleySmoothFractal(ScriptNode z, ScriptNode dr, ScriptNode R, int Start, int Length, Expression Expression)
TODO
HalleySmoothFractal(ScriptNode z, ScriptNode dr, ScriptNode R, ScriptNode Coefficients, ScriptNode Palette, ScriptNode DimX, int Start, int Length, Expression Expression)
TODO
static FractalGraph CalcHalley(double rCenter, double iCenter, double rDelta, Complex R, double[] Coefficients, SKColor[] Palette, int Width, int Height, ScriptNode Node, Variables Variables, FractalZoomScript FractalZoomScript, object State)
TODO
static FractalGraph CalcHalley(double rCenter, double iCenter, double rDelta, Complex R, Complex[] Coefficients, SKColor[] Palette, int Width, int Height, ScriptNode Node, Variables Variables, FractalZoomScript FractalZoomScript, object State)
TODO
HalleySmoothFractal(ScriptNode z, ScriptNode dr, ScriptNode R, ScriptNode Coefficients, 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
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
static void Smooth(double[] ColorIndex, double[] Boundary, int Width, int Height, int N, SKColor[] Palette, ScriptNode Node, Variables Variables)
TODO
Handles bitmap-based graphs.
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 Preview(Expression Expression, IElement Result)
Reports a preview of the final result.
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.