-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomColour.java
More file actions
51 lines (49 loc) · 1.5 KB
/
RandomColour.java
File metadata and controls
51 lines (49 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.awt.Color;
import java.util.*;
public class RandomColour{
private int length;
private Color [] myColors;
private int num = -1;
public RandomColour(int length) {
//System.out.println(length);
this.length = length;
this.myColors= new Color[length];
populateColors();
}
public Color getNext() {
if(num+1 == length) num = -1;
return myColors[++num];
}
private int Range = 120;
private void populateColors(){
Random r = new Random();
///0 -> Red, 1->Green, 2->Blue
///Choosing 135-255 for dominant, 55-175 for secondary, 0-110 for third.
///I really need a better way of ordering 3 elements.
int dc = r.nextInt(6);
Color root = new Color(1, 2, 3);
switch (dc) {
//GBR
case 0: root = new Color(r.nextInt(Range)+0, r.nextInt(Range)+135, r.nextInt(Range)+70);
break;
//RGB
case 1: root = new Color(r.nextInt(Range)+135, r.nextInt(Range)+70, r.nextInt(Range)+0);
break;
//RBG
case 2: root = new Color(r.nextInt(Range)+135, r.nextInt(Range)+0, r.nextInt(Range)+70);
break;
//BRG
case 3: root = new Color(r.nextInt(Range)+70, r.nextInt(Range)+0, r.nextInt(Range)+135);
break;
//BGR
case 4: root = new Color(r.nextInt(Range)+0, r.nextInt(Range)+70, r.nextInt(Range)+135);
break;
//GRB
case 5: root = new Color(r.nextInt(Range)+70, r.nextInt(Range)+135,r.nextInt(Range)+0);
break;
}
for(int i = 0; i<length;i++) {
myColors[i] = root;
}
}
}