private Body BuildHexagon(BodyRenderer renderer, Color[] colors, Hexagon hex, float radius, float spacing) { var pos = hex.GetPosition(spacing); pos += new Vector2(radius) * Rand.Sign(); var color = colors.RandomItem(); return BuildHexagon(renderer, color, pos, radius, spacing); }
private Node GridDistribution(Rectangle area, Color[] colors, BodyRenderer renderer) { var hexagons = new Node(); var r = 8; var x = r * (float)Math.Sqrt(3); var y = r * 2f; var n = area.Width / x - 1; var m = area.Height / y - 1; var o = new Vector2(r + 3, r); var d = r; for (var i = 0; i < n; i++) { o += new Vector2(0, d); d = -d; for (var j = 0; j < m; j++) { if (Rand.Float() < .6f) continue; var pos = o + new Vector2(i * x, j * y); var color = colors.RandomItem(); hexagons.Add(BuildHexagon(renderer, color, pos, r, r)); } } return hexagons; }
private IEnumerable<Body> SpiralRingDistribution(BodyRenderer renderer, Color[] colors, Vector2 origin, float size, float spacing, int spiralRadius, float chance) { var hexagons = new List<Body>(); var center = new Hexagon(0, 0); var color = colors.RandomItem(); var pos = origin + center.GetPosition(spacing); //hexagons.Add(BuildHexagon(render, color, pos, size, spacing)); var ring = center.GetSpiralRing(spiralRadius); foreach (var hexagon in ring) { pos = origin + hexagon.GetPosition(spacing); var rand = Rand.Float(); if (rand < chance) { if (rand > chance / 2) continue; var newSize = size / 3; var newSpacing = spacing / 3; if (newSpacing > .5f) { hexagons.AddRange(SpiralRingDistribution(renderer, colors, pos, newSize, newSpacing, 1, chance)); } continue; } color = colors.RandomItem(); hexagons.Add(BuildHexagon(renderer, color, pos, size, spacing)); } return hexagons; }