private static int RandomColor(Renderer.ColorScheme colorScheme, Random random) { switch (colorScheme) { case Renderer.ColorScheme.AllColors: return(random.Next(Renderer.firstColorIndex, Renderer.lastColorIndex)); // Decided to exclude the darkest gray value from this, thus the missing "+1" case Renderer.ColorScheme.GrayColors: return(random.Next(Renderer.firstMonochromeColorIndex, Renderer.lastColorIndex + 1)); case Renderer.ColorScheme.PastelColors: return(random.Next(Renderer.firstColorIndex, Renderer.lastPastelColorIndex + 1)); } return(1); // Added to make the compiler happy, not reachable }
public static void LoadXRandomBodies(GravitySim sim, int numBodies, Renderer.ColorScheme colorScheme) { const double baseMass = 100000.0; SetScenarioName(sim, String.Format("{0} Random Bodies Scenario ({1})", numBodies, colorScheme)); Random rand = new Random(); sim.ClearSim(); sim.SetSimSpace(new SimulationSpace(SimulationSpace.Space.Toy)); for (int i = 0; i < numBodies; i++) { double size = rand.NextDouble() * 4.0 + 1.0; // Mass as square of size sim.AddBody(size * size * baseMass, size * 10.0, RandomColor(colorScheme, rand), GravitySim.BodyStartPosition.RandomScreenPosition); } sim.SetMonitoredBody(numBodies - 1); sim.SetMonitoredValues(); sim.SetAccelerationLimits(true, toySpaceScenariosDefaultAccelerationLimit, toySpaceScenariosDeaultMinimumSeparation); }