4using System.Threading.Tasks;
44 : base(new
ScriptNode[] { z, c, dr, Palette, DimX, DimY },
55 : base(new
ScriptNode[] { z, c, dr, Palette, DimX },
87 return new string[] {
"z",
"c",
"dr",
"Palette",
"DimX",
"DimY" };
110 string ColorExpression =
null;
124 Obj =
Arguments[i++].AssociatedObjectValue;
125 if (Obj is Complex z)
140 Obj =
Arguments[i++].AssociatedObjectValue;
144 throw new ScriptRuntimeException(
"Lambda expression in calls to JuliaSmoothFractal() must be of one variable.",
this);
148 fDef = this.Arguments[i - 1];
150 else if (Obj is Complex z2)
173 ColorExpression = this.Arguments[i].SubExpression;
178 Palette = ColorModels.RandomLinearAnalogousHSL.CreatePalette(1024, 16, out
int Seed,
this,
Variables);
179 ColorExpression =
"RandomLinearAnalogousHSL(1024,16," + Seed.ToString() +
")";
181 if (i < c && this.Arguments[i] is
null)
197 throw new ScriptRuntimeException(
"Parameter mismatch in call to JuliaSmoothFractal(z,c|f,dr[,Palette][,dimx[,dimy]]).",
201 if (dimx <= 0 || dimx > 5000 || dimy <= 0 || dimy > 5000)
207 this.FractalZoomScript,
new object[] { Palette, dimx, dimy, r0, i0, ColorExpression, fDef });
211 return await
CalcJulia(rc, ic, r0, i0, dr, Palette, dimx, dimy,
this,
Variables,
212 this.FractalZoomScript,
new object[] { Palette, dimx, dimy, r0, i0, ColorExpression, fDef });
216 private string FractalZoomScript(
double r,
double i,
double Size,
object State)
218 object[] Parameters = (
object[])State;
219 int DimX = (int)Parameters[1];
220 int DimY = (int)Parameters[2];
221 double r0 = (double)Parameters[3];
222 double i0 = (double)Parameters[4];
223 string ColorExpression = (string)Parameters[5];
226 StringBuilder sb =
new StringBuilder();
228 sb.Append(
"JuliaSmoothFractal((");
248 if (!
string.IsNullOrEmpty(ColorExpression))
251 sb.Append(ColorExpression);
255 sb.Append(DimX.ToString());
257 sb.Append(DimY.ToString());
260 return sb.ToString();
266 public static async Task<FractalGraph>
CalcJulia(
double rCenter,
double iCenter,
double R0,
double I0,
double rDelta,
268 FractalZoomScript FractalZoomScript,
object State)
270 double r0, i0, r1, i1;
273 double zr, zi, zrt, zr2, zi2;
282 r0 = rCenter - rDelta;
283 r1 = rCenter + rDelta;
285 aspect = ((double)Width) / Height;
287 i0 = iCenter - rDelta / aspect;
288 i1 = iCenter + rDelta / aspect;
290 dr = (r1 - r0) / Width;
291 di = (i1 - i0) / Height;
293 int Size = Width * Height;
294 double[] ColorIndex =
new double[Size];
296 for (y = 0, i = i0, index = 0; y < Height; y++, i += di)
298 for (x = 0, r = r0; x < Width; x++, r += dr)
307 while (zr2 + zi2 < 9 && n < N)
310 zrt = zr2 - zi2 + R0;
311 zi = 2 * zr * zi + I0;
319 ColorIndex[index++]=N;
321 ColorIndex[index++]=n;
338 double rDelta, SKColor[] Palette,
int Width,
int Height,
ScriptNode Node,
341 double r0, i0, r1, i1;
351 r0 = rCenter - rDelta;
352 r1 = rCenter + rDelta;
354 aspect = ((double)Width) / Height;
356 i0 = iCenter - rDelta / aspect;
357 i1 = iCenter + rDelta / aspect;
359 dr = (r1 - r0) / Width;
360 di = (i1 - i0) / Height;
362 int Size = Width * Height;
363 double[] ColorIndex =
new double[Size];
370 for (y = 0, i = i0; y < Height; y++, i += di)
372 Complex[] Row =
new Complex[Width];
373 int[] Offset =
new int[Width];
376 for (x = 0, x2 = y * Width, r = r0; x < Width; x++, r += dr, x2++)
378 Row[x] =
new Complex(r, i);
383 while (n < N && c > 0)
388 Row = Obj.AssociatedObjectValue as Complex[];
392 else if (Row.Length != c)
395 for (x = x2 = 0; x < c; x++)
418 Array.Resize(ref Row, x2);
419 Array.Resize(ref Offset, x2);
426 for (x = 0; x < c; x++)
Script runtime exception.
Class managing a script expression.
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 Julia set Fractal Image
JuliaSmoothFractal(ScriptNode z, ScriptNode c, ScriptNode dr, ScriptNode Palette, ScriptNode DimX, ScriptNode DimY, int Start, int Length, Expression Expression)
TODO
override string[] DefaultArgumentNames
TODO
override IElement Evaluate(IElement[] Arguments, Variables Variables)
TODO
override string FunctionName
TODO
JuliaSmoothFractal(ScriptNode z, ScriptNode c, ScriptNode dr, int Start, int Length, Expression Expression)
TODO
override async Task< IElement > EvaluateAsync(IElement[] Arguments, Variables Variables)
TODO
JuliaSmoothFractal(ScriptNode z, ScriptNode c, ScriptNode dr, ScriptNode Palette, ScriptNode DimX, int Start, int Length, Expression Expression)
TODO
JuliaSmoothFractal(ScriptNode z, ScriptNode c, ScriptNode dr, ScriptNode Palette, int Start, int Length, Expression Expression)
TODO
override bool IsAsynchronous
If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluat...
static async Task< FractalGraph > CalcJulia(double rCenter, double iCenter, ILambdaExpression f, double rDelta, SKColor[] Palette, int Width, int Height, ScriptNode Node, Variables Variables, FractalZoomScript FractalZoomScript, object State)
TODO
static async Task< FractalGraph > CalcJulia(double rCenter, double iCenter, double R0, double I0, double rDelta, SKColor[] Palette, int Width, int Height, ScriptNode Node, Variables Variables, FractalZoomScript FractalZoomScript, object State)
TODO
Exception thrown if an image with invalid size is requested.
Exception thrown if a lambda expression with invalid type is encountered.
Exception thrown if a lambda expression with invalid type is encountered.
Defines a clickable fractal graph in the complex plane.
static async Task Smooth(double[] ColorIndex, double[] Boundary, int Width, int Height, int N, SKColor[] Palette, ScriptNode Node, Variables Variables)
TODO
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
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.
string SubExpression
Sub-expression defining the node.
Expression Expression
Expression of which the node is a part.
int Start
Start position in script expression.
async Task Preview(Expression Expression, IElement Result)
Reports a preview of the final result.
Basic interface for all types of elements.
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.