/// <summary> /// /// </summary> private void DisplayLayerDensity() { const string propName = "_Value"; CellLayer[] layers = _model.Stack.Layers; int layer0 = _currentLayer + 1; int layer1 = _model.CurrentLayer; for (int i = layer0; i <= layer1; i++) { CellLayer layer = layers[i]; float value = SlurMath.Normalize(layer.Density, _densityDisplay01Min, _densityDisplay01Max); foreach (var cell in layer.Cells) { // skip dead cells if (cell.State == 0) { continue; } // update cell material Renderer renderer = cell.Renderer; renderer.sharedMaterial = _densityMaterialForLayer; // set material properties renderer.GetPropertyBlock(_properties); _properties.SetFloat(propName, value); renderer.SetPropertyBlock(_properties); } } _currentLayer = layer1; }
private IEnumerator DisplayColor() { while (true) { foreach (var cell in _cells) { if (cell.State == 0) { continue; } MeshRenderer renderer = cell.Renderer; renderer.sharedMaterial = _ageMaterial; const string propName = "_Value"; { renderer.GetPropertyBlock(_properties); // normalize age float value = SlurMath.Normalize(cell.Age, _ageDisplayMin, _ageDisplayMax); _properties.SetFloat(propName, value); renderer.SetPropertyBlock(_properties); } // cell.GetComponent<MeshRenderer>().material.color = new Color(UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value); } yield return(new WaitForSeconds(0.1f)); } }
/// <summary> /// /// </summary> private void ShowFittest() { const string propName = "_Value"; var population = _population.Population; for (int i = 0; i < population.Count; i++) { var stack = population[i]; float value = SlurMath.Normalize(stack.Fitness, _population.MinFitness, _population.MaxFitness); if (value > _fitnessCutoff) { if (stack.gameObject.active == false) { stack.gameObject.SetActive(true); } } else { if (stack.gameObject.active == true) { stack.gameObject.SetActive(false); } } } }
private void ChangeColour() { const string propName = "_Value"; foreach (var cell in _modelManager.Cells) { // skip dead cells if (cell.State == 0) { continue; } // update cell material MeshRenderer renderer = cell.Renderer; renderer.sharedMaterial = _ageMaterial; // set material properties { renderer.GetPropertyBlock(_properties); // normalize age float value = SlurMath.Normalize(cell.Age, _ageDisplayMin, _ageDisplayMax); //Debug.Log(cell.Age); _properties.SetFloat(propName, value); renderer.SetPropertyBlock(_properties); } } }
/// <summary> /// /// </summary> private void DisplayFitness() { const string propName = "_Value"; var population = _population.Population; foreach (var stack in population) { // normalize fitness float value = SlurMath.Normalize(stack.Fitness, _population.MinFitness, _population.MaxFitness); if (stack.Fitness == _population.MaxFitness) { value = .999f; } if (stack.Fitness == _population.MinFitness) { value = .001f; } if (stack.gameObject.active == false) { continue; } foreach (var layer in stack.Layers) { foreach (var cell in layer.Cells) { // skip dead cells if (cell.State == 0) { continue; } // update cell material MeshRenderer renderer = cell.Renderer; renderer.sharedMaterial = _fitnessMaterial; // set material properties { renderer.GetPropertyBlock(_properties); _properties.SetFloat(propName, value); renderer.SetPropertyBlock(_properties); } } } } }
/// <summary> /// /// </summary> private void DisplayVNR2Density() { const string propName = "_Value"; CellLayer[] layers = _stack.Layers; //int layer0 = _currentLayer + 1; int layer0 = 0; int layer1 = _stack.Layers.Length; //apply material props to each obj renderer for (int k = layer0; k < layer1; k++) { Cell[,] cells = layers[k].Cells; int nrows = cells.GetLength(0); int ncols = cells.GetLength(1); for (int i = 0; i < nrows; i++) { for (int j = 0; j < ncols; j++) { Cell cell = cells[i, j]; // skip dead cells if (cell.State == 0) { continue; } // update cell material Renderer renderer = cell.Renderer; renderer.enabled = true; renderer.sharedMaterial = _densityMaterial; // set material properties renderer.GetPropertyBlock(_properties); // normalize density float density = GetNeighborDensity(cells, new Index2(i, j), Neighborhoods.VonNeumannR2); float value = SlurMath.Normalize(density, _densityDisplayMin, _densityDisplayMax); _properties.SetFloat(propName, value); cell.Renderer.SetPropertyBlock(_properties); } } } _currentLayer = layer1; }
private void DisplayOldCells() { const string propName = "_Value"; CellLayer[] layers = _model.Stack.Layers; int layer0 = _currentLayer + 1; int layer1 = _model.CurrentLayer; for (int i = layer0; i <= layer1; i++) { foreach (var cell in layers[i].Cells) { // skip dead cells if (cell.State == 0) { continue; } // update cell material MeshRenderer renderer = cell.Renderer; if (cell.Age < 10) { renderer.enabled = false; } if (cell.Age >= 10) { renderer.enabled = true; } renderer.sharedMaterial = _ageMaterial; // set material properties { renderer.GetPropertyBlock(_properties); // normalize age float value = SlurMath.Normalize(cell.Age, _ageDisplayMin, _ageDisplayMax); _properties.SetFloat(propName, value); renderer.SetPropertyBlock(_properties); } } } _currentLayer = layer1; }
/// <summary> /// /// </summary> private IEnumerator DisplayColor() { while (true) { yield return(new WaitForSeconds(1f)); const string propName = "_Value"; CellLayer[] layers = _model.Stack.Layers; int layer0 = _currentLayer + 1; int layer1 = _model.CurrentLayer; for (int i = layer0; i <= layer1; i++) { foreach (var cell in layers[i].Cells) { // skip dead cells if (cell.State == 0) { continue; } // update cell material MeshRenderer renderer = cell.Renderer; renderer.sharedMaterial = _ageMaterial; // set material properties { renderer.GetPropertyBlock(_properties); // normalize age float value = SlurMath.Normalize(cell.Age, _ageDisplayMin, _ageDisplayMax); _properties.SetFloat(propName, value); renderer.SetPropertyBlock(_properties); } } } _currentLayer = layer1; yield return(new WaitForSeconds(0.1f)); } }
/// <summary> /// /// </summary> /// <param name="weight"></param> /// <returns></returns> public float ToScale(float weight) { var t = SlurMath.Saturate(SlurMath.Normalize(weight, _weight0, _weight1)); return(SlurMath.Lerp(_scale0, _scale1, t)); }