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