43 : base(new
ScriptNode[] { z, c, dr, Palette, DimX, DimY },
54 : base(new
ScriptNode[] { z, c, dr, Palette, DimX },
86 return new string[] {
"z",
"c",
"dr",
"Palette",
"DimX",
"DimY" };
95 string ColorExpression =
null;
108 Obj =
Arguments[i++].AssociatedObjectValue;
109 if (Obj is Complex z)
123 Obj =
Arguments[i++].AssociatedObjectValue;
127 throw new ScriptRuntimeException(
"Lambda expression in calls to JuliaInternalFractal() must be of one variable.",
this);
131 fDef = this.Arguments[i - 1];
133 else if (Obj is Complex z2)
154 ColorExpression = this.Arguments[i].SubExpression;
159 Palette = ColorModels.RandomLinearAnalogousHSL.CreatePalette(16, 4, out
int Seed,
this,
Variables);
160 ColorExpression =
"RandomLinearAnalogousHSL(16,4," + Seed.ToString() +
")";
162 if (i < c && this.Arguments[i] is
null)
178 throw new ScriptRuntimeException(
"Parameter mismatch in call to JuliaInternalFractal(z,c|f,dr[,Palette][,dimx[,dimy]]).",
182 if (dimx <= 0 || dimx > 5000 || dimy <= 0 || dimy > 5000)
187 return CalcJulia(rc, ic, f, fDef, dr, Palette, dimx, dimy,
this,
Variables,
188 this.FractalZoomScript,
new object[] { Palette, dimx, dimy, r0, i0, ColorExpression, fDef });
192 return CalcJulia(
Variables, rc, ic, r0, i0, dr, Palette, dimx, dimy,
this,
193 this.FractalZoomScript,
new object[] { Palette, dimx, dimy, r0, i0, ColorExpression, fDef });
197 private string FractalZoomScript(
double r,
double i,
double Size,
object State)
199 object[] Parameters = (
object[])State;
200 int DimX = (int)Parameters[1];
201 int DimY = (int)Parameters[2];
202 double r0 = (double)Parameters[3];
203 double i0 = (double)Parameters[4];
204 string ColorExpression = (string)Parameters[5];
207 StringBuilder sb =
new StringBuilder();
209 sb.Append(
"JuliaInternalFractal((");
229 if (!
string.IsNullOrEmpty(ColorExpression))
232 sb.Append(ColorExpression);
236 sb.Append(DimX.ToString());
238 sb.Append(DimY.ToString());
241 return sb.ToString();
248 SKColor[] Palette,
int Width,
int Height,
ScriptNode Node, FractalZoomScript FractalZoomScript,
object State)
253 double r0, i0, r1, i1;
256 double zr, zi, zrt, zr2, zi2;
265 greens =
new byte[N];
268 for (x = 0; x < N; x++)
272 greens[x] = cl.Green;
276 int size = Width * Height * 4;
277 byte[] rgb =
new byte[size];
280 r0 = rCenter - rDelta;
281 r1 = rCenter + rDelta;
283 aspect = ((double)Width) / Height;
285 i0 = iCenter - rDelta / aspect;
286 i1 = iCenter + rDelta / aspect;
288 dr = (r1 - r0) / Width;
289 di = (i1 - i0) / Height;
291 for (y = 0, i = i0, index = 0; y < Height; y++, i += di)
293 for (x = 0, r = r0; x < Width; x++, r += dr)
302 while (zr2 + zi2 < 9 && n < N)
305 zrt = zr2 - zi2 + R0;
306 zi = 2 * zr * zi + I0;
313 n = (int)(N * Math.Sqrt((zr2 + zi2) / 9) + 0.5);
316 rgb[index++] = blues[n];
317 rgb[index++] = greens[n];
318 rgb[index++] = reds[n];
332 return new FractalGraph(
Variables, Pixels, r0, i0, r1, i1, rDelta * 2,
true, Node,
FractalZoomScript, State);
340 FractalZoomScript FractalZoomScript,
object State)
345 double r0, i0, r1, i1;
355 greens =
new byte[N];
358 for (x = 0; x < N; x++)
362 greens[x] = cl.Green;
366 int size = Width * Height * 4;
367 byte[] rgb =
new byte[size];
374 r0 = rCenter - rDelta;
375 r1 = rCenter + rDelta;
377 int[] Counts =
new int[N];
379 aspect = ((double)Width) / Height;
381 i0 = iCenter - rDelta / aspect;
382 i1 = iCenter + rDelta / aspect;
384 dr = (r1 - r0) / Width;
385 di = (i1 - i0) / Height;
387 for (y = 0, i = i0; y < Height; y++, i += di)
389 Complex[] Row =
new Complex[Width];
390 int[] Offset =
new int[Width];
393 for (x = 0, x2 = y * Width * 4, r = r0; x < Width; x++, r += dr, x2 += 4)
395 Row[x] =
new Complex(r, i);
403 while (n < N && c > 0)
408 Row = Obj.AssociatedObjectValue as Complex[];
413 "and return complex vectors of equal length. Type returned: " +
414 Obj.GetType().FullName, Node);
416 else if (Row.Length != c)
419 "and return complex vectors of equal length. Length returned: " +
420 Row.Length.ToString() +
". Expected: " + c.ToString(), Node);
423 for (x = x2 = 0; x < c; x++)
451 Array.Resize(ref Row, x2);
452 Array.Resize(ref Offset, x2);
459 for (x = 0; x < c; x++)
465 n = (int)(N * Mod / 3 + 0.5);
471 rgb[j++] = greens[n];
490 return new FractalGraph(
Variables, Pixels, r0, i0, r1, i1, rDelta * 2,
true, Node,
FractalZoomScript, State);
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
JuliaInternalFractal(ScriptNode z, ScriptNode c, ScriptNode dr, ScriptNode Palette, int Start, int Length, Expression Expression)
TODO
override IElement Evaluate(IElement[] Arguments, Variables Variables)
TODO
JuliaInternalFractal(ScriptNode z, ScriptNode c, ScriptNode dr, int Start, int Length, Expression Expression)
TODO
override string FunctionName
TODO
JuliaInternalFractal(ScriptNode z, ScriptNode c, ScriptNode dr, ScriptNode Palette, ScriptNode DimX, int Start, int Length, Expression Expression)
TODO
JuliaInternalFractal(ScriptNode z, ScriptNode c, ScriptNode dr, ScriptNode Palette, ScriptNode DimX, ScriptNode DimY, int Start, int Length, Expression Expression)
TODO
static FractalGraph CalcJulia(double rCenter, double iCenter, ILambdaExpression f, ScriptNode _, double rDelta, SKColor[] Palette, int Width, int Height, ScriptNode Node, Variables Variables, FractalZoomScript FractalZoomScript, object State)
TODO
override string[] DefaultArgumentNames
TODO
static FractalGraph CalcJulia(Variables Variables, double rCenter, double iCenter, double R0, double I0, double rDelta, SKColor[] Palette, int Width, int Height, ScriptNode Node, FractalZoomScript FractalZoomScript, object State)
TODO
Defines a clickable fractal graph in the complex plane.
static SKColor[] ToPalette(ObjectVector Vector)
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.
string SubExpression
Sub-expression defining the node.
Expression Expression
Expression of which the node is a part.
int Start
Start position in script expression.
TextWriter ConsoleOut
Console out interface. Can be used by functions and script to output data to the console.
void CopyTo(Variables Variables)
Copies available variables to another variable collection.
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.