Skip to content

Commit

Permalink
enable coloring by agent vision
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelBuhler committed Jul 12, 2020
1 parent d540f1d commit f9da486
Show file tree
Hide file tree
Showing 5 changed files with 362 additions and 1 deletion.
14 changes: 14 additions & 0 deletions Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ public void Render () {
case State.ColoringOptions.BY_SEX:
renderer.sharedMaterial = sex == Sex.MALE ? Materials.MALE : Materials.FEMALE;
break;
case State.ColoringOptions.BY_VISION:
{
float range = Simulation.Parameters.Vision.MAX - Simulation.Parameters.Vision.MIN;
float a = Simulation.Parameters.Vision.MIN + range * 1 / 3;
float b = Simulation.Parameters.Vision.MIN + range * 2 / 3;
if ( vision < a ) {
renderer.sharedMaterial = Materials.LOW_VISION;
} else if ( vision < b ) {
renderer.sharedMaterial = Materials.MEDIUM_VISION;
} else {
renderer.sharedMaterial = Materials.HIGH_VISION;
}
}
break;
}
}

Expand Down
14 changes: 14 additions & 0 deletions Materials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public class Materials {
public static readonly Material MALE;
public static readonly Material FEMALE;

public static readonly Material LOW_VISION;
public static readonly Material MEDIUM_VISION;
public static readonly Material HIGH_VISION;

static Materials () {
GROUND = new Material(Shaders.Legacy.DIFFUSE) {
color = Color.white
Expand All @@ -31,6 +35,16 @@ static Materials () {
FEMALE = new Material(Shaders.Legacy.DIFFUSE) {
color = Color.blue
};

LOW_VISION = new Material(Shaders.Legacy.DIFFUSE) {
color = Color.red
};
MEDIUM_VISION = new Material(Shaders.Legacy.DIFFUSE) {
color = new Color(0.5f, 0, 0.5f, 1) // purple
};
HIGH_VISION = new Material(Shaders.Legacy.DIFFUSE) {
color = Color.blue
};
}

}
3 changes: 2 additions & 1 deletion State.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ public class State {

public enum ColoringOptions {
DEFAULT,
BY_SEX
BY_SEX,
BY_VISION
}

public static float DELTA_TIME = 0;
Expand Down
8 changes: 8 additions & 0 deletions UI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ public void ColorsSexToggled (bool value) {
}
}

public void ColorsVisionToggled (bool value) {
if ( value ) {
State.COLORING_OPTION = State.ColoringOptions.BY_VISION;
colorsDescription.text = "low is red, medium is purple, high is blue";
Simulation.Render();
}
}

public void EndowmentMaxUnfocused (string value) {
if ( value.Length > 0 ) {
int num = Mathf.Max(Simulation.Parameters.Endowment.MIN, int.Parse(value));
Expand Down
Loading

0 comments on commit f9da486

Please sign in to comment.