forked from nottombrown/TitanicsEnd
/
Effects.pde
104 lines (83 loc) · 2.46 KB
/
Effects.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
class BeatMask extends LXEffect {
public final BasicParameter amount = new BasicParameter("AMOUNT", 0);
public BeatMask(LX lx) {
super(lx);
addParameter(amount);
}
public void run(double deltaMs) {
float scale = lerp(1, beat.getValuef(), amount.getValuef());
if (scale < 1) {
LXColor.scaleBrightness(this.colors, scale, null);
}
}
}
class Heartbeat extends LXEffect {
PGraphics g;
PImage heart;
float[] xZoomTargets;
float[] yZoomTargets;
float[] targetZooms;
float[] maxZooms;
float xTranslate = 0;
float yTranslate = 0;
float xTranslateStart = 0;
float yTranslateStart = 0;
color backgroundColor;
BasicParameter minSize = new BasicParameter("SIZE", 0.09, 0, 0.2);
BasicParameter pulseDelta = new BasicParameter("PULSE", 1, 0, 10);
Heartbeat(LX lx) {
super(lx);
addParameter(minSize);
addParameter(pulseDelta);
heart = new PImage();
heart = loadImage("images/heart.png");
backgroundColor = LXColor.hsb(0,0,0);
g = createGraphics(int(model.xRange), int(model.yRange));
}
PImage drawImage() {
float beatZoom = constrain(eq.getAveragef(1, 10)*pulseDelta.getValuef() + 1, 1., 1.5);
float zoom = beatZoom * minSize.getValuef();
g.imageMode(CENTER);
g.beginDraw();
g.background(backgroundColor);
g.noStroke();
g.pushMatrix();
g.translate(model.cx, model.cy);
g.scale(zoom, -zoom);
g.image(heart, 0, 0);
g.popMatrix();
g.endDraw();
return g.get();
}
float zoomSpeed = 1.02;
void update() {
}
public void run(double deltaMs) {
if (amulet.heartbeatMode.getValueb()){
update();
PImage img = drawImage();
for (LXPoint p : model.points) {
int ix, iy;
if (p.z > 0) {
ix = int((model.xRange - p.x - 5*FEET) / model.xRange * img.width);
iy = int(p.y / model.yRange * img.height);
}
else {
ix = int(p.x / model.xRange * img.width);
iy = int(p.y / model.yRange * img.height);
}
int imageColor = img.get(ix, iy);
int origColor = colors[p.index];
float[] origHSB = LXColor.RGBtoHSB(origColor, null);
// Invert the hues when the heart is on
if (LXColor.b(imageColor) > 50) {
colors[p.index] = LXColor.hsb(
-LXColor.h(origColor),
LXColor.s(origColor),
LXColor.b(origColor)
);
}
}
}
}
}