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