Skip to content

Commit 2a64237

Browse files
committed
Simplify code
Rects where used because the strokeWeight wasn't working in Processing 2 in the OpenGL mode. Since this is fixed we can simplify the effects and prossibly make them work with a real laser. Add retina support for macOS.
1 parent e988884 commit 2a64237

File tree

5 files changed

+103
-94
lines changed

5 files changed

+103
-94
lines changed

MusicBeam/Derby_Effect.pde

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,57 +46,65 @@ class Derby_Effect extends Effect
4646
aHueToggle.getCaptionLabel().set("A").align(ControlP5.CENTER, ControlP5.CENTER);
4747
aHueToggle.setState(true);
4848
}
49+
50+
int weight, points, hue;
51+
float speed;
4952

5053
void draw()
5154
{
52-
float width = stg.width-weightSlider.getValue();
53-
float height = stg.height-weightSlider.getValue();
54-
float points = int(pointSlider.getValue());
55+
weight = int(weightSlider.getValue());
56+
points = int(pointSlider.getValue());
57+
hue = int(hueSlider.getValue());
58+
speed = speedSlider.getValue();
59+
60+
float width = stg.width-weight;
61+
float height = stg.height-weight;
5562

5663
int countTrigger = 0;
5764
if(isHat()) countTrigger++;
5865
if(isSnare()) countTrigger++;
5966
if(isKick()) countTrigger++;
6067

6168
translate(-stg.width/2, -stg.height/2);
62-
stg.fill(hueSlider.getValue(), 100, 100);
63-
for (int i=1;i<=points;i++)
64-
{
65-
stg.ellipse(weightSlider.getValue()/2+i*width/(points+1)+cos(rotation)*width/(points+1), weightSlider.getValue()/2+height/3-height/3*sin(rotation), weightSlider.getValue()*0.9, weightSlider.getValue()*0.9);
66-
}
67-
if (mirrorToggle.getState())
68-
for (int i=1;i<=points;i++)
69-
{
70-
stg.ellipse(weightSlider.getValue()/2+i*width/(points+1)-cos(rotation)*width/(points+1), weightSlider.getValue()/2+height/3-height/3*sin(rotation), weightSlider.getValue()*0.9, weightSlider.getValue()*0.9);
71-
}
72-
73-
stg.fill((hueSlider.getValue()+120)%360, 100, 100);
69+
7470
for (int i=1;i<=points;i++)
7571
{
76-
stg.ellipse(weightSlider.getValue()/2+i*width/(points+1)+cos(rotation)*width/(points+1), weightSlider.getValue()/2+2*height/3-height/3*-sin(rotation), weightSlider.getValue()*0.9, weightSlider.getValue()*0.9);
72+
float posx = weight/2+i * width/(points+1);
73+
float rotx = width/(points+1) * cos(rotation);
74+
float posy = weight/2+height/3;
75+
float roty = -height/3 * sin(rotation);
76+
77+
stg.fill(hue, 100, 100);
78+
79+
stg.ellipse(posx+rotx, posy+roty, weight*0.9, weight*0.9);
80+
81+
if (mirrorToggle.getState())
82+
stg.ellipse(posx-rotx, posy+roty, weight*0.9, weight*0.9);
83+
84+
stg.fill((hue+120)%360, 100, 100);
85+
86+
stg.ellipse(posx+rotx, height/3 + posy-roty, weight*0.9, weight*0.9);
87+
88+
if (mirrorToggle.getState())
89+
stg.ellipse(posx-rotx, height/3 + posy-roty, weight*0.9, weight*0.9);
90+
7791
}
7892

79-
if (mirrorToggle.getState())
80-
for (int i=1;i<=points;i++)
81-
{
82-
stg.ellipse(weightSlider.getValue()/2+i*width/(points+1)-cos(rotation)*width/(points+1), weightSlider.getValue()/2+2*height/3-height/3*-sin(rotation), weightSlider.getValue()*0.9, weightSlider.getValue()*0.9);
83-
}
84-
8593
if (aHueToggle.getState() && countTrigger >= 2)
86-
hueSlider.setValue((hueSlider.getValue()+120)%360);
94+
hueSlider.setValue((hue+120)%360);
8795

8896
if (rotation%(PI/2)>0.1) {
8997
moving = false;
90-
rotation = rotation + speedSlider.getValue()/10%(2*PI);
98+
rotation = rotation + speed/10%(2*PI);
9199
}
92100
else if (rotation%(PI/2)<=0.1 && (isKick() || isSnare() || isOnset() || moving)) {
93101
moving = true;
94-
rotation = rotation + speedSlider.getValue()/10%(2*PI);
102+
rotation = rotation + speed/10%(2*PI);
95103
}
96104
else
97105
{
98106
rotation = rotation + getLevel()/100%(2*PI);
99107
moving = false;
100108
}
101109
}
102-
}
110+
}

MusicBeam/MusicBeam.pde

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ int height = 570;
4848
float maxLevel = 0;
4949
float goalMaxLevel=0;
5050
void settings() {
51+
pixelDensity(displayDensity());
5152
initAudioInput();
5253

5354
if(!hasEnoughScreenDevices()) {
@@ -64,7 +65,7 @@ void settings() {
6465

6566
void setup() {
6667
surface.setTitle("MusicBeam v"+version);
67-
68+
6869
colorMode(HSB, 360, 100, 100);
6970

7071
initControls();
@@ -204,7 +205,7 @@ void drawBeatHistory(LinkedList<Beat> history, int x, int y)
204205
void initControls()
205206
{
206207
cp5 = new ControlP5(this);
207-
cp5.setFont(createFont("Monospace", 12));
208+
cp5.setFont(createFont("Monospace", 12 / displayDensity()));
208209
beatDelaySlider = cp5.addSlider("beatDelay").setSize(395, 20).setPosition(10, 134).setRange(10, 1000);
209210
beatDelaySlider.getCaptionLabel().set("Beat Delay (ms)").align(ControlP5.CENTER, ControlP5.CENTER);
210211
beatDelaySlider.setValue(200);
@@ -333,8 +334,8 @@ float getLevel()
333334

334335
private boolean hasEnoughScreenDevices()
335336
{
336-
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
337-
GraphicsDevice[] gs = ge.getScreenDevices(); //<>//
337+
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); //<>//
338+
GraphicsDevice[] gs = ge.getScreenDevices();
338339
return gs.length > 1;
339340
}
340341

MusicBeam/Polygon_Effect.pde

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ class Polygon_Effect extends Effect
44
{
55
return "Polygon";
66
}
7-
7+
88
char triggeredByKey() {
99
return '8';
1010
}
1111

12-
int winHeight = 200;
13-
14-
float[] px, py, pxs, pys;
12+
float[] px, py;
1513

1614

1715
float rotation = 0;
@@ -48,56 +46,48 @@ class Polygon_Effect extends Effect
4846
aHueToggle.getCaptionLabel().set("A").align(ControlP5.CENTER, ControlP5.CENTER);
4947
aHueToggle.setState(true);
5048
}
49+
50+
int points, weight, radius, hue;
5151

5252
void draw() {
5353

54-
int points = int(pointsSlider.getValue());
55-
float weight = weightSlider.getValue();
56-
float radius = stg.getMinRadius()-weight;
57-
float c = hueSlider.getValue();
54+
points = int(pointsSlider.getValue());
55+
weight = int(weightSlider.getValue());
56+
hue = int(hueSlider.getValue());
5857

5958
setEllipse();
6059

6160
rotate(rotation);
6261
for (int i=0; i < points; i++) {
63-
stg.fill((((i%2)==1?120:0)+c)%360, 100, 100);
64-
if (i==points-1) {
65-
stg.quad(px[i], py[i], px[0], py[0], pxs[0], pys[0], pxs[i], pys[i]);
66-
stg.fill(-1);
67-
stg.ellipse((px[0]-pxs[0])/2+pxs[0], (py[0]-pys[0])/2+pys[0], 1.5*weight, 1.5*weight);
68-
}
69-
else {
70-
stg.quad(px[i], py[i], px[i+1], py[i+1], pxs[i+1], pys[i+1], pxs[i], pys[i]);
71-
}
62+
int prev = (i + 1) % points;
63+
stg.stroke((((i%2)==1?120:0)+hue)%360, 100, 100);
64+
stg.strokeWeight(weight);
65+
stg.line(px[i], py[i], px[prev], py[prev]);
7266
stg.fill(-1);
73-
stg.ellipse((px[i]-pxs[i])/2+pxs[i], (py[i]-pys[i])/2+pys[i], 1.5*weight, 1.5*weight);
67+
stg.noStroke();
68+
stg.ellipse(px[i], py[i], 1.5*weight, 1.5*weight);
69+
stg.ellipse(px[prev], py[prev], 1.5*weight, 1.5*weight);
7470
}
7571
rotation = (rotation+rotationSpeedSlider.getValue()/20)%(2*PI);
7672

7773
if (aHueToggle.getState()&& (isKick()&&isSnare()))
78-
hueSlider.setValue((hueSlider.getValue()+120)%360);
74+
hueSlider.setValue((hue+120)%360);
7975
}
8076

8177
// fill up arrays with ellipse coordinate data
8278
void setEllipse() {
83-
int points = int(pointsSlider.getValue());
84-
float weight = weightSlider.getValue();
85-
float radius = stg.getMinRadius()/2-1.5*weight;
8679
px = new float[points];
8780
py = new float[points];
88-
pxs = new float[points];
89-
pys = new float[points];
81+
float radius = stg.getMinRadius()/2-1.5*weight;
9082
float angle = 360.0/points;
9183
for ( int i=0; i<points; i++) {
92-
px[i] = cos(radians(angle))*radius;
93-
py[i] = sin(radians(angle))*radius;
94-
pxs[i] = cos(radians(angle))*(radius+weightSlider.getValue());
95-
pys[i] = sin(radians(angle))*(radius+weightSlider.getValue());
84+
px[i] = cos(radians(angle))*(radius + weight / 2);
85+
py[i] = sin(radians(angle))*(radius + weight / 2);
9686
angle+=360.0/points;
9787
}
9888
}
99-
100-
void keyPressed(char key, int keyCode)
89+
90+
void keyPressed(char key, int keyCode)
10191
{
10292
super.keyPressed(key, keyCode);
10393
if (key == CODED) {

MusicBeam/Scanner_Effect.pde

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Scanner_Effect extends Effect
2828
{
2929
return "Scanner";
3030
}
31-
31+
3232
char triggeredByKey() {
3333
return '2';
3434
}
@@ -39,12 +39,20 @@ class Scanner_Effect extends Effect
3939

4040
Toggle aHueToggle, bwToggle;
4141

42+
int hue, weight;
43+
float speed;
44+
4245
void draw()
4346
{
4447

45-
stg.fill(hueSlider.getValue(), 100, 100);
48+
hue = int(hueSlider.getValue());
49+
weight = int(weightSlider.getValue());
50+
speed = speedSlider.getValue();
51+
52+
stg.stroke(hue, 100, 100);
53+
stg.strokeWeight(weight);
4654

47-
rotation = (rotation+speedSlider.getValue()/20)%(9*PI);
55+
rotation = (rotation+speed/20)%(9*PI);
4856

4957
if (rotation<PI)
5058
rotateRight();
@@ -60,73 +68,70 @@ class Scanner_Effect extends Effect
6068
{
6169
rotate(PI/2);
6270
LinesDissolve();
63-
}
64-
else if (rotation<PI*7)
71+
} else if (rotation<PI*7)
6572
{
6673
rotate(PI/2);
6774
LinesJoin();
68-
}
69-
else if (rotation<PI*8)
75+
} else if (rotation<PI*8)
7076
{
7177
LinesDissolve();
7278
resetStage();
7379
rotate(PI/2);
74-
stg.fill((hueSlider.getValue()+120)%360, 100, 100);
80+
stg.fill((hue+120)%360, 100, 100);
7581
LinesDissolve();
76-
}
77-
else if (rotation<PI*9)
82+
} else if (rotation<PI*9)
7883
{
7984
LinesJoin();
8085
resetStage();
8186
rotate(PI/2);
82-
stg.fill((hueSlider.getValue()+120)%360, 100, 100);
87+
stg.fill((hue+120)%360, 100, 100);
8388
LinesJoin();
8489
}
8590

8691
if (aHueToggle.getState() && isKick() && isOnset() && isHat() && isSnare())
87-
hueSlider.setValue((hueSlider.getValue()+120)%360);
92+
hueSlider.setValue((hue+120)%360);
8893
}
8994

9095
void rotateRight()
9196
{
9297
rotate(rotation);
93-
stg.rect(-stg.getMaxRadius()/2, -weightSlider.getValue()/2, stg.getMaxRadius(), weightSlider.getValue());
94-
rotate(PI/2);
95-
stg.fill((hueSlider.getValue()+120)%360, 100, 100);
96-
stg.rect(-stg.getMaxRadius()/2, -weightSlider.getValue()/2, stg.getMaxRadius(), weightSlider.getValue());
98+
stg.line(-stg.getMaxRadius(), 0, stg.getMaxRadius(), 0);
99+
stg.stroke((hue+120)%360, 100, 100);
100+
stg.line(0, -stg.getMaxRadius(), 0, stg.getMaxRadius());
97101
}
98102

99103
void rotateLeft()
100104
{
101105
rotate(-rotation);
102-
stg.rect(-stg.getMaxRadius()/2, -weightSlider.getValue()/2, stg.getMaxRadius(), weightSlider.getValue());
103-
rotate(-PI/2);
104-
stg.fill((hueSlider.getValue()+120)%360, 100, 100);
105-
stg.rect(-stg.getMaxRadius()/2, -weightSlider.getValue()/2, stg.getMaxRadius(), weightSlider.getValue());
106+
stg.line(-stg.getMaxRadius(), 0, stg.getMaxRadius(), 0);
107+
stg.stroke((hue+120)%360, 100, 100);
108+
stg.line(0, -stg.getMaxRadius(), 0, stg.getMaxRadius());
109+
stg.stroke(hue, 100, 100);
106110
}
107111

108112
void rotateOpposite()
109113
{
110114
rotate(rotation);
111-
stg.rect(-stg.getMaxRadius()/2, -weightSlider.getValue()/2, stg.getMaxRadius(), weightSlider.getValue());
112-
rotate(-2*rotation);
113-
stg.fill((hueSlider.getValue()+120)%360, 100, 100);
114-
stg.rect(-stg.getMaxRadius()/2, -weightSlider.getValue()/2, stg.getMaxRadius(), weightSlider.getValue());
115+
stg.line(-stg.getMaxRadius(), 0, stg.getMaxRadius(), 0);
116+
stg.stroke((hue+120)%360, 100, 100);
117+
stg.line(0, -stg.getMaxRadius(), 0, stg.getMaxRadius());
118+
stg.stroke(hue, 100, 100);
115119
}
116120

117121
void LinesDissolve()
118122
{
119-
translate(0, (stg.height-weightSlider.getValue())*((rotation%PI)/PI)/2);
120-
stg.rect(-stg.getMaxRadius()/2, -weightSlider.getValue()/2, stg.getMaxRadius(), weightSlider.getValue());
121-
translate(0, -(stg.height-weightSlider.getValue())*(rotation%PI/PI));
122-
stg.rect(-stg.getMaxRadius()/2, -weightSlider.getValue()/2, stg.getMaxRadius(), weightSlider.getValue());
123+
translate(0, (stg.height-weight)*((rotation%PI)/PI)/2);
124+
stg.line(-stg.getMaxRadius(), 0, stg.getMaxRadius(), 0);
125+
translate(0, -(stg.height-weight)*(rotation%PI/PI));
126+
stg.line(-stg.getMaxRadius(), 0, stg.getMaxRadius(), 0);
123127
}
124128

125129
void LinesJoin()
126130
{
127-
translate(0, (stg.height-weightSlider.getValue())*(1-((rotation%PI)/PI))/2);
128-
stg.rect(-stg.getMaxRadius()/2, -weightSlider.getValue()/2, stg.getMaxRadius(), weightSlider.getValue());
129-
translate(0, -(stg.height-weightSlider.getValue())*(1-((rotation%PI)/PI)));
130-
stg.rect(-stg.getMaxRadius()/2, -weightSlider.getValue()/2, stg.getMaxRadius(), weightSlider.getValue());
131+
translate(0, (stg.height-weight)*(1-((rotation%PI)/PI))/2);
132+
stg.line(-stg.getMaxRadius(), 0, stg.getMaxRadius(), 0);
133+
translate(0, -(stg.height-weight)*(1-((rotation%PI)/PI)));
134+
stg.stroke((hue+120)%360, 100, 100);
135+
stg.line(-stg.getMaxRadius(), 0, stg.getMaxRadius(), 0);
131136
}
132137
}

MusicBeam/Stage.pde

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ public class Stage extends PApplet {
1212
}
1313

1414
public void settings() {
15-
fullScreen(P2D, 2);
15+
pixelDensity(displayDensity());
16+
if (ctrl.debugMode) {
17+
size(800, 600, P2D);
18+
} else {
19+
fullScreen(P2D, 2);
20+
}
1621
}
1722

1823
public void setup() {
19-
noStroke();
2024
colorMode(HSB, 360, 100, 100);
2125
try {
2226
blendMode(ADD);
@@ -28,6 +32,7 @@ public class Stage extends PApplet {
2832
public void draw() {
2933
ctrl.beatDetect();
3034
background(0);
35+
noStroke();
3136

3237
if (ctrl.debugMode) {
3338
fill(120, 100, 100);

0 commit comments

Comments
 (0)