/// <summary> /// Create a new Cave Generator /// </summary> /// <param name="input">The input map, usually white noise</param> /// <param name="threshold">Input values below this threshold will be treated as zero</param> /// <param name="iterations">How many times to iterate the automata, higher values give smoother caves, but are slow</param> /// <param name="searchRadius">Neighbour search radius</param> /// <param name="birthRule"></param> /// <param name="deathRule"></param> public CaveGenerator(ValueMap input, float threshold, int iterations = 3, int searchRadius = 1, int birthRule = 2, int deathRule = 3) { this.threshold = threshold; this.iterations = iterations; this.searchRadius = searchRadius; this.birthRule = birthRule; this.deathRule = deathRule; this.input = input; size = new Vector2Int(input.Width, input.Height); map = ValueMap.CreateInstance(size); buffer = ValueMap.CreateInstance(size); }
public override object GetValue(NodePort port) { var graph = (Terra2DGraph)this.graph; if (graph.isComputing) { try { output = ValueMap.CreateInstance(graph.size.x, graph.size.y, gradient, vertical); return(output); } catch (System.Exception e) { graph.isComputing = false; throw e; } } return(null); }
public ValueMap Generate() { // initialize maze = ValueMap.CreateInstance(size.x, size.y); random = new System.Random(seed.GetHashCode()); List <Vector2Int> activeCells = new List <Vector2Int>(); // add the start cell to the active list activeCells.Add(start); maze[start.x, start.y] = 1; // while active list is not empty while (activeCells.Count > 0) { // select cell from active list // randomly selected based on waviness // higher waviness produces long winding passages with fewer dead ends, and vice versa int cellIndex = random.NextDouble() > waviness?random.Next(activeCells.Count) : activeCells.Count - 1; var cell = activeCells[cellIndex]; // get untraversed neighbours of selected cell var neighbours = GetNeighbours(cell.x, cell.y); if (neighbours.Count > 0) { // randomly select a neighbour and connect it to the selected cell var neighbour = neighbours[random.Next(neighbours.Count)]; maze.ConnectCells(cell, neighbour, 1); // add that neighbour to the active list activeCells.Add(neighbour); } else { // if no traversable neighbours, remove cell from active list activeCells.Remove(cell); } } return(maze); }
public static ValueMap CellNoise(int seed, Vector2Int size, Vector2 offset, FastNoise.CellularDistanceFunction distanceFunction, FastNoise.CellularReturnType returnType, float jitter = 0.45f, float frequency = 0.02f) { var noise = new FastNoise(seed); noise.SetCellularDistanceFunction(distanceFunction); noise.SetCellularReturnType(returnType); noise.SetCellularJitter(jitter); noise.SetFrequency(frequency); ValueMap output = ValueMap.CreateInstance(size); for (int x = 0; x < size.x; x++) { for (int y = 0; y < size.y; y++) { output[x, y] = noise.GetCellular(offset.x + x, offset.y + y); } } return(output); }