Beispiel #1
0
 private Color ComputeLifePointColor(float value, float reality)
 => value > 0
         ? ColorMath.Mix(Options.NeutralColor, Options.GoodColor, value, reality)
         : ColorMath.Mix(Options.NeutralColor, Options.BadColor, -value, reality);
Beispiel #2
0
        public RenderResult Render(IEnumerable <Individual> individuals,
                                   Action <RenderResult> snapshotHandler, TimeSpan snapshotDelta,
                                   CancellationToken cancellationToken)
        {
            individualCount            = 0;
            alternativeIndividualCount = 0;
            lifeStepCount            = 0;
            alternativeLifeStepCount = 0;

            var bmp = new Bitmap(Options.CanvasSize.Width, Options.CanvasSize.Height, PixelFormat.Format32bppArgb);
            var g   = Graphics.FromImage(bmp);

            g.Clear(Options.BackgroundColor);
            g.SmoothingMode = SmoothingMode.HighQuality;

            var        t0    = DateTime.Now;
            var        tRef  = t0;
            Individual pivot = null;
            long       index = -1;

            foreach (var individual in individuals)
            {
                index++;
                if (individual.Reality == 1f)
                {
                    individualCount++;
                }
                else
                {
                    alternativeIndividualCount++;
                }

                if (Options.PivotIndex == index)
                {
                    pivot = individual;
                }
                if (cancellationToken.IsCancelled)
                {
                    break;
                }
                if (Options.PivotOnly)
                {
                    continue;
                }

                RenderIndividual(g, individual, false);

                var t = DateTime.Now;
                if (t > tRef + snapshotDelta)
                {
                    tRef = t;
                    snapshotHandler?.Invoke(BuildResult(t - t0, new Bitmap(bmp)));
                }
            }
            if (Options.HighlightPivot && !Options.PivotOnly)
            {
                using (var dimBrush = new SolidBrush(Color.FromArgb(
                                                         ColorMath.ColorValue(Options.HighlightDimOpacity * 255f),
                                                         Options.BackgroundColor)))
                {
                    g.FillRectangle(dimBrush, -1, -1,
                                    Options.CanvasSize.Width + 2, Options.CanvasSize.Height + 2);
                }
            }
            if (pivot != null)
            {
                if (Options.PivotOnly)
                {
                    RenderIndividual(g, pivot, false);
                }
                else if (Options.HighlightPivot)
                {
                    RenderIndividual(g, pivot, true);
                }
            }
            g.Dispose();
            return(BuildResult(DateTime.Now - t0, bmp));
        }