Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
NewtonBasinFractal.cs
1using System;
2using System.Collections.Generic;
3using System.Numerics;
4using System.Text;
5using SkiaSharp;
11
13{
39 {
45 : base(new ScriptNode[] { z, dr, R, c, N, DimX, DimY },
46 new ArgumentType[] { ArgumentType.Scalar, ArgumentType.Scalar, ArgumentType.Scalar,
47 ArgumentType.Normal, ArgumentType.Scalar, ArgumentType.Scalar, ArgumentType.Scalar},
49 {
50 }
51
57 : base(new ScriptNode[] { z, dr, R, c, N, DimX },
58 new ArgumentType[] { ArgumentType.Scalar, ArgumentType.Scalar, ArgumentType.Scalar,
59 ArgumentType.Normal, ArgumentType.Scalar, ArgumentType.Scalar},
61 {
62 }
63
69 : base(new ScriptNode[] { z, dr, R, c, N },
70 new ArgumentType[] { ArgumentType.Scalar, ArgumentType.Scalar, ArgumentType.Scalar,
71 ArgumentType.Normal, ArgumentType.Scalar },
73 {
74 }
75
81 : base(new ScriptNode[] { z, dr, R, c },
82 new ArgumentType[] { ArgumentType.Scalar, ArgumentType.Scalar, ArgumentType.Scalar,
83 ArgumentType.Normal },
85 {
86 }
87
91 public override string[] DefaultArgumentNames
92 {
93 get
94 {
95 return new string[] { "z", "dr", "R", "c", "N", "DimX", "DimY" };
96 }
97 }
98
103 {
104 double[] Coefficients = null;
105 Complex[] CoefficientsZ = null;
106 ILambdaExpression f = null;
107 ScriptNode fDef = null;
108 double rc, ic;
109 double dr;
110 Complex R;
111 int N;
112 int dimx, dimy;
113 int c = Arguments.Length;
114 int i = 0;
115 object Obj;
116
117 Obj = Arguments[i++].AssociatedObjectValue;
118 if (Obj is Complex z)
119 {
120 rc = z.Real;
121 ic = z.Imaginary;
122 }
123 else
124 {
125 rc = Expression.ToDouble(Obj);
126 ic = Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
127 }
128
129 if (i >= c)
130 throw new ScriptRuntimeException("Insufficient parameters in call to NewtonBasinFractal().", this);
131
132 dr = Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
133
134 if (i < c && ((Obj = Arguments[i].AssociatedObjectValue) is double || Obj is Complex))
135 {
136 R = Expression.ToComplex(Obj);
137 i++;
138 }
139 else
140 {
141 R = Complex.One;
142
143 if (i < c && this.Arguments[i] is null)
144 i++;
145 }
146
147 if (i < c)
148 {
149 if (Arguments[i] is DoubleVector)
150 Coefficients = (double[])Arguments[i++].AssociatedObjectValue;
151 else if (Arguments[i] is ComplexVector)
152 CoefficientsZ = (Complex[])Arguments[i++].AssociatedObjectValue;
153 /*else if (Parameters[i] is RealPolynomial)
154 Coefficients = ((RealPolynomial)Arguments[i++].AssociatedObjectValue).Coefficients;
155 else if (Parameters[i] is ComplexPolynomial)
156 CoefficientsZ = ((ComplexPolynomial)Arguments[i++].AssociatedObjectValue).Coefficients;*/
157 else if (Arguments[i] is IVector)
158 {
159 IVector Vector = (IVector)Arguments[i++];
160 int j, d = Vector.Dimension;
161
162 CoefficientsZ = new Complex[d];
163 for (j = 0; j < d; j++)
164 CoefficientsZ[j] = Expression.ToComplex(Vector.GetElement(j).AssociatedObjectValue);
165 }
166 else if (Arguments[i].AssociatedObjectValue is ILambdaExpression)
167 {
169 if (f.NrArguments != 1)
170 throw new ScriptRuntimeException("Lambda expression in calls to NewtonBasinFractal() must be of one variable.", this);
171
172 fDef = this.Arguments[i++];
173 }
174 else
175 {
176 throw new ScriptRuntimeException("Parameter " + (i + 1).ToString() +
177 " in call to NewtonBasinFractal has to be a vector of numbers, containing coefficients " +
178 "of the polynomial to use. Now it was of type " + Arguments[i].GetType().FullName,
179 this);
180 }
181 }
182 else
183 throw new ScriptRuntimeException("Missing coefficients or lambda expression.", this);
184
185 if (i < c)
186 N = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
187 else
188 N = 32;
189
190 if (i < c)
191 dimx = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
192 else
193 dimx = 320;
194
195 if (i < c)
196 dimy = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
197 else
198 dimy = 200;
199
200 if (i < c)
201 {
202 throw new ScriptRuntimeException("Parameter mismatch in call to NewtonBasinFractal(r,c,dr,Coefficients[,Palette][,dimx[,dimy]]).",
203 this);
204 }
205
206 if (dimx <= 0 || dimx > 5000 || dimy <= 0 || dimy > 5000)
207 throw new ScriptRuntimeException("Image size must be within 1x1 to 5000x5000", this);
208
209 if (!(f is null))
210 {
211 return CalcNewton(rc, ic, dr, R, f, fDef, Variables, N, dimx, dimy, this, this.FractalZoomScript,
212 new object[] { dimx, dimy, N, R, fDef });
213 }
214 else if (!(CoefficientsZ is null))
215 {
216 return CalcNewton(Variables, rc, ic, dr, R, CoefficientsZ, N, dimx, dimy, this, this.FractalZoomScript,
217 new object[] { dimx, dimy, N, R, CoefficientsZ });
218 }
219 else
220 {
221 return CalcNewton(Variables, rc, ic, dr, R, Coefficients, N, dimx, dimy, this, this.FractalZoomScript,
222 new object[] { dimx, dimy, N, R, Coefficients });
223 }
224 }
225
226 private string FractalZoomScript(double r, double i, double Size, object State)
227 {
228 object[] Parameters = (object[])State;
229 int DimX = (int)Parameters[0];
230 int DimY = (int)Parameters[1];
231 int N = (int)Parameters[2];
232 Complex R = (Complex)Parameters[3];
233 double[] Coefficients = Parameters[4] as double[];
234
235 StringBuilder sb = new StringBuilder();
236
237 sb.Append("NewtonBasinFractal((");
238 sb.Append(Expression.ToString(r));
239 sb.Append(',');
240 sb.Append(Expression.ToString(i));
241 sb.Append("),");
242 sb.Append(Expression.ToString(Size / 4));
243 sb.Append(',');
244 sb.Append(Expression.ToString(R));
245 sb.Append(',');
246
247 if (Parameters[4] is ScriptNode fDef)
248 sb.Append(fDef.SubExpression);
249 else if (Parameters[4] is Complex[] CoefficientsZ)
250 sb.Append(Expression.ToString(CoefficientsZ));
251 else
252 sb.Append(Expression.ToString(Coefficients));
253
254 sb.Append(',');
255 sb.Append(N.ToString());
256 sb.Append(',');
257 sb.Append(DimX.ToString());
258 sb.Append(',');
259 sb.Append(DimY.ToString());
260 sb.Append(')');
261
262 return sb.ToString();
263 }
264
268 public static FractalGraph CalcNewton(Variables Variables, double rCenter, double iCenter, double rDelta, Complex R,
269 double[] Coefficients, int N, int Width, int Height, ScriptNode Node, FractalZoomScript FractalZoomScript, object State)
270 {
271 double RRe = R.Real;
272 double RIm = R.Imaginary;
273 List<double> AttractorsR = new List<double>();
274 List<double> AttractorsI = new List<double>();
275 List<int> AttractorColors = new List<int>();
276 double[] AttractorsR2 = new double[0];
277 double[] AttractorsI2 = new double[0];
278 int[] AttractorsColors2 = new int[0];
279 double r0, i0, r1, i1;
280 double dr, di;
281 double r, i;
282 double zr, zi, zr2, zi2, zr3, zi3, zr4, zi4;
283 double aspect;
284 double Temp;
285 int x, y, b, c = 0, d;
286 int n;
287 int index;
288 int Degree = Coefficients.Length - 1;
289
290 if (Degree < 2)
291 {
292 Array.Resize(ref Coefficients, 3);
293 while (Degree < 2)
294 Coefficients[++Degree] = 0;
295 }
296
297 double[] Prim = new double[Degree];
298 for (x = 1; x <= Degree; x++)
299 Prim[x - 1] = x * Coefficients[x];
300
301 Array.Reverse(Prim);
302 Coefficients = (double[])Coefficients.Clone();
303 Array.Reverse(Coefficients);
304
305 int size = Width * Height * 4;
306 double Conv = 1e-10;
307 double Div = 1e10;
308 double Conv2 = Conv * 2;
309 byte[] rgb = new byte[size];
310
311 rDelta *= 0.5;
312 r0 = rCenter - rDelta;
313 r1 = rCenter + rDelta;
314
315 aspect = ((double)Width) / Height;
316
317 i0 = iCenter - rDelta / aspect;
318 i1 = iCenter + rDelta / aspect;
319
320 dr = (r1 - r0) / Width;
321 di = (i1 - i0) / Height;
322
323 for (y = 0, i = i0, index = 0; y < Height; y++, i += di)
324 {
325 for (x = 0, r = r0; x < Width; x++, r += dr)
326 {
327 zr = r;
328 zi = i;
329
330 n = 0;
331 do
332 {
333 // f:
334 zr2 = zi2 = 0;
335 foreach (double C in Coefficients)
336 {
337 Temp = zr2 * zr - zi2 * zi + C;
338 zi2 = zr2 * zi + zi2 * zr;
339 zr2 = Temp;
340 }
341
342 // f':
343 zr3 = zi3 = 0;
344 foreach (double C in Prim)
345 {
346 Temp = zr3 * zr - zi3 * zi + C;
347 zi3 = zr3 * zi + zi3 * zr;
348 zr3 = Temp;
349 }
350
351 // f/f':
352
353 Temp = 1.0 / (zr3 * zr3 + zi3 * zi3);
354 zr4 = (zr2 * zr3 + zi2 * zi3) * Temp;
355 zi4 = (zi2 * zr3 - zr2 * zi3) * Temp;
356
357 // R*f/f'
358 Temp = zr4 * RRe - zi4 * RIm;
359 zi4 = zr4 * RIm + zi4 * RRe;
360 zr4 = Temp;
361
362 zr -= zr4;
363 zi -= zi4;
364
365 Temp = Math.Sqrt(zr4 * zr4 + zi4 * zi4);
366 }
367 while ((Temp > Conv) && (Temp < Div) && (n++ < N));
368
369 if (Temp < Conv && n < N)
370 {
371 for (b = 0; b < c; b++)
372 {
373 if (Math.Abs(AttractorsR2[b] - zr) < Conv2 &&
374 Math.Abs(AttractorsI2[b] - zi) < Conv2)
375 {
376 break;
377 }
378 }
379
380 if (b == c)
381 {
382 AttractorsR.Add(zr);
383 AttractorsI.Add(zi);
384
385 int p1 = ~((b % 6) + 1);
386 int p2 = ((b / 6) % 7);
387
388 int Red = (p1 & 1) != 0 ? 255 : 0;
389 int Green = (p1 & 2) != 0 ? 255 : 0;
390 int Blue = (p1 & 4) != 0 ? 255 : 0;
391
392 if ((p2 & 1) != 0)
393 Red >>= 1;
394
395 if ((p2 & 2) != 0)
396 Green >>= 1;
397
398 if ((p2 & 4) != 0)
399 Blue >>= 1;
400
401 Blue <<= 8;
402 Blue |= Green;
403 Blue <<= 8;
404 Blue |= Red;
405
406 AttractorColors.Add(Blue);
407
408 AttractorsR2 = AttractorsR.ToArray();
409 AttractorsI2 = AttractorsI.ToArray();
410 AttractorsColors2 = AttractorColors.ToArray();
411
412 c++;
413 }
414
415 b = AttractorColors[b];
416
417 d = (byte)b;
418 rgb[index++] = (byte)((d * (N - n + 1)) / N);
419 b >>= 8;
420 d = (byte)b;
421 rgb[index++] = (byte)((d * (N - n + 1)) / N);
422 b >>= 8;
423 d = (byte)b;
424 rgb[index++] = (byte)((d * (N - n + 1)) / N);
425 }
426 else
427 {
428 rgb[index++] = 0;
429 rgb[index++] = 0;
430 rgb[index++] = 0;
431 }
432
433 rgb[index++] = 255;
434 }
435 }
436
437 PixelInformation Pixels = new PixelInformationRaw(SKColorType.Bgra8888, rgb, Width, Height, Width << 2);
438 return new FractalGraph(Variables, Pixels, r0, i0, r1, i1, rDelta * 2, true, Node, FractalZoomScript, State);
439 }
440
444 public static FractalGraph CalcNewton(Variables Variables, double rCenter, double iCenter, double rDelta, Complex R,
445 Complex[] Coefficients, int N, int Width, int Height, ScriptNode Node, FractalZoomScript FractalZoomScript, object State)
446 {
447 double RRe = R.Real;
448 double RIm = R.Imaginary;
449 List<double> AttractorsR = new List<double>();
450 List<double> AttractorsI = new List<double>();
451 List<int> AttractorColors = new List<int>();
452 double[] AttractorsR2 = new double[0];
453 double[] AttractorsI2 = new double[0];
454 int[] AttractorsColors2 = new int[0];
455 double r0, i0, r1, i1;
456 double dr, di;
457 double r, i;
458 double zr, zi, zr2, zi2, zr3, zi3, zr4, zi4;
459 double aspect;
460 double Temp;
461 int x, y, b, c = 0, d;
462 int n;
463 int index;
464 int Degree = Coefficients.Length - 1;
465
466 if (Degree < 2)
467 {
468 Array.Resize(ref Coefficients, 3);
469 while (Degree < 2)
470 Coefficients[++Degree] = Complex.Zero;
471 }
472
473 Complex[] Prim = new Complex[Degree];
474 for (x = 1; x <= Degree; x++)
475 Prim[x - 1] = x * Coefficients[x];
476
477 Array.Reverse(Prim);
478 Coefficients = (Complex[])Coefficients.Clone();
479 Array.Reverse(Coefficients);
480
481 int j, e = Prim.Length;
482 double[] ReC = new double[e + 1];
483 double[] ImC = new double[e + 1];
484 double[] RePrim = new double[e];
485 double[] ImPrim = new double[e];
486 Complex z;
487
488 for (j = 0; j < e; j++)
489 {
490 z = Coefficients[j];
491 ReC[j] = z.Real;
492 ImC[j] = z.Imaginary;
493
494 z = Prim[j];
495 RePrim[j] = z.Real;
496 ImPrim[j] = z.Imaginary;
497 }
498
499 z = Coefficients[j];
500 ReC[j] = z.Real;
501 ImC[j] = z.Imaginary;
502
503 int size = Width * Height * 4;
504 double Conv = 1e-10;
505 double Div = 1e10;
506 double Conv2 = Conv * 2;
507 byte[] rgb = new byte[size];
508
509 rDelta *= 0.5;
510 r0 = rCenter - rDelta;
511 r1 = rCenter + rDelta;
512
513 aspect = ((double)Width) / Height;
514
515 i0 = iCenter - rDelta / aspect;
516 i1 = iCenter + rDelta / aspect;
517
518 dr = (r1 - r0) / Width;
519 di = (i1 - i0) / Height;
520
521 for (y = 0, i = i0, index = 0; y < Height; y++, i += di)
522 {
523 for (x = 0, r = r0; x < Width; x++, r += dr)
524 {
525 zr = r;
526 zi = i;
527
528 n = 0;
529 do
530 {
531 // f:
532 zr2 = zi2 = 0;
533 for (j = 0; j <= e; j++)
534 {
535 Temp = zr2 * zr - zi2 * zi + ReC[j];
536 zi2 = zr2 * zi + zi2 * zr + ImC[j];
537 zr2 = Temp;
538 }
539
540 // f':
541 zr3 = zi3 = 0;
542 for (j = 0; j < e; j++)
543 {
544 Temp = zr3 * zr - zi3 * zi + RePrim[j];
545 zi3 = zr3 * zi + zi3 * zr + ImPrim[j];
546 zr3 = Temp;
547 }
548
549 // f/f':
550
551 Temp = 1.0 / (zr3 * zr3 + zi3 * zi3);
552 zr4 = (zr2 * zr3 + zi2 * zi3) * Temp;
553 zi4 = (zi2 * zr3 - zr2 * zi3) * Temp;
554
555 // R*f/f'
556 Temp = zr4 * RRe - zi4 * RIm;
557 zi4 = zr4 * RIm + zi4 * RRe;
558 zr4 = Temp;
559
560 zr -= zr4;
561 zi -= zi4;
562
563 Temp = Math.Sqrt(zr4 * zr4 + zi4 * zi4);
564 }
565 while ((Temp > Conv) && (Temp < Div) && (n++ < N));
566
567 if (Temp < Conv && n < N)
568 {
569 for (b = 0; b < c; b++)
570 {
571 if (Math.Abs(AttractorsR2[b] - zr) < Conv2 &&
572 Math.Abs(AttractorsI2[b] - zi) < Conv2)
573 {
574 break;
575 }
576 }
577
578 if (b == c)
579 {
580 AttractorsR.Add(zr);
581 AttractorsI.Add(zi);
582
583 int p1 = ~((b % 6) + 1);
584 int p2 = ((b / 6) % 7);
585
586 int Red = (p1 & 1) != 0 ? 255 : 0;
587 int Green = (p1 & 2) != 0 ? 255 : 0;
588 int Blue = (p1 & 4) != 0 ? 255 : 0;
589
590 if ((p2 & 1) != 0)
591 Red >>= 1;
592
593 if ((p2 & 2) != 0)
594 Green >>= 1;
595
596 if ((p2 & 4) != 0)
597 Blue >>= 1;
598
599 Blue <<= 8;
600 Blue |= Green;
601 Blue <<= 8;
602 Blue |= Red;
603
604 AttractorColors.Add(Blue);
605
606 AttractorsR2 = AttractorsR.ToArray();
607 AttractorsI2 = AttractorsI.ToArray();
608 AttractorsColors2 = AttractorColors.ToArray();
609
610 c++;
611 }
612
613 b = AttractorColors[b];
614
615 d = (byte)b;
616 rgb[index++] = (byte)((d * (N - n + 1)) / N);
617 b >>= 8;
618 d = (byte)b;
619 rgb[index++] = (byte)((d * (N - n + 1)) / N);
620 b >>= 8;
621 d = (byte)b;
622 rgb[index++] = (byte)((d * (N - n + 1)) / N);
623 }
624 else
625 {
626 rgb[index++] = 0;
627 rgb[index++] = 0;
628 rgb[index++] = 0;
629 }
630
631 rgb[index++] = 255;
632 }
633 }
634
635 PixelInformation Pixels = new PixelInformationRaw(SKColorType.Bgra8888, rgb, Width, Height, Width << 2);
636 return new FractalGraph(Variables, Pixels, r0, i0, r1, i1, rDelta * 2, true, Node, FractalZoomScript, State);
637 }
638
642 public static FractalGraph CalcNewton(double rCenter, double iCenter, double rDelta, Complex R,
643 ILambdaExpression f, ScriptNode _, Variables Variables, int N, int Width, int Height,
644 ScriptNode Node, FractalZoomScript FractalZoomScript, object State)
645 {
646 double RRe = R.Real;
647 double RIm = R.Imaginary;
648 List<double> AttractorsR = new List<double>();
649 List<double> AttractorsI = new List<double>();
650 List<int> AttractorColors = new List<int>();
651 double[] AttractorsR2 = new double[0];
652 double[] AttractorsI2 = new double[0];
653 int[] AttractorsColors2 = new int[0];
654 double r0, i0, r1, i1;
655 double dr, di;
656 double r, i;
657 double zr, zi;
658 double aspect;
659 int x, y, b, c, d;
660 int NrAttractors = 0;
661 int n;
662 int index;
663
664 Variables v = new Variables();
665 Variables.CopyTo(v);
666
667 if (!(f is IDifferentiable Differentiable) ||
668 !(Differentiable.Differentiate(Differentiable.DefaultVariableName, v) is ILambdaExpression fPrim))
669 {
670 throw new ScriptRuntimeException("Lambda expression not differentiable.", Node);
671 }
672
673 int size = Width * Height * 4;
674 double Conv = 1e-10;
675 double Div = 1e10;
676 double Conv2 = Conv * 2;
677 byte[] rgb = new byte[size];
678
679 Complex[] Row;
680 Complex[] Row2;
681 Complex[] Row3;
682 int[] Offset;
683 IElement[] P = new IElement[1];
684 int j, x2;
685 IElement Obj, Obj2;
686 double Mod;
687 Complex z;
688
689 rDelta *= 0.5;
690 r0 = rCenter - rDelta;
691 r1 = rCenter + rDelta;
692
693 aspect = ((double)Width) / Height;
694
695 i0 = iCenter - rDelta / aspect;
696 i1 = iCenter + rDelta / aspect;
697
698 dr = (r1 - r0) / Width;
699 di = (i1 - i0) / Height;
700
701 for (y = 0, i = i0, index = 0; y < Height; y++, i += di)
702 {
703 Row = new Complex[Width];
704 Offset = new int[Width];
705
706 c = Width;
707 for (x = 0, x2 = y * Width * 4, r = r0; x < Width; x++, r += dr, x2 += 4)
708 {
709 Row[x] = new Complex(r, i);
710 Offset[x] = x2;
711 }
712
713 n = 0;
714 while (n < N && c > 0)
715 {
716 n++;
717 P[0] = new ComplexVector(Row);
718 Obj = f.Evaluate(P, v);
719 Obj2 = fPrim.Evaluate(P, v);
720 Row2 = Obj.AssociatedObjectValue as Complex[];
721 Row3 = Obj2.AssociatedObjectValue as Complex[];
722
723 if (Row2 is null || Row3 is null)
724 {
725 throw new ScriptRuntimeException("Lambda expression (and its first derivative) must be able to accept complex vectors, " +
726 "and return complex vectors of equal length. Type returned: " +
727 Obj.GetType().FullName + " and " + Obj2.GetType().FullName, Node);
728 }
729 else if (Row2.Length != c || Row3.Length != c)
730 {
731 throw new ScriptRuntimeException("Lambda expression (and its first derivative) must be able to accept complex vectors, " +
732 "and return complex vectors of equal length. Length returned: " +
733 Row2.Length.ToString() + " and " + Row3.Length.ToString() +
734 ". Expected: " + c.ToString(), Node);
735 }
736
737 for (x = x2 = 0; x < c; x++)
738 {
739 j = Offset[x];
740 z = R * Row2[x] / Row3[x];
741 Row[x] -= z;
742
743 Mod = z.Magnitude;
744
745 if (Mod > Conv && Mod < Div)
746 {
747 if (x != x2)
748 Offset[x2] = j;
749
750 x2++;
751 }
752 else
753 {
754 if (n >= N)
755 {
756 rgb[j++] = 0;
757 rgb[j++] = 0;
758 rgb[j++] = 0;
759 }
760 else
761 {
762 zr = z.Real;
763 zi = z.Imaginary;
764
765 for (b = 0; b < NrAttractors; b++)
766 {
767 if (Math.Abs(AttractorsR2[b] - zr) < Conv2 &&
768 Math.Abs(AttractorsI2[b] - zi) < Conv2)
769 {
770 break;
771 }
772 }
773
774 if (b == NrAttractors)
775 {
776 AttractorsR.Add(zr);
777 AttractorsI.Add(zi);
778
779 int p1 = ~((b % 6) + 1);
780 int p2 = ((b / 6) % 7);
781
782 int Red = (p1 & 1) != 0 ? 255 : 0;
783 int Green = (p1 & 2) != 0 ? 255 : 0;
784 int Blue = (p1 & 4) != 0 ? 255 : 0;
785
786 if ((p2 & 1) != 0)
787 Red >>= 1;
788
789 if ((p2 & 2) != 0)
790 Green >>= 1;
791
792 if ((p2 & 4) != 0)
793 Blue >>= 1;
794
795 Blue <<= 8;
796 Blue |= Green;
797 Blue <<= 8;
798 Blue |= Red;
799
800 AttractorColors.Add(Blue);
801
802 AttractorsR2 = AttractorsR.ToArray();
803 AttractorsI2 = AttractorsI.ToArray();
804 AttractorsColors2 = AttractorColors.ToArray();
805
806 NrAttractors++;
807 }
808
809 b = AttractorColors[b];
810
811 d = (byte)b;
812 rgb[index++] = (byte)((d * (N - n + 1)) / N);
813 b >>= 8;
814 d = (byte)b;
815 rgb[index++] = (byte)((d * (N - n + 1)) / N);
816 b >>= 8;
817 d = (byte)b;
818 rgb[index++] = (byte)((d * (N - n + 1)) / N);
819 }
820
821 rgb[j++] = 255;
822 }
823 }
824
825 if (x2 < x)
826 {
827 Array.Resize(ref Row, x2);
828 Array.Resize(ref Offset, x2);
829 c = x2;
830 }
831 }
832
833 }
834
835 PixelInformation Pixels = new PixelInformationRaw(SKColorType.Bgra8888, rgb, Width, Height, Width << 2);
836 return new FractalGraph(Variables, Pixels, r0, i0, r1, i1, rDelta * 2, true, Node, FractalZoomScript, State);
837 }
838
842 public override string FunctionName => nameof(NewtonBasinFractal);
843 }
844}
Class managing a script expression.
Definition: Expression.cs:39
static Complex ToComplex(object Object)
Converts an object to a complex value.
Definition: Expression.cs:4942
static double ToDouble(object Object)
Converts an object to a double value.
Definition: Expression.cs:4824
static string ToString(double Value)
Converts a value to a string, that can be parsed as part of an expression.
Definition: Expression.cs:4496
NewtonBasinFractal(ScriptNode z, ScriptNode dr, ScriptNode R, ScriptNode c, ScriptNode N, ScriptNode DimX, ScriptNode DimY, int Start, int Length, Expression Expression)
TODO
NewtonBasinFractal(ScriptNode z, ScriptNode dr, ScriptNode R, ScriptNode c, int Start, int Length, Expression Expression)
TODO
static FractalGraph CalcNewton(Variables Variables, double rCenter, double iCenter, double rDelta, Complex R, double[] Coefficients, int N, int Width, int Height, ScriptNode Node, FractalZoomScript FractalZoomScript, object State)
TODO
NewtonBasinFractal(ScriptNode z, ScriptNode dr, ScriptNode R, ScriptNode c, ScriptNode N, ScriptNode DimX, int Start, int Length, Expression Expression)
TODO
override IElement Evaluate(IElement[] Arguments, Variables Variables)
TODO
static FractalGraph CalcNewton(double rCenter, double iCenter, double rDelta, Complex R, ILambdaExpression f, ScriptNode _, Variables Variables, int N, int Width, int Height, ScriptNode Node, FractalZoomScript FractalZoomScript, object State)
TODO
static FractalGraph CalcNewton(Variables Variables, double rCenter, double iCenter, double rDelta, Complex R, Complex[] Coefficients, int N, int Width, int Height, ScriptNode Node, FractalZoomScript FractalZoomScript, object State)
TODO
NewtonBasinFractal(ScriptNode z, ScriptNode dr, ScriptNode R, ScriptNode c, ScriptNode N, int Start, int Length, Expression Expression)
TODO
Defines a clickable fractal graph in the complex plane.
Definition: FractalGraph.cs:22
Contains pixel information
Contains pixel information in a raw unencoded format.
Base class for multivariate funcions.
ScriptNode[] Arguments
Function arguments.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
override string ToString()
Definition: ScriptNode.cs:359
Expression Expression
Expression of which the node is a part.
Definition: ScriptNode.cs:177
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
Collection of variables.
Definition: Variables.cs:25
void CopyTo(Variables Variables)
Copies available variables to another variable collection.
Definition: Variables.cs:400
Basic interface for all types of elements.
Definition: IElement.cs:20
object AssociatedObjectValue
Associated object value.
Definition: IElement.cs:33
Basic interface for vectors.
Definition: IVector.cs:9
int Dimension
Dimension of vector.
Definition: IVector.cs:14
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.
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.
Definition: IFunction.cs:9