// Use this for initialization void Start() { result = new Texture2D(size.x, size.y); cellular = new CellularAutomaton(size.x, size.y, fill); pixel_colors = new Color[size.x, size.y]; SyncColorsWithCells(); }
// Start is called before the first frame update void Start() { texture = new Texture2D(256, 256); automaton = new CellularAutomaton(256, 256, 35, 4, 1); float[,] values = automaton.LifeNoise(); texture.SetPixels32(floatToColor32(values)); texture.Apply(); }
IEnumerator Test() { celAuto = new CellularAutomaton((int)worldSize.x * Chunk.chunkSize, (int)worldSize.z * Chunk.chunkSize, Ruleset.majority, 0.5f, true); generate = true; yield return(new WaitForSeconds(1f)); generate = false; StartCoroutine(GenerateWorldCoroutine()); }
private void Generate() { automaton = new CellularAutomaton(config); GeneratePalette(); deadColor = GetMainColorHSV().WithSV(0.3f, 0.2f).ToColor(); aliveColor = GetMainColorHSV().ToColor(); }
private static IHeightMap GenerateRocks(int seed, int x, int y, double density) { CellularAutomaton ca = new CellularAutomaton(seed, new RuleSet(Lerp(0.1, 0.3, density), false, (region, generation) => region.GetNeighbors() > 2)); IHeightMap layer1 = new BooleanMap(ca.Generate(x, y, 4)); IHeightMap layer2 = new BooleanMap(ca.Generate(x, y, 2)); return(new HeightMap(2, ValueArray.Create(x, y, (i, j) => layer1[i, j] + layer2[i, j]))); }
IEnumerator GenerateCelAuto() { celAuto = new CellularAutomaton(WorldController.worldsize, WorldController.worldsize, Ruleset.majority, 0.5f, true); generate = true; //yield return new WaitForSeconds(1f); generate = false; StartCoroutine(GenerateWorld()); //yield return new WaitForSeconds(1f); yield return(null); }
public Map(CellularAutomaton ca, int border) { this.W = ca.Width + border * 2; this.H = ca.Height + border * 2; this.T = new byte[H, W]; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { bool outside = i < border || j < border || i >= (H - border) || j >= (W - border); T[i, j] = outside ? (byte)0 : ca[i - border, j - border]; } } }
void Start() { //CellularAutomaton ca = new CellularAutomaton(50, 50, "45678/5678"); ////ca[1, 0] = ca[1, 1] = ca[1, 2] = 1; //Blinker ////ca[1, 1] = ca[1, 2] = ca[1, 3] = ////ca[2, 0] = ca[2, 1] = ca[2, 2] = 1; //Toad //for (int i = 0; i < 50; i++) //{ // for (int j = 0; j < 50; j++) // { // ca[i,j] = (byte)(Random.value < 0.55f ? 1 : 0); // } //} //testCA = new TestCellularAutomaton(ca); CellularAutomaton ca = new CellularAutomaton(100, 50, "45678/5678"); for (int i = 0; i < 50; i++) { for (int j = 0; j < 100; j++) { ca[i, j] = (byte)(Random.value < 0.55f ? 1 : 0); } } for (int i = 0; i < 10; i++) { ca.UpdateTiles(); } //Map map = new Map(4, 4); //map.T = new byte[,] //{ // { 0,1,0,1 }, // { 1,0,1,0 }, // { 1,1,1,1 }, // { 1,1,1,1 } //}; map = new Map(ca, 3); GameObject mapVisual = GameObject.Find("Map"); mapVisual.GetComponent <MapVisual>().Build(map, 1, 2); }
public virtual void Init(int width, int height, IntPoint2D[] initialState) { _width = width; _height = height; _board = new Toroidal2DBoard <StateType>(new IntPoint2D() { x = width, y = height }); _cellularAutomaton = new CellularAutomaton <StateType, IntPoint2D>(_board, new RuleType()); foreach (var point in initialState) { var newState = new StateType(); newState.SetActive(); _board.SetState(point, newState); } }
private void GenerateCave() { CellularAutomaton cave = new CellularAutomaton(WidthFull, HeightFull); cave.Simulate(ExplorerConstants.Generation.CaveSurviveStates, ExplorerConstants.Generation.CaveBornStates, CellularAutomaton.BorderType.Solid, ExplorerConstants.Generation.CaveDensity, ExplorerConstants.Generation.CaveSimulations); byte[,] caveData = cave.GetGrid(); //First, convert basic cave data to actual map data for (int i = 0; i < WidthFull; i++) { for (int j = 0; j < HeightFull; j++) { ForcePut(ExplorerConstants.Items.IDS.CaveFloor, i, j); if (caveData[i, j] > 0) ForcePut(ExplorerConstants.Items.IDS.CaveStone, i, j); } } //Gather up the 3x3 empty spaces List<Tuple<int, int>> emptyBlocks = GetEmptyBlocks(2); //Not empty enough yo if (emptyBlocks.Count == 0) { GenerateCave(); return; } //Now find a nice place to put the spawn and jam it there. Tuple<int, int> spawnTuple = emptyBlocks[random.Next(emptyBlocks.Count)]; emptyBlocks.RemoveAll(x => Math.Abs(x.Item1 - spawnTuple.Item1) < 5 && Math.Abs(x.Item2 - spawnTuple.Item2) < 5); //Eww, we're repurposing the spawn parameters as block spawn! spawnAcreX = spawnTuple.Item1 + 1; spawnAcreY = spawnTuple.Item2 + 1; //Set up the area for(int i = -1; i <= 1; i++) for(int j = -1; j <= 1; j++) ForcePut(ExplorerConstants.Items.IDS.CaveFloor2, spawnTuple.Item1 + i, spawnTuple.Item2 + j); //Put the "ladder" ForcePut(ExplorerConstants.Items.IDS.CaveExit, spawnTuple.Item1, spawnTuple.Item2); //Now pick 2/3 of the random cave items and stick them in there too List<ExplorerConstants.Items.IDS> leftoverLoot = new List<ExplorerConstants.Items.IDS>(ExplorerConstants.Items.CaveLoot); for (int i = 0; i < ExplorerConstants.Items.CaveLoot.Count * 2 / 3; i++) { Tuple<int, int> lootTuple = emptyBlocks[random.Next(emptyBlocks.Count)]; emptyBlocks.RemoveAll(x => Math.Abs(x.Item1 - lootTuple.Item1) < 5 && Math.Abs(x.Item2 - lootTuple.Item2) < 5); if (emptyBlocks.Count == 0) { GenerateCave(); return; } //Set up the area for (int x = -1; x <= 1; x++) for (int y = -1; y <= 1; y++) ForcePut(ExplorerConstants.Items.IDS.CaveFloor2, lootTuple.Item1 + x, lootTuple.Item2 + y); //Put the loot ExplorerConstants.Items.IDS loot = (i == 0 ? ExplorerConstants.Items.IDS.StarCrystal : leftoverLoot[random.Next(leftoverLoot.Count)]); ForcePut(loot, lootTuple.Item1,lootTuple.Item2); leftoverLoot.Remove(loot); } }
public TestCellularAutomaton(CellularAutomaton ca) { this.ca = ca; }
private void GenerateChasmsAndLakes(ref int[,] data) { CellularAutomaton automaton = new CellularAutomaton(96, 96); automaton.Spawn(0.55f); automaton.Iterate(6, 4, 10); data = automaton.Data; MapHelpers.Smooth(ref data, 4, 3); for (int i = 0; i <= 2; i++) { Point point = new Point( UnityEngine.Random.Range(0, m_width - 1), UnityEngine.Random.Range(0, m_depth - 1)); int sample = data[point.X, point.Y]; if (sample == TerrainType.Generator_Default) { MapHelpers.FloodFill(ref data, point, TerrainType.Generator_Default, TerrainType.Generator_Secondary); } } }
private static bool[,] GenerateWalls(int seed, int x, int y, double density) { CellularAutomaton ca = new CellularAutomaton(seed, new RuleSet(Lerp(0.35, 0.5, density), true, (region, generation) => region.GetNeighbors() > 4)); return(ca.Generate(x, y, 11)); }
static void Main(string[] args) { int width = 64; int generations = 128; int rule = 30; int scale = 1; string filename = "cells.png"; string defaultFilename = filename; Console.Write("Enter the size of the world. [" + width + "] "); int defaultWidth = width; if (!Int32.TryParse(Console.ReadLine(), out width)) width = defaultWidth; Console.Write("Enter the desired number of generations to run. [" + generations + "] "); int defaultGenerations = generations; if (!Int32.TryParse(Console.ReadLine(), out generations)) generations = defaultGenerations; Console.Write("Enter the rule to use. [" + rule + "] "); int defaultRule = rule; if (!Int32.TryParse(Console.ReadLine(), out rule)) rule = defaultRule; Console.Write("Enter the path where the generated image should be saved. [" + filename + "] "); filename = Console.ReadLine(); Console.Write("Enter image scale multiplier. [" + scale + "] "); int defaultScale = scale; if (!Int32.TryParse(Console.ReadLine(), out scale)) scale = defaultScale; CellularAutomaton ca = new CellularAutomaton(rule, width); Console.Write("Enter \"r\" for random starting seed or \"s\" for single cell. [r] "); string choice = Console.ReadLine(); if (choice == "s") { List<byte> startingField = new List<byte>(); for (int i = 0; i < width; i++) { startingField.Add(0); if (Math.Floor(width / 2f) == i) { startingField[i] = 1; } } ca = new CellularAutomaton(rule, width, startingField); } for (int i = 0; i < generations; i++) { ca.Generate(); Console.WriteLine(ca.ToString()); } try { ca.ToImage().Save(filename); } catch(ArgumentException) { ca.ToImage(scale).Save(defaultFilename); } }
public CellularAutomatonMixIsland(MatrixRange matrixRange, uint loopNum, IList <int> list) { this.loopNum = loopNum; this.mixRect = new HalfMixRect(matrixRange, list); this.cellularAutomaton = new CellularAutomaton(matrixRange); }