private static void RunChaosGame(Variables v, FlameFunction[] Functions, double[] SumWeights, FlameState P, bool Preview, double Gamma, double LightFactor, ScriptNode Node, bool ShowStatus) { Random Gen = new Random(); FlameFunction f; double Weight; int i, j; int c = Functions.Length; for (i = 0; i < 20; i++) { Weight = Gen.NextDouble(); j = 0; while (j < c - 1 && SumWeights[j] <= Weight) { j++; } f = Functions[j]; if (!f.Operate(P, v)) { P.N = 0; break; } } if (Preview || Node.Expression.HandlesStatus) { System.DateTime Start = System.DateTime.Now; System.DateTime NextPreview = Start.AddSeconds(1); System.DateTime PrevPreview = Start; System.DateTime Temp; System.DateTime Temp2; TimeSpan TimeLeft; int NextPreviewDeciSeconds = 10; int NrIterationsPerPreview = 4096; int Pos = NrIterationsPerPreview; long NrIterations; long PrevNrIterations = 0; long NrIterationsSinceLast; double PercentDone; double IterationsPerSeconds; do { if (Pos-- <= 0) { Pos = NrIterationsPerPreview; Temp = System.DateTime.Now; if (Temp > NextPreview) { NextPreview = Temp.AddSeconds(NextPreviewDeciSeconds * 0.1); if (NextPreviewDeciSeconds < 50) { NextPreviewDeciSeconds++; } if (Preview) { Node.Expression.Preview(new GraphBitmap(P.RenderBitmapHsl(Gamma, LightFactor, true, SKColors.Black))); Temp2 = System.DateTime.Now; double d = (Temp2 - Temp).TotalSeconds; double d2 = (Temp - PrevPreview).TotalSeconds; if (d / d2 > 0.1) { NrIterationsPerPreview <<= 1; if (NrIterationsPerPreview < 0) { NrIterationsPerPreview = int.MaxValue; } } } NrIterations = P.N0 - P.N; NrIterationsSinceLast = NrIterations - PrevNrIterations; IterationsPerSeconds = NrIterationsSinceLast / (Temp - PrevPreview).TotalSeconds; PercentDone = (100 * (1.0 - ((double)P.N) / P.N0)); TimeLeft = new TimeSpan((long)((Temp - Start).Ticks * 100 / PercentDone)); Node.Expression.Status(P.N.ToString() + " iterations left, " + NrIterations.ToString() + " iterations done, " + IterationsPerSeconds.ToString("F0") + " iterations/s, " + PercentDone.ToString("F1") + "% done, Time Left: " + TimeLeft.ToString() + "."); PrevNrIterations = NrIterations; PrevPreview = Temp; } } Weight = Gen.NextDouble(); j = 0; while (j < c - 1 && SumWeights[j] <= Weight) { j++; } f = Functions[j]; if (!f.Operate(P, v)) { break; } }while (P.IncHistogram()); Node.Expression.Status(string.Empty); } else { do { Weight = Gen.NextDouble(); j = 0; while (j < c - 1 && SumWeights[j] <= Weight) { j++; } f = Functions[j]; if (!f.Operate(P, v)) { break; } }while (P.IncHistogram()); } }