-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathKristjan.pde
64 lines (52 loc) · 1.87 KB
/
Kristjan.pde
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
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.util.Collections;
public class Disco extends LEDomePattern {
public static final int SET_COUNT = 3;
public static final float HUE_SEPARATION = 360 / SET_COUNT;
private LEDome dome;
private List<LEDomeFace> litFaces;
private List<List<LEDomeFace>> faceSets ;
private Random random = new Random();
public LEDomeAudioParameterFull tempo = new LEDomeAudioParameterFull("TPO", 6000, 5000, 12000);
private TriangleLFO beat = new TriangleLFO(0.0, 1.0, tempo);
public String getName() { return "Disco"; }
public Disco(LX lx) {
super(lx);
addParameter(tempo);
addModulator(beat).start();
this.dome = this.model;
this.litFaces = litFaces();
this.faceSets = new ArrayList<List<LEDomeFace>>();
for (int i = 0; i < SET_COUNT; i++) {
this.faceSets.add(new ArrayList<LEDomeFace>());
}
shuffleFaces();
}
public void run(double deltaMs) {
if (beat.getValue() > .95) shuffleFaces();
for (int i = 0; i < SET_COUNT; i++) {
for (LEDomeFace face : this.faceSets.get(i)) {
for (LXPoint p : face.points) {
float hue = (lx.palette.getHuef() + (HUE_SEPARATION * i + HUE_SEPARATION / 2)) % 360;
colors[p.index] = LXColor.hsb(hue, 100, 100 * (1 - beat.getValue()));
}
}
}
}
private List<LEDomeFace> litFaces() {
List<LEDomeFace> faces = new ArrayList<LEDomeFace>();
for (LEDomeFace face : this.dome.getFaces()) {
if (face.hasLights()) faces.add(face);
}
return faces;
}
private LEDomeFace randomLitFace() {
return this.litFaces.get(random.nextInt(this.litFaces.size()));
}
private void shuffleFaces() {
for (int i = 0; i < this.faceSets.size(); i++) this.faceSets.get(i).clear();
Collections.shuffle(this.litFaces);
for (int i = 0; i < this.litFaces.size(); i++) {
this.faceSets.get(i % SET_COUNT).add(this.litFaces.get(i));
}
}
}