1 package org.opentrafficsim.road.gtu.colorer;
2
3 import java.awt.Color;
4 import java.util.ArrayList;
5 import java.util.List;
6
7 import org.opentrafficsim.core.animation.ColorInterpolator;
8 import org.opentrafficsim.core.animation.gtu.colorer.GTUColorer;
9 import org.opentrafficsim.core.gtu.GTU;
10 import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.Tailgating;
11
12
13
14
15
16
17
18
19
20
21
22
23 public class SocialPressureColorer implements GTUColorer
24 {
25
26
27 private static final List<LegendEntry> LEGEND;
28
29
30 private static final Color NONE = Color.WHITE;
31
32
33 private static final Color FULL = Color.RED;
34
35
36 private static final Color NA = Color.YELLOW;
37
38 static
39 {
40 LEGEND = new ArrayList<>(3);
41 LEGEND.add(new LegendEntry(NONE, "None", "None: 0.0"));
42 LEGEND.add(new LegendEntry(FULL, "Full", "Full: 1.0"));
43 LEGEND.add(new LegendEntry(NA, "N/A", "N/A"));
44 }
45
46
47 @Override
48 public Color getColor(final GTU gtu)
49 {
50 try
51 {
52 double rho = gtu.getParameters().getParameter(Tailgating.RHO);
53 return ColorInterpolator.interpolateColor(NONE, FULL, rho);
54 }
55 catch (Exception exception)
56 {
57 return NA;
58 }
59 }
60
61
62 @Override
63 public List<LegendEntry> getLegend()
64 {
65 return LEGEND;
66 }
67
68
69 @Override
70 public String toString()
71 {
72 return "Social pressure";
73 }
74
75 }