private void RenderOrbit(Orbit orbit, float origin, float scale, System.Drawing.Graphics graphics, SolidBrush brush, int number = 0) { if (orbit == null) { return; } if (orbit.Orbiters != null) { // Check each orbiting object. foreach (var orbiter in orbit.Orbiters) { var localOrigin = origin; // We can only really draw something useful if we have a radius... if (orbiter.OrbitRadius != null) { // Figure out max radius of children. var maxOrbit = scale * GetMaxRadius(orbiter.Moons); // Draw actual stuff at max bounds. localOrigin += orbiter.OrbitRadius.High * scale; var orbiterFactory = FactoryManager.GetFactory(orbiter.Name) as PlanetFactory; if (orbiterFactory != null) { brush.Color = System.Drawing.Color.FromArgb(150, orbiterFactory.SurfaceTint.R, orbiterFactory.SurfaceTint.G, orbiterFactory.SurfaceTint.B); if (orbiterFactory.Radius != null) { var diameter = orbiterFactory.Radius.Low * scale * 2; graphics.FillEllipse(brush, localOrigin - diameter / 2f, pbPreview.Image.Height / 2f - diameter / 2f, diameter, diameter); diameter = orbiterFactory.Radius.High * scale * 2; graphics.FillEllipse(brush, localOrigin - diameter / 2f, pbPreview.Image.Height / 2f - diameter / 2f, diameter, diameter); maxOrbit = Math.Max(maxOrbit, orbiterFactory.Radius.High * scale); } } // Half the interval of variance we have for our radius. var halfVariance = scale * (orbiter.OrbitRadius.High - orbiter.OrbitRadius.Low) / 2f; // Add it to the max orbit to get the overall maximum possible // when rendering a circle with its center in the middle of the // variance interval. (and times two for width/height) maxOrbit = (maxOrbit + halfVariance) * 2; // Show the indicator of the maximum bounds for this orbiter. brush.Color = System.Drawing.Color.FromArgb(20, 255, 165, 0); graphics.FillEllipse(brush, origin + scale * orbiter.OrbitRadius.Low + halfVariance - maxOrbit / 2f, pbPreview.Image.Height / 2f - maxOrbit / 2f, maxOrbit, maxOrbit); // Draw own orbit. var color = OrbitColors[number % OrbitColors.Length]; using (var p = new Pen(System.Drawing.Color.FromArgb(210, color.R, color.G, color.B))) { float orbitX, orbitY; var eccentricity = orbiter.Eccentricity.Low; Orbiter.ComputeRadii(orbiter.OrbitRadius.High * scale, eccentricity, out orbitX, out orbitY); graphics.DrawEllipse(p, origin - orbitX + orbitX * eccentricity, pbPreview.Image.Height / 2f - orbitY, orbitX * 2, orbitY * 2); p.Color = System.Drawing.Color.FromArgb(110, color.R, color.G, color.B); eccentricity = orbiter.Eccentricity.High; Orbiter.ComputeRadii(orbiter.OrbitRadius.Low * scale, eccentricity, out orbitX, out orbitY); graphics.DrawEllipse(p, origin - orbitX + orbitX * eccentricity, pbPreview.Image.Height / 2f - orbitY, orbitX * 2, orbitY * 2); } } // Render children. RenderOrbit(orbiter.Moons, localOrigin, scale, graphics, brush, ++number); } } }