1
2
3
4
5
6 package nl.tudelft.goal.ut2004.visualizer.map;
7
8 import java.awt.Color;
9
10
11
12
13
14
15
16 public class TeamShade {
17
18 private Color personalBase;
19 private Color personalRed;
20 private Color personalBlue;
21
22 private Color redTeam;
23 private Color blueTeam;
24
25 private static final double TEAM_COLOR_STRENGHT = 0.25;
26
27 public TeamShade(){
28 this(randomColor());
29 }
30
31 public TeamShade(Color personalColor) {
32 this(personalColor, Color.RED, Color.BLUE);
33 }
34
35 public TeamShade(Color redteam, Color blueTeam) {
36 this(randomColor(), redteam, blueTeam);
37 }
38
39 public TeamShade(Color personalColor, Color redTeam, Color blueTeam) {
40 this.personalBase = personalColor;
41 this.redTeam = redTeam;
42 this.blueTeam = blueTeam;
43
44 personalRed = mix(redTeam, personalBase, TEAM_COLOR_STRENGHT);
45 personalBlue = mix(blueTeam, personalBase, TEAM_COLOR_STRENGHT);
46 }
47
48 public Color getColor(int team) {
49 switch (team) {
50 case 0:
51 return personalRed;
52 case 1:
53 return personalBlue;
54 default:
55 return personalBase;
56 }
57 }
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73 private Color mix(Color a, Color b, double portion) {
74 double thisPortion = 1 - portion;
75 return new Color(
76
77 (int) (thisPortion * a.getRed()) + (int) (portion * b.getRed()),
78
79 (int) (thisPortion * a.getGreen()) + (int) (portion * b.getGreen()),
80
81 (int) (thisPortion * a.getBlue()) + (int) (portion * b.getBlue()),
82
83 (int) (thisPortion * a.getAlpha()) + (int) (portion * b.getAlpha()));
84 }
85
86 private static Color randomColor() {
87 return new Color((float) Math.random(), (float) Math.random(), (float) Math.random());
88 }
89
90 public Color getRedTeam() {
91 return redTeam;
92 }
93
94 public void setRedTeam(Color redTeam) {
95 this.redTeam = redTeam;
96 personalRed = mix(redTeam, personalBase, TEAM_COLOR_STRENGHT);
97 }
98
99 public Color getBlueTeam() {
100 return blueTeam;
101 }
102
103 public void setBlueTeam(Color blueTeam) {
104 this.blueTeam = blueTeam;
105 personalBlue = mix(blueTeam, personalBase, TEAM_COLOR_STRENGHT);
106 }
107
108 }