Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
FlameFractalRgba.cs
1using SkiaSharp;
2using System;
3using System.Text;
4using System.Threading;
5using System.Threading.Tasks;
13
15{
28 {
33 ScriptNode Preview, ScriptNode Parallel, ScriptNode DimX, ScriptNode DimY, ScriptNode SuperSampling,
34 ScriptNode Gamma, ScriptNode Vibrancy, ScriptNode Seed, int Start, int Length, Expression Expression)
35 : base(new ScriptNode[] { xc, yc, dr, N, FlameFunctions, Preview, Parallel, DimX, DimY, SuperSampling,
36 Gamma, Vibrancy, Seed },
37 new ArgumentType[] { ArgumentType.Scalar, ArgumentType.Scalar, ArgumentType.Scalar,
38 ArgumentType.Scalar, ArgumentType.Vector, ArgumentType.Scalar, ArgumentType.Scalar,
39 ArgumentType.Scalar, ArgumentType.Scalar, ArgumentType.Scalar, ArgumentType.Scalar,
40 ArgumentType.Scalar, ArgumentType.Scalar }, Start, Length, Expression)
41 {
42 }
43
48 ScriptNode Preview, ScriptNode Parallel, ScriptNode DimX, ScriptNode DimY, ScriptNode SuperSampling,
49 ScriptNode Gamma, ScriptNode Vibrancy, int Start, int Length, Expression Expression)
50 : base(new ScriptNode[] { xc, yc, dr, N, FlameFunctions, Preview, Parallel, DimX, DimY, SuperSampling,
51 Gamma, Vibrancy },
52 new ArgumentType[] { ArgumentType.Scalar, ArgumentType.Scalar, ArgumentType.Scalar,
53 ArgumentType.Scalar, ArgumentType.Vector, ArgumentType.Scalar, ArgumentType.Scalar,
54 ArgumentType.Scalar, ArgumentType.Scalar, ArgumentType.Scalar, ArgumentType.Scalar,
55 ArgumentType.Scalar }, Start, Length, Expression)
56 {
57 }
58
63 ScriptNode Preview, ScriptNode Parallel, ScriptNode DimX, ScriptNode DimY, ScriptNode SuperSampling,
65 : base(new ScriptNode[] { xc, yc, dr, N, FlameFunctions, Preview, Parallel, DimX, DimY, SuperSampling,
66 Gamma },
67 new ArgumentType[] { ArgumentType.Scalar, ArgumentType.Scalar, ArgumentType.Scalar,
68 ArgumentType.Scalar, ArgumentType.Vector, ArgumentType.Scalar, ArgumentType.Scalar,
69 ArgumentType.Scalar, ArgumentType.Scalar, ArgumentType.Scalar, ArgumentType.Scalar },
71 {
72 }
73
78 ScriptNode Preview, ScriptNode Parallel, ScriptNode DimX, ScriptNode DimY, ScriptNode SuperSampling,
80 : base(new ScriptNode[] { xc, yc, dr, N, FlameFunctions, Preview, Parallel, DimX, DimY, SuperSampling },
81 new ArgumentType[] { ArgumentType.Scalar, ArgumentType.Scalar, ArgumentType.Scalar,
82 ArgumentType.Scalar, ArgumentType.Vector, ArgumentType.Scalar, ArgumentType.Scalar,
83 ArgumentType.Scalar, ArgumentType.Scalar, ArgumentType.Scalar },
85 {
86 }
87
92 ScriptNode Preview, ScriptNode Parallel, ScriptNode DimX, ScriptNode DimY, int Start, int Length,
94 : base(new ScriptNode[] { xc, yc, dr, N, FlameFunctions, Preview, Parallel, DimX, DimY },
95 new ArgumentType[] { ArgumentType.Scalar, ArgumentType.Scalar, ArgumentType.Scalar,
96 ArgumentType.Scalar, ArgumentType.Vector, ArgumentType.Scalar, ArgumentType.Scalar,
97 ArgumentType.Scalar, ArgumentType.Scalar },
99 {
100 }
101
106 ScriptNode Preview, ScriptNode Parallel, ScriptNode DimX, int Start, int Length, Expression Expression)
107 : base(new ScriptNode[] { xc, yc, dr, N, FlameFunctions, Preview, Parallel, DimX },
108 new ArgumentType[] { ArgumentType.Scalar, ArgumentType.Scalar, ArgumentType.Scalar,
109 ArgumentType.Scalar, ArgumentType.Vector, ArgumentType.Scalar, ArgumentType.Scalar,
110 ArgumentType.Scalar },
112 {
113 }
114
119 ScriptNode Preview, ScriptNode Parallel, int Start, int Length, Expression Expression)
120 : base(new ScriptNode[] { xc, yc, dr, N, FlameFunctions, Preview, Parallel },
121 new ArgumentType[] { ArgumentType.Scalar, ArgumentType.Scalar, ArgumentType.Scalar,
122 ArgumentType.Scalar, ArgumentType.Vector, ArgumentType.Scalar, ArgumentType.Scalar },
124 {
125 }
126
131 ScriptNode Preview, int Start, int Length, Expression Expression)
132 : base(new ScriptNode[] { xc, yc, dr, N, FlameFunctions, Preview },
133 new ArgumentType[] { ArgumentType.Scalar, ArgumentType.Scalar, ArgumentType.Scalar,
134 ArgumentType.Scalar, ArgumentType.Vector, ArgumentType.Scalar },
136 {
137 }
138
144 : base(new ScriptNode[] { xc, yc, dr, N, FlameFunctions },
145 new ArgumentType[] { ArgumentType.Scalar, ArgumentType.Scalar, ArgumentType.Scalar,
146 ArgumentType.Scalar, ArgumentType.Vector },
148 {
149 }
150
154 public override string[] DefaultArgumentNames
155 {
156 get
157 {
158 return new string[]
159 {
160 "xc", "yc", "dr", "N", "FlameFunctions", "Preview", "Parallel",
161 "DimX", "DimY", "SuperSampling", "Gamma", "Vibrancy", "Seed"
162 };
163 }
164 }
165
169 public override string FunctionName => nameof(FlameFractalRgba);
170
174 public override string[] Aliases
175 {
176 get
177 {
178 return new string[] { "FlameFractal" };
179 }
180 }
181
186 public override bool IsAsynchronous => true;
187
192 {
193 return this.EvaluateAsync(Arguments, Variables).Result;
194 }
195
199 public override async Task<IElement> EvaluateAsync(IElement[] Arguments, Variables Variables)
200 {
201 double xc, yc;
202 double dr;
203 long N;
204 int dimx, dimy;
205 int i, c;
206 int Seed;
207
208 i = 0;
209 c = Arguments.Length;
210 xc = Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
211 yc = Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
212 dr = Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
213 N = (long)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
214 if (N <= 0)
215 throw new ScriptRuntimeException("N in calls to FlameFractalRgba() must be a positive integer.", this);
216
217 object Obj = Arguments[i].AssociatedObjectValue;
218 string FunctionsExpression = this.Arguments[i++].SubExpression;
219
220 if (!(Obj is Array FlameArray))
221 throw new ScriptRuntimeException("The fifth parameter to FlameFractalRgba must be an array, containing flame definitions.", this);
222
224 double Weight;
225 double Gamma;
226 double Vibrancy;
227 int SuperSampling;
228 FlameFunction CurrentFunction = null;
229
230 foreach (object FlameItem in FlameArray)
231 {
232 if (FlameItem is DoubleMatrix M)
233 {
234 CurrentFunction = new FlameFunction(M, this);
235 FlameFunctions.Add(CurrentFunction);
236 }
237 else if (FlameItem is SKColor || FlameItem is string)
238 {
239 if (CurrentFunction is null)
240 {
241 M = new DoubleMatrix(new double[,] { { 1, 0 }, { 0, 1 } });
242 CurrentFunction = new FlameFunction(M, this);
243 FlameFunctions.Add(CurrentFunction);
244 }
245
246 CurrentFunction.SetColor(Graph.ToColor(FlameItem));
247 CurrentFunction = null;
248 }
249 else if (FlameItem is IFlameVariation FlameVariation)
250 {
251 if (CurrentFunction is null)
252 {
253 M = new DoubleMatrix(new double[,] { { 1, 0 }, { 0, 1 } });
254 CurrentFunction = new FlameFunction(M, this);
255 FlameFunctions.Add(CurrentFunction);
256 }
257
258 CurrentFunction.Add(FlameVariation);
259 }
260 else if (FlameItem is ILambdaExpression LambdaExpression)
261 {
262 if (CurrentFunction is null)
263 {
264 M = new DoubleMatrix(new double[,] { { 1, 0 }, { 0, 1 } });
265 CurrentFunction = new FlameFunction(M, this);
266 FlameFunctions.Add(CurrentFunction);
267 }
268
269 CurrentFunction.Add(LambdaExpression);
270 }
271 else if (!(FlameItem is null))
272 {
273 try
274 {
275 Weight = Expression.ToDouble(FlameItem);
276
277 if (CurrentFunction is null)
278 {
279 M = new DoubleMatrix(new double[,] { { 1, 0 }, { 0, 1 } });
280 CurrentFunction = new FlameFunction(M, this);
281 FlameFunctions.Add(CurrentFunction);
282 }
283
284 CurrentFunction.SetWeight(Weight);
285 }
286 catch (Exception)
287 {
288 throw new ScriptRuntimeException("Invalid flame variation definition.", this);
289 }
290 }
291 }
292
293 if (i < c && Arguments[i].AssociatedObjectValue is bool Preview)
294 i++;
295 else
296 Preview = false;
297
298 if (i < c && Arguments[i].AssociatedObjectValue is bool Parallel)
299 i++;
300 else
301 Parallel = false;
302
303 if (i < c)
304 dimx = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
305 else
306 dimx = 320;
307
308 if (i < c)
309 dimy = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
310 else
311 dimy = 200;
312
313 if (i < c)
314 SuperSampling = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
315 else
316 SuperSampling = 2;
317
318 if (i < c)
319 Gamma = Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
320 else
321 Gamma = 2.2;
322
323 if (i < c)
324 Vibrancy = Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
325 else
326 Vibrancy = 1.0;
327
328 if (i < c)
329 Seed = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
330 else
331 {
332 lock (gen)
333 {
334 Seed = gen.Next();
335 }
336
337 Variables.ConsoleOut?.WriteLine("Seed = " + Seed.ToString(), Variables);
338 }
339
340 if (i < c)
341 {
342 throw new ScriptRuntimeException("Parameter mismatch in call to FlameFractalRgba(xc,yc,dr,N,FlameFunctions[,Preview[,Parallel[,dimx[,dimy[,SuperSampling[,Gamma[,Vibrancy[,Seed]]]]]]]]).",
343 this);
344 }
345
346 if (dimx <= 0 || dimx > 5000 || dimy <= 0 || dimy > 5000)
347 throw new FractalImageSizeScriptException(this);
348
349 FlameFunction[] Functions = FlameFunctions.ToArray();
350
351 if (dr <= 0)
352 {
353 EstimateSize(out xc, out yc, out dr, Functions, dimx, dimy, Seed, 5000, Variables, this);
354
355 Variables.ConsoleOut?.WriteLine("X-center: " + Expression.ToString(xc), Variables);
356 Variables.ConsoleOut?.WriteLine("Y-center: " + Expression.ToString(yc), Variables);
357 Variables.ConsoleOut?.WriteLine("Width: " + Expression.ToString(dr), Variables);
358 }
359
360 return await CalcFlame(xc, yc, dr, N, Functions, dimx, dimy, Seed, SuperSampling, Gamma,
361 Vibrancy, Preview, Parallel, Variables, this, this.FractalZoomScript,
362 new object[] { dimx, dimy, N, FunctionsExpression, Seed, SuperSampling, Gamma,
363 Vibrancy, Preview, Parallel });
364 }
365
366 private readonly static Random gen = new Random();
367
368 private string FractalZoomScript(double r, double i, double Size, object State)
369 {
370 object[] Parameters = (object[])State;
371 int DimX = (int)Parameters[0];
372 int DimY = (int)Parameters[1];
373 long N = (long)Parameters[2];
374 string FunctionsExpression = (string)Parameters[3];
375 int Seed = (int)Parameters[4];
376 int SuperSampling = (int)Parameters[5];
377 double Gamma = (double)Parameters[6];
378 double Vibrancy = (double)Parameters[7];
379 bool Preview = (bool)Parameters[8];
380 bool Parallel = (bool)Parameters[9];
381
382 StringBuilder sb = new StringBuilder();
383
384 sb.Append("FlameFractalRgba(");
385 sb.Append(Expression.ToString(r));
386 sb.Append(',');
387 sb.Append(Expression.ToString(i));
388 sb.Append(',');
389 sb.Append(Expression.ToString(Size / 4));
390 sb.Append(',');
391 sb.Append(N.ToString());
392 sb.Append(',');
393 sb.Append(FunctionsExpression);
394 sb.Append(',');
395 sb.Append(Expression.ToString(Preview));
396 sb.Append(',');
397 sb.Append(Expression.ToString(Parallel));
398 sb.Append(',');
399 sb.Append(DimX.ToString());
400 sb.Append(',');
401 sb.Append(DimY.ToString());
402 sb.Append(',');
403 sb.Append(SuperSampling.ToString());
404 sb.Append(',');
405 sb.Append(Expression.ToString(Gamma));
406 sb.Append(',');
407 sb.Append(Expression.ToString(Vibrancy));
408 sb.Append(',');
409 sb.Append(Seed.ToString());
410 sb.Append(')');
411
412 return sb.ToString();
413 }
414
418 public static void EstimateSize(out double xCenter, out double yCenter, out double rDelta, FlameFunction[] Functions,
419 int Width, int Height, int Seed, long N, Variables Variables, ScriptNode Node)
420 {
421 double TotWeight = 0;
422 double Weight;
423 int i, c = Functions.Length;
424 Random Gen = new Random(Seed);
425
426 if (c < 1)
427 throw new ScriptRuntimeException("At least one flame function needs to be provided.", Node);
428
429 double[] SumWeights = new double[c];
431
432 for (i = 0; i < c; i++)
433 {
434 f = Functions[i];
435 Weight = f.Weight;
436 if (Weight < 0)
437 throw new ScriptRuntimeException("Weights must be non-negative.", Node);
438
439 f.DefinitionDone();
440 TotWeight += Weight;
441 SumWeights[i] = TotWeight;
442 }
443
444 if (TotWeight == 0)
445 throw new ScriptRuntimeException("The total weight of all functions must be postitive.", Node);
446
447 for (i = 0; i < c; i++)
448 SumWeights[i] /= TotWeight;
449
450 double AspectRatio = ((double)Width) / Height;
451 int j;
452 double xMin, xMax, yMin, yMax;
453 double d;
454
455 FlameState P = new FlameState(Gen, -1, 1, -1, 1, Width, Height, 1, N, ColorMode.Rgba, Node);
456 Variables v = new Variables();
457 Variables.CopyTo(v);
458
459 for (i = 0; i < 20; i++)
460 {
461 Weight = Gen.NextDouble();
462 j = 0;
463 while (j < c - 1 && SumWeights[j] <= Weight)
464 j++;
465
466 f = Functions[j];
467 if (!f.Operate(P, v))
468 {
469 N = 0;
470 break;
471 }
472 }
473
474 xMin = xMax = P.x;
475 yMin = yMax = P.y;
476
477 while (N-- > 0)
478 {
479 Weight = Gen.NextDouble();
480 j = 0;
481 while (j < c - 1 && SumWeights[j] <= Weight)
482 j++;
483
484 f = Functions[j];
485 if (!f.Operate(P, v))
486 break;
487
488 d = P.x;
489 if (d < xMin)
490 xMin = d;
491 else if (d > xMax)
492 xMax = d;
493
494 d = P.y;
495 if (d < yMin)
496 yMin = d;
497 else if (d > yMax)
498 yMax = d;
499 }
500
501 d = Graph.GetStepSize(xMin, xMax, 10);
502 xMin = Math.Floor(xMin / d) * d;
503 xMax = Math.Ceiling(xMax / d) * d;
504
505 d = Graph.GetStepSize(yMin, yMax, 10);
506 yMin = Math.Floor(yMin / d) * d;
507 yMax = Math.Ceiling(yMax / d) * d;
508
509 xCenter = (xMax + xMin) * 0.5;
510 yCenter = (yMax + yMin) * 0.5;
511
512 rDelta = xMax - xMin;
513 d = (yMax - yMin) * AspectRatio;
514 if (d > rDelta)
515 rDelta = d;
516 }
517
521 public static async Task<FractalGraph> CalcFlame(double xCenter, double yCenter, double rDelta, long N,
522 FlameFunction[] Functions, int Width, int Height, int Seed, int SuperSampling, double Gamma,
523 double Vibrancy, bool Preview, bool Parallel, Variables Variables, ScriptNode Node,
524 FractalZoomScript FractalZoomScript, object State)
525 {
526 double TotWeight = 0;
527 double Weight;
528 int i, c = Functions.Length;
529 Random Gen = new Random(Seed);
530
531 if (c < 1)
532 throw new ScriptRuntimeException("At least one flame function needs to be provided.", Node);
533
534 if (SuperSampling < 1)
535 throw new ScriptRuntimeException("SuperSampling must be a postitive integer.", Node);
536
538 Preview = false;
539
540 Array.Sort(Functions, (f1, f2) =>
541 {
542 double d = f2.Weight - f1.Weight;
543 if (d < 0)
544 return -1;
545 else if (d > 0)
546 return 1;
547 else
548 return 0;
549 });
550
551 double[] SumWeights = new double[c];
553
554 for (i = 0; i < c; i++)
555 {
556 f = Functions[i];
557 Weight = f.Weight;
558 if (Weight < 0)
559 throw new ScriptRuntimeException("Weights must be non-negative.", Node);
560
561 f.DefinitionDone();
562 TotWeight += Weight;
563 SumWeights[i] = TotWeight;
564 }
565
566 if (TotWeight == 0)
567 throw new ScriptRuntimeException("The total weight of all functions must be postitive.", Node);
568
569 for (i = 0; i < c; i++)
570 SumWeights[i] /= TotWeight;
571
572 double AspectRatio = ((double)Width) / Height;
573 double xMin, xMax, yMin, yMax;
574
575 xMin = xCenter - rDelta / 2;
576 xMax = xMin + rDelta;
577 yMin = yCenter - rDelta / (2 * AspectRatio);
578 yMax = yMin + rDelta / AspectRatio;
579
580 int NrGames = Parallel ? Environment.ProcessorCount : 1;
581
582 if (NrGames <= 1)
583 {
584 FlameState P = new FlameState(Gen, xMin, xMax, yMin, yMax, Width, Height, SuperSampling, N, ColorMode.Rgba, Node);
585 Variables v = new Variables();
586 Variables.CopyTo(v);
587
588 await RunChaosGame(v, Functions, SumWeights, P, Preview, Gamma, Vibrancy, Node);
589
590 return new FractalGraph(Variables, P.RenderBitmapRgba(Gamma, Vibrancy, false, SKColors.White), xMin, yMin, xMax, yMax, rDelta,
591 false, Node, FractalZoomScript, State);
592 }
593 else
594 {
595 FlameState[] P = new FlameState[NrGames];
596 WaitHandle[] Done = new WaitHandle[NrGames];
597 Thread[] T = new Thread[NrGames];
598
599 try
600 {
601 for (i = 0; i < NrGames; i++)
602 {
603 Done[i] = new ManualResetEvent(false);
604 P[i] = new FlameState(Gen, xMin, xMax, yMin, yMax, Width, Height, SuperSampling,
605 i < NrGames - 1 ? N / NrGames : N - (N / NrGames) * (NrGames - 1),
606 ColorMode.Rgba, Node);
607
608 Variables v = new Variables();
609 Variables.CopyTo(v);
610
611 T[i] = new Thread(new ParameterizedThreadStart(ChaosGameThread))
612 {
613 Name = "FlameFractal thread #" + (i + 1).ToString(),
614 Priority = ThreadPriority.BelowNormal
615 };
616
617 T[i].Start(new object[] { Done[i], i, v, Functions, SumWeights, P[i],
618 Node, i == 0 && Preview, Gamma, Vibrancy });
619 }
620
621 WaitHandle.WaitAll(Done);
622
623 for (i = 1; i < NrGames; i++)
624 P[0].Add(P[i]);
625
626 return new FractalGraph(Variables, P[0].RenderBitmapRgba(Gamma, Vibrancy, false, SKColors.White), xMin, yMin, xMax, yMax, rDelta,
627 false, Node, FractalZoomScript, State);
628 }
629 catch (ThreadAbortException)
630 {
631 for (i = 0; i < NrGames; i++)
632 {
633 try
634 {
635 if (T[i] is null)
636 continue;
637
638 if (Done[i] is null || !Done[i].WaitOne(0))
639 T[i].Abort();
640 }
641 catch (Exception)
642 {
643 // Ignore
644 }
645 }
646
647 return null;
648 }
649 finally
650 {
651 for (i = 0; i < NrGames; i++)
652 {
653 try
654 {
655 Done[i]?.Close();
656 }
657 catch (Exception)
658 {
659 // Ignore
660 }
661 }
662 }
663 }
664 }
665
666 private static void ChaosGameThread(object P)
667 {
668 object[] Parameters = (object[])P;
669 ManualResetEvent Done = (ManualResetEvent)Parameters[0];
670 //int GameNr = (int)Parameters[1];
671 Variables v = (Variables)Parameters[2];
672 FlameFunction[] Functions = (FlameFunction[])Parameters[3];
673 double[] SumWeights = (double[])Parameters[4];
674 FlameState P2 = (FlameState)Parameters[5];
675 ScriptNode Node = (ScriptNode)Parameters[6];
676 bool Preview = (bool)Parameters[7];
677 double Gamma=(double)Parameters[8];
678 double Vibrancy=(double)Parameters[9];
679
680 try
681 {
682 RunChaosGame(v, Functions, SumWeights, P2, Preview, Gamma, Vibrancy, Node).Wait();
683 }
684 catch (ThreadAbortException)
685 {
686 Thread.ResetAbort();
687 }
688 catch (Exception)
689 {
690 // Ignore.
691 }
692 finally
693 {
694 Done.Set();
695 }
696 }
697
698 private static async Task RunChaosGame(Variables v, FlameFunction[] Functions,
699 double[] SumWeights, FlameState P, bool Preview, double Gamma, double Vibrancy,
700 ScriptNode Node)
701 {
702 Random Gen = new Random();
703 FlameFunction f;
704 double Weight;
705 int i, j;
706 int c = Functions.Length;
707
708 for (i = 0; i < 20; i++)
709 {
710 Weight = Gen.NextDouble();
711 j = 0;
712 while (j < c - 1 && SumWeights[j] <= Weight)
713 j++;
714
715 f = Functions[j];
716 if (!f.Operate(P, v))
717 {
718 P.N = 0;
719 break;
720 }
721 }
722
723 if (Preview || v.HandlesStatus)
724 {
725 DateTime Start = DateTime.Now;
726 DateTime NextPreview = Start.AddSeconds(1);
727 DateTime PrevPreview = Start;
728 DateTime Temp;
729 DateTime Temp2;
730 TimeSpan TimeLeft;
731 int NextPreviewDeciSeconds = 10;
732 int NrIterationsPerPreview = 4096;
733 int Pos = NrIterationsPerPreview;
734 long NrIterations;
735 long PrevNrIterations = 0;
736 long NrIterationsSinceLast;
737 double PercentDone;
738 double IterationsPerSeconds;
739
740 do
741 {
742 if (Pos-- <= 0)
743 {
744 Pos = NrIterationsPerPreview;
745 Temp = DateTime.Now;
746 if (Temp > NextPreview)
747 {
748 NextPreview = Temp.AddSeconds(NextPreviewDeciSeconds * 0.1);
749 if (NextPreviewDeciSeconds < 50)
750 NextPreviewDeciSeconds++;
751
752 if (Preview)
753 {
754 await v.Preview(Node.Expression, new GraphBitmap(v, P.RenderBitmapRgba(Gamma, Vibrancy, true, SKColors.White)));
755
756 Temp2 = DateTime.Now;
757
758 double d = (Temp2 - Temp).TotalSeconds;
759 double d2 = (Temp - PrevPreview).TotalSeconds;
760
761 if (d / d2 > 0.1)
762 {
763 NrIterationsPerPreview <<= 1;
764 if (NrIterationsPerPreview < 0)
765 NrIterationsPerPreview = int.MaxValue;
766 }
767 }
768
769 NrIterations = P.N0 - P.N;
770 NrIterationsSinceLast = NrIterations - PrevNrIterations;
771 IterationsPerSeconds = NrIterationsSinceLast / (Temp - PrevPreview).TotalSeconds;
772 PercentDone = (100 * (1.0 - ((double)P.N) / P.N0));
773 TimeLeft = new TimeSpan((long)((Temp - Start).Ticks * 100 / PercentDone));
774 await v.Status(Node.Expression, P.N.ToString() + " iterations left, " + NrIterations.ToString() + " iterations done, " + IterationsPerSeconds.ToString("F0") + " iterations/s, " + PercentDone.ToString("F1") + "% done, Time Left: " + TimeLeft.ToString() + ".");
775 PrevNrIterations = NrIterations;
776 PrevPreview = Temp;
777 }
778 }
779
780 Weight = Gen.NextDouble();
781 j = 0;
782 while (j < c - 1 && SumWeights[j] <= Weight)
783 j++;
784
785 f = Functions[j];
786 if (!f.Operate(P, v))
787 break;
788 }
789 while (P.IncHistogram());
790
791 await v.Status(Node.Expression, string.Empty);
792 }
793 else
794 {
795 do
796 {
797 Weight = Gen.NextDouble();
798 j = 0;
799 while (j < c - 1 && SumWeights[j] <= Weight)
800 j++;
801
802 f = Functions[j];
803 if (!f.Operate(P, v))
804 break;
805 }
806 while (P.IncHistogram());
807 }
808 }
809
810 }
811}
A chunked list is a linked list of chunks of objects of type T .
Definition: ChunkedList.cs:54
Class managing a script expression.
Definition: Expression.cs:41
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
Exception thrown if an image with invalid size is requested.
Defines a clickable fractal graph in the complex plane.
Definition: FractalGraph.cs:23
Calculates a flame fractal in RGBA space. Intensity is calculated along the A-axis....
override bool IsAsynchronous
If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluat...
static async Task< FractalGraph > CalcFlame(double xCenter, double yCenter, double rDelta, long N, FlameFunction[] Functions, int Width, int Height, int Seed, int SuperSampling, double Gamma, double Vibrancy, bool Preview, bool Parallel, Variables Variables, ScriptNode Node, FractalZoomScript FractalZoomScript, object State)
TODO
override IElement Evaluate(IElement[] Arguments, Variables Variables)
TODO
FlameFractalRgba(ScriptNode xc, ScriptNode yc, ScriptNode dr, ScriptNode N, ScriptNode FlameFunctions, ScriptNode Preview, int Start, int Length, Expression Expression)
TODO
static void EstimateSize(out double xCenter, out double yCenter, out double rDelta, FlameFunction[] Functions, int Width, int Height, int Seed, long N, Variables Variables, ScriptNode Node)
TODO
FlameFractalRgba(ScriptNode xc, ScriptNode yc, ScriptNode dr, ScriptNode N, ScriptNode FlameFunctions, ScriptNode Preview, ScriptNode Parallel, ScriptNode DimX, ScriptNode DimY, ScriptNode SuperSampling, int Start, int Length, Expression Expression)
TODO
FlameFractalRgba(ScriptNode xc, ScriptNode yc, ScriptNode dr, ScriptNode N, ScriptNode FlameFunctions, ScriptNode Preview, ScriptNode Parallel, int Start, int Length, Expression Expression)
TODO
FlameFractalRgba(ScriptNode xc, ScriptNode yc, ScriptNode dr, ScriptNode N, ScriptNode FlameFunctions, int Start, int Length, Expression Expression)
TODO
FlameFractalRgba(ScriptNode xc, ScriptNode yc, ScriptNode dr, ScriptNode N, ScriptNode FlameFunctions, ScriptNode Preview, ScriptNode Parallel, ScriptNode DimX, ScriptNode DimY, ScriptNode SuperSampling, ScriptNode Gamma, ScriptNode Vibrancy, ScriptNode Seed, int Start, int Length, Expression Expression)
TODO
FlameFractalRgba(ScriptNode xc, ScriptNode yc, ScriptNode dr, ScriptNode N, ScriptNode FlameFunctions, ScriptNode Preview, ScriptNode Parallel, ScriptNode DimX, int Start, int Length, Expression Expression)
TODO
FlameFractalRgba(ScriptNode xc, ScriptNode yc, ScriptNode dr, ScriptNode N, ScriptNode FlameFunctions, ScriptNode Preview, ScriptNode Parallel, ScriptNode DimX, ScriptNode DimY, ScriptNode SuperSampling, ScriptNode Gamma, int Start, int Length, Expression Expression)
TODO
FlameFractalRgba(ScriptNode xc, ScriptNode yc, ScriptNode dr, ScriptNode N, ScriptNode FlameFunctions, ScriptNode Preview, ScriptNode Parallel, ScriptNode DimX, ScriptNode DimY, int Start, int Length, Expression Expression)
TODO
FlameFractalRgba(ScriptNode xc, ScriptNode yc, ScriptNode dr, ScriptNode N, ScriptNode FlameFunctions, ScriptNode Preview, ScriptNode Parallel, ScriptNode DimX, ScriptNode DimY, ScriptNode SuperSampling, ScriptNode Gamma, ScriptNode Vibrancy, int Start, int Length, Expression Expression)
TODO
override async Task< IElement > EvaluateAsync(IElement[] Arguments, Variables Variables)
TODO
Handles bitmap-based graphs.
Definition: GraphBitmap.cs:13
Base class for graphs.
Definition: Graph.cs:88
static double GetStepSize(double Min, double Max, int ApproxNrLabels)
Gets a human readable step size for an interval, given its limits and desired number of steps.
Definition: Graph.cs:1070
static SKColor ToColor(object Object)
Converts an object to a color.
Definition: Graph.cs:844
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
TextWriter ConsoleOut
Console out interface. Can be used by functions and script to output data to the console.
Definition: Variables.cs:223
async Task Status(Expression Expression, string Result)
Reports current status of execution.
Definition: Variables.cs:424
bool HandlesPreview
If previews are desired.
Definition: Variables.cs:389
bool HandlesStatus
If status messages are desired.
Definition: Variables.cs:434
void CopyTo(Variables Variables)
Copies available variables to another variable collection.
Definition: Variables.cs:334
async Task Preview(Expression Expression, IElement Result)
Reports a preview of the final result.
Definition: Variables.cs:407
Basic interface for all types of elements.
Definition: IElement.cs:21
Base interface for lambda expressions.
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