using System; using Prism; namespace Konis.Testbed { /// /// A background to judge particles against: a fill, and a grid of cells drawn over it. /// public class Backdrop { /// /// The backdrops the testbed offers, in the order they cycle. /// public static readonly Backdrop[] All = { new Backdrop("Black", Color.FromArgb(255, 0, 0, 0), Array.Empty(), (column, row) => -1), new Backdrop("White", Color.FromArgb(255, 255, 255, 255), Array.Empty(), (column, row) => -1), new Backdrop("Checker", Color.FromArgb(255, 255, 255, 255), new[] { Color.FromArgb(255, 0, 0, 0) }, (column, row) => ((column + row) & 1) == 0 ? 0 : -1), new Backdrop("Greys", Color.FromArgb(255, 0, 0, 0), GreyRamp(8), (column, row) => Wrap(column, 8)), new Backdrop("Colours", Color.FromArgb(255, 0, 0, 0), new[] { Color.FromArgb(255, 220, 50, 47), Color.FromArgb(255, 235, 140, 30), Color.FromArgb(255, 230, 210, 50), Color.FromArgb(255, 60, 170, 70), Color.FromArgb(255, 40, 160, 200), Color.FromArgb(255, 70, 90, 210), Color.FromArgb(255, 170, 70, 190), }, (column, row) => Wrap(column + 3 * row, 7)), }; private readonly Func swatchAt; public Backdrop(string name, Color fill, Color[] swatches, Func swatchAt) { Name = name; Fill = fill; Swatches = swatches; this.swatchAt = swatchAt; } /// /// Gets the backdrop's name. /// public string Name { get; } /// /// Gets the color under the grid, which is all of a backdrop with no cells. /// public Color Fill { get; } /// /// Gets the colors the cells are drawn in. /// public Color[] Swatches { get; } private static Color[] GreyRamp(int steps) { var greys = new Color[steps]; for (int i = 0; i < steps; i++) { int level = 255 * i / (steps - 1); greys[i] = Color.FromArgb(255, level, level, level); } return greys; } // A remainder that stays in range for the negative cells left of and above the origin. private static int Wrap(int value, int count) { return ((value % count) + count) % count; } /// /// Returns which of colors the cell, or -1 when the cell is left as . /// public int SwatchAt(int column, int row) { return swatchAt(column, row); } } }