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 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; }
private Node TreeDistribution(Rectangle area, Color[] colors, BodyRenderer renderer) { var hexagons = new Node(); var radius = 2; var spacing = 4; var mapWidth = area.Width / spacing - 3; var mapHeight = area.Height / spacing - 1; var map = new HexagonMap<bool>(mapWidth, mapHeight); var first = new Hexagon(Rand.Floor(mapWidth), Rand.Floor(mapHeight)); map[first] = true; hexagons.Add(BuildHexagon(renderer, colors, first, radius, spacing)); var current = first; var n = 5 + Rand.Floor(10); for (int i = 0; i < n; i++) { var freeNeighbors = current.GetNeighborsWhere(hexagon => map.IsInBound(hexagon) && !map[hexagon]).ToArray(); if (!freeNeighbors.Any()) break; current = freeNeighbors.RandomItem(); map[current] = true; hexagons.Add(BuildHexagon(renderer, colors, current, radius, spacing)); } return hexagons; }
public static Hexagon GetNeighbor(Hexagon node, int direction) { var d = Directions[direction]; return new Hexagon(node.Q + d.Q, node.R + d.R); }