55 : base(new
ScriptNode[] { z, dr, R, c, Palette, DimX, DimY },
67 : base(new
ScriptNode[] { z, dr, R, c, Palette, DimX },
79 : base(new
ScriptNode[] { z, dr, R, c, Palette },
93 ArgumentType.Normal },
105 return new string[] {
"z",
"dr",
"R",
"c",
"Palette",
"DimX",
"DimY" };
114 string ColorExpression =
null;
116 double[] Coefficients =
null;
117 Complex[] CoefficientsZ =
null;
128 Obj =
Arguments[i++].AssociatedObjectValue;
129 if (Obj is Complex z)
145 if (i < c && ((Obj =
Arguments[i].AssociatedObjectValue) is
double || Obj is Complex))
154 if (i < c && this.Arguments[i] is
null)
161 Coefficients = (
double[])
Arguments[i++].AssociatedObjectValue;
163 CoefficientsZ = (Complex[])
Arguments[i++].AssociatedObjectValue;
173 CoefficientsZ =
new Complex[d];
174 for (j = 0; j < d; j++)
181 throw new ScriptRuntimeException(
"Lambda expression in calls to NewtonSmoothFractal() must be of one variable.",
this);
183 fDef = this.Arguments[i++];
188 " in call to NewtonSmoothFractal has to be a vector of numbers, containing coefficients " +
189 "of the polynomial to use. Now it was of type " +
Arguments[i].GetType().FullName,
198 ColorExpression = this.Arguments[i].SubExpression;
203 Palette = ColorModels.RandomLinearAnalogousHSL.CreatePalette(128, 4, out
int Seed,
this,
Variables);
204 ColorExpression =
"RandomLinearAnalogousHSL(128,4," + Seed.ToString() +
")";
206 if (i < c && this.Arguments[i] is
null)
222 throw new ScriptRuntimeException(
"Parameter mismatch in call to NewtonSmoothFractal(r,c,dr,Coefficients[,Palette][,dimx[,dimy]]).",
226 if (dimx <= 0 || dimx > 5000 || dimy <= 0 || dimy > 5000)
231 return CalcNewtonSmooth(rc, ic, dr, R, f,
Variables, Palette, dimx, dimy,
this, this.FractalZoomScript,
232 new object[] { Palette, dimx, dimy, R, fDef, ColorExpression });
234 else if (!(CoefficientsZ is
null))
238 new object[] { Palette, dimx, dimy, R, CoefficientsZ, ColorExpression });
244 new object[] { Palette, dimx, dimy, R, Coefficients, ColorExpression });
248 private string FractalZoomScript(
double r,
double i,
double Size,
object State)
250 object[] Parameters = (
object[])State;
251 int DimX = (int)Parameters[1];
252 int DimY = (int)Parameters[2];
253 Complex R = (Complex)Parameters[3];
254 double[] Coefficients = Parameters[4] as
double[];
255 string ColorExpression = (string)Parameters[5];
257 StringBuilder sb =
new StringBuilder();
259 sb.Append(
"NewtonSmoothFractal((");
270 sb.Append(fDef.SubExpression);
271 else if (Parameters[4] is Complex[] CoefficientsZ)
276 if (!
string.IsNullOrEmpty(ColorExpression))
279 sb.Append(ColorExpression);
283 sb.Append(DimX.ToString());
285 sb.Append(DimY.ToString());
288 return sb.ToString();
296 FractalZoomScript FractalZoomScript,
object State)
299 double RIm = R.Imaginary;
300 double r0, i0, r1, i1;
303 double zr, zi, zr2, zi2, zr3, zi3, zr4, zi4;
308 int Degree = Coefficients.Length - 1;
314 Array.Resize(ref Coefficients, 3);
316 Coefficients[++Degree] = 0;
319 if (Width <= 2 || Height <= 2)
322 double[] Prim =
new double[Degree];
323 for (x = 1; x <= Degree; x++)
324 Prim[x - 1] = x * Coefficients[x];
327 Coefficients = (
double[])Coefficients.Clone();
328 Array.Reverse(Coefficients);
330 int Size = Width * Height;
333 double[] ColorIndex =
new double[Size];
337 r0 = rCenter - rDelta;
338 r1 = rCenter + rDelta;
340 aspect = ((double)Width) / Height;
342 i0 = iCenter - rDelta / aspect;
343 i1 = iCenter + rDelta / aspect;
345 dr = (r1 - r0) / Width;
346 di = (i1 - i0) / Height;
348 for (y = 0, i = i0; y < Height; y++, i += di)
350 for (x = 0, r = r0; x < Width; x++, r += dr)
360 foreach (
double C
in Coefficients)
362 Temp = zr2 * zr - zi2 * zi + C;
363 zi2 = zr2 * zi + zi2 * zr;
369 foreach (
double C
in Prim)
371 Temp = zr3 * zr - zi3 * zi + C;
372 zi3 = zr3 * zi + zi3 * zr;
378 Temp = 1.0 / (zr3 * zr3 + zi3 * zi3);
379 zr4 = (zr2 * zr3 + zi2 * zi3) * Temp;
380 zi4 = (zi2 * zr3 - zr2 * zi3) * Temp;
383 Temp = zr4 * RRe - zi4 * RIm;
384 zi4 = zr4 * RIm + zi4 * RRe;
390 Temp = Math.Sqrt(zr4 * zr4 + zi4 * zi4);
392 while ((Temp > Conv) && (Temp < Div) && (n++ < N));
394 if (Temp < Conv && n < N)
395 ColorIndex[Index++] = n;
397 ColorIndex[Index++] = N;
415 FractalZoomScript FractalZoomScript,
object State)
418 double RIm = R.Imaginary;
419 double r0, i0, r1, i1;
422 double zr, zi, zr2, zi2, zr3, zi3, zr4, zi4;
427 int Degree = Coefficients.Length - 1;
433 Array.Resize(ref Coefficients, 3);
435 Coefficients[++Degree] = Complex.Zero;
438 if (Width <= 2 || Height <= 2)
441 Complex[] Prim =
new Complex[Degree];
442 for (x = 1; x <= Degree; x++)
443 Prim[x - 1] = x * Coefficients[x];
446 Coefficients = (Complex[])Coefficients.Clone();
447 Array.Reverse(Coefficients);
449 int j, c = Prim.Length;
450 double[] ReC =
new double[c + 1];
451 double[] ImC =
new double[c + 1];
452 double[] RePrim =
new double[c];
453 double[] ImPrim =
new double[c];
456 for (j = 0; j < c; j++)
460 ImC[j] = z.Imaginary;
464 ImPrim[j] = z.Imaginary;
469 ImC[j] = z.Imaginary;
471 int Size = Width * Height;
474 double[] ColorIndex =
new double[Size];
478 r0 = rCenter - rDelta;
479 r1 = rCenter + rDelta;
481 aspect = ((double)Width) / Height;
483 i0 = iCenter - rDelta / aspect;
484 i1 = iCenter + rDelta / aspect;
486 dr = (r1 - r0) / Width;
487 di = (i1 - i0) / Height;
489 for (y = 0, i = i0; y < Height; y++, i += di)
491 for (x = 0, r = r0; x < Width; x++, r += dr)
501 for (j = 0; j <= c; j++)
503 Temp = zr2 * zr - zi2 * zi + ReC[j];
504 zi2 = zr2 * zi + zi2 * zr + ImC[j];
510 for (j = 0; j < c; j++)
512 Temp = zr3 * zr - zi3 * zi + RePrim[j];
513 zi3 = zr3 * zi + zi3 * zr + ImPrim[j];
519 Temp = 1.0 / (zr3 * zr3 + zi3 * zi3);
520 zr4 = (zr2 * zr3 + zi2 * zi3) * Temp;
521 zi4 = (zi2 * zr3 - zr2 * zi3) * Temp;
524 Temp = zr4 * RRe - zi4 * RIm;
525 zi4 = zr4 * RIm + zi4 * RRe;
531 Temp = Math.Sqrt(zr4 * zr4 + zi4 * zi4);
533 while ((Temp > Conv) && (Temp < Div) && (n++ < N));
535 if (Temp < Conv && n < N)
536 ColorIndex[Index++] = n;
538 ColorIndex[Index++] = N;
556 ScriptNode Node, FractalZoomScript FractalZoomScript,
object State)
559 double RIm = R.Imaginary;
560 double r0, i0, r1, i1;
569 if (Width <= 2 || Height <= 2)
576 !(Differentiable.Differentiate(Differentiable.DefaultVariableName, v) is
ILambdaExpression fPrim))
581 int Size = Width * Height;
584 double[] ColorIndex =
new double[Size];
598 r0 = rCenter - rDelta;
599 r1 = rCenter + rDelta;
601 aspect = ((double)Width) / Height;
603 i0 = iCenter - rDelta / aspect;
604 i1 = iCenter + rDelta / aspect;
606 dr = (r1 - r0) / Width;
607 di = (i1 - i0) / Height;
609 for (y = 0, i = i0; y < Height; y++, i += di)
611 Row =
new Complex[Width];
612 Offset =
new int[Width];
615 for (x = 0, x2 = y * Width, r = r0; x < Width; x++, r += dr, x2++)
617 Row[x] =
new Complex(r, i);
622 while (n < N && c > 0)
627 Obj2 = fPrim.Evaluate(P, v);
628 Row2 = Obj.AssociatedObjectValue as Complex[];
629 Row3 = Obj2.AssociatedObjectValue as Complex[];
631 if (Row2 is
null || Row3 is
null)
633 throw new ScriptRuntimeException(
"Lambda expression (and its first derivative) must be able to accept complex vectors, " +
634 "and return complex vectors of equal length. Type returned: " +
635 Obj.GetType().FullName +
" and " + Obj2.GetType().FullName, Node);
637 else if (Row2.Length != c || Row3.Length != c)
639 throw new ScriptRuntimeException(
"Lambda expression (and its first derivative) must be able to accept complex vectors, " +
640 "and return complex vectors of equal length. Length returned: " +
641 Row2.Length.ToString() +
" and " + Row3.Length.ToString() +
642 ". Expected: " + c.ToString(), Node);
645 for (x = x2 = 0; x < c; x++)
648 z = R * Row2[x] / Row3[x];
653 if (Mod > Conv && Mod < Div)
663 ColorIndex[Index++] = N;
671 Array.Resize(ref Row, x2);
672 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 smoothes the colors using the heat equation in two spatial dim...
NewtonSmoothFractal(ScriptNode z, ScriptNode dr, ScriptNode R, ScriptNode c, ScriptNode Palette, ScriptNode DimX, int Start, int Length, Expression Expression)
TODO
NewtonSmoothFractal(ScriptNode z, ScriptNode dr, ScriptNode R, ScriptNode c, int Start, int Length, Expression Expression)
TODO
override IElement Evaluate(IElement[] Arguments, Variables Variables)
TODO
static FractalGraph CalcNewtonSmooth(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
override string FunctionName
TODO
NewtonSmoothFractal(ScriptNode z, ScriptNode dr, ScriptNode R, ScriptNode c, ScriptNode Palette, ScriptNode DimX, ScriptNode DimY, int Start, int Length, Expression Expression)
TODO
override string[] DefaultArgumentNames
TODO
static FractalGraph CalcNewtonSmooth(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
NewtonSmoothFractal(ScriptNode z, ScriptNode dr, ScriptNode R, ScriptNode c, ScriptNode Palette, int Start, int Length, Expression Expression)
TODO
static FractalGraph CalcNewtonSmooth(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
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.