Skip to content

Commit

Permalink
Add two new effects: Vortex & Raindrops (#66)
Browse files Browse the repository at this point in the history

Co-authored-by: Johannes Maron <[email protected]>
  • Loading branch information
tgfmfc and codingjoe authored Dec 27, 2022
1 parent a18667f commit 98a134d
Show file tree
Hide file tree
Showing 4 changed files with 246 additions and 6 deletions.
8 changes: 5 additions & 3 deletions MusicBeam/MusicBeam.pde
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import controlP5.*;
import ddf.minim.*;
import ddf.minim.analysis.*;

String version = "2.6.1";
String version = "2.7.0";

public Boolean debugMode = false;

Expand Down Expand Up @@ -43,7 +43,7 @@ float randomTimer = 0;

int randomEffect = 0;
int width = 775;
int height = 570;
int height = 670;

float maxLevel = 0;
float goalMaxLevel=0;
Expand Down Expand Up @@ -243,7 +243,7 @@ void initEffects()
{
initRandomControls();

effectArray = new Effect[9];
effectArray = new Effect[11];
effectArray[0] = new Blackout_Effect(this, 0);
effectArray[1] = new Strobe_Effect(this, 1);
effectArray[2] = new Scanner_Effect(this, 2);
Expand All @@ -253,6 +253,8 @@ void initEffects()
effectArray[6] = new Snowstorm_Effect(this, 6);
effectArray[7] = new LaserBurst_Effect(this, 7);
effectArray[8] = new Polygon_Effect(this, 8);
effectArray[9] = new Vortex_Effect(this, 9);
effectArray[10] = new Raindrops_Effect(this, 10);

activeSetting.activate(0);

Expand Down
106 changes: 106 additions & 0 deletions MusicBeam/Raindrops_Effect.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
class Raindrops_Effect extends Effect //<>//
{
String getName()
{
return "Raindrops";
}

char triggeredByKey() {
return 'a';
}

Toggle interactionToggle, directionToggle, bwToggle;
Slider fadeSpeedSlider, densitySlider;
int tmpCounter, maxSize;
int halfWidth = stg.width/2;
int halfHeight = stg.height/2;
int dirUP=1;
int dirDOWN=-1;
ArrayList<Drop> drops = new ArrayList<Drop>();

Raindrops_Effect(MusicBeam controller, int y)
{
super(controller, y);
maxSize = min(stg.width, stg.height);
tmpCounter = 0;
stg.noStroke();
stg.ellipseMode(CENTER);
fadeSpeedSlider = cp5.addSlider("speed"+getName()).setPosition(105, 5).setSize(290, 45).setRange(1, 10).setGroup(controlGroup);
fadeSpeedSlider.getCaptionLabel().set("fadespeed").align(ControlP5.RIGHT, ControlP5.CENTER);
fadeSpeedSlider.setValue(5);
directionToggle = ctrl.cp5.addToggle("direction"+getName()).setPosition(0, 5).setSize(100, 45).setGroup(controlGroup);
directionToggle.getCaptionLabel().set("raindrops").align(ControlP5.CENTER, ControlP5.CENTER);
directionToggle.setState(false);
interactionToggle = ctrl.cp5.addToggle("interaction"+getName()).setPosition(0, 55).setSize(100, 45).setGroup(controlGroup);
interactionToggle.getCaptionLabel().set("music").align(ControlP5.CENTER, ControlP5.CENTER);
interactionToggle.setState(true);
densitySlider = cp5.addSlider("density"+getName()).setPosition(105, 55).setSize(290, 45).setRange(1, 10).setGroup(controlGroup);
densitySlider.getCaptionLabel().set("density").align(ControlP5.RIGHT, ControlP5.CENTER);
densitySlider.setValue(5);
bwToggle = ctrl.cp5.addToggle("bw"+getName()).setPosition(0, 105).setSize(45, 45).setGroup(controlGroup);
bwToggle.getCaptionLabel().set("BW").align(ControlP5.CENTER, ControlP5.CENTER);
bwToggle.setState(true);
}

void draw() {
directionToggle.getCaptionLabel().set(directionToggle.getState() ? "Sunrays" : "Raindrops");
stg.fill(100, 0, 100);
if (!interactionToggle.getState()) {
interactionToggle.getCaptionLabel().set("auto");
if (tmpCounter==0) {
addDrop();
}
tmpCounter += 1;
if (tmpCounter >= 10 - densitySlider.getValue()) {
tmpCounter = 0;
}
} else {
interactionToggle.getCaptionLabel().set("music");
if (isHat()) addDrop();
if (isSnare()) addDrop();
if (isKick()) addDrop();
}
for (Drop dr : drops) {
dr.draw();
}
for (int i=drops.size()-1; i>=0; i--) {
Drop dr = drops.get(i);
if (dr.size <= 0) {
drops.remove(i);
}
}
}

class Drop {
int posX, posY, direction, hue;
float size, targetSize;

Drop(int dir) {
targetSize = random(maxSize / 100, maxSize / 10);
posX = int(random(halfWidth*-1, halfWidth));
posY = int(random(halfHeight*-1, halfHeight));
hue = int(random(0, 360));
direction = dir;
size = (dir == dirUP) ? 1: targetSize;
targetSize = (dir == dirUP) ? targetSize : 1;

bwToggle.getState();

}

void draw() {
size += fadeSpeedSlider.getValue() * direction / sqrt(size);
if (direction == dirUP && size >= targetSize) {
direction = dirDOWN;
}
stg.fill(hue % 360, bwToggle.getState() ? 0 : 100, 100);
if (size > 0) {
stg.ellipse(posX, posY, size, size);
}
}
}

void addDrop() {
drops.add(new Drop(directionToggle.getState() ? dirUP : dirDOWN));
}
}
6 changes: 3 additions & 3 deletions MusicBeam/Settings.pde
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ void initSettings()
saveSliderLabelAlign();
cp5.getProperties().setFormat(ControlP5.SERIALIZED);

loadDefaultSettingsButton = cp5.addButton("loadDefaultSettings").setSize(129, 45).setPosition(10, 515);
loadDefaultSettingsButton = cp5.addButton("loadDefaultSettings").setPosition(10, height-55).setSize(129, 45);
loadDefaultSettingsButton.getCaptionLabel().set("Default Settings").align(ControlP5.CENTER, ControlP5.CENTER);

loadSettingsButton = cp5.addButton("loadSettings").setSize(129, 45).setPosition(143, 515);
loadSettingsButton = cp5.addButton("loadSettings").setPosition(143, height-55).setSize(129, 45);
loadSettingsButton.getCaptionLabel().set("Load Settings").align(ControlP5.CENTER, ControlP5.CENTER);

saveSettingsButton = cp5.addButton("saveSettings").setSize(129, 45).setPosition(276, 515);
saveSettingsButton = cp5.addButton("saveSettings").setPosition(276, height-55).setSize(129, 45);
saveSettingsButton.getCaptionLabel().set("Save Settings").align(ControlP5.CENTER, ControlP5.CENTER);
}

Expand Down
132 changes: 132 additions & 0 deletions MusicBeam/Vortex_Effect.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
class Vortex_Effect extends Effect
{
String getName()
{
return "Spinner";
}

char triggeredByKey() {
return '9';
}
int currentPulseValue, maxSize;
float offset, gap;
boolean swap;
Toggle bwToggle, dualColourToggle, swapColourToggle, pulseToggle;
Slider weightSlider, sizeSlider, gapSlider, hueSlider, hue2Slider, speedSlider;

Vortex_Effect(MusicBeam controller, int y)
{
super(controller, y);
swap=false;
int maxWeight =20;
maxSize = min(stg.width, stg.height) - maxWeight;
currentPulseValue=0;
weightSlider = cp5.addSlider("weight"+getName()).setPosition(0, 5).setSize(395, 45).setRange(1, 100).setGroup(controlGroup);
weightSlider.getCaptionLabel().set("Weight").align(ControlP5.RIGHT, ControlP5.CENTER);
weightSlider.setValue(20);

sizeSlider = cp5.addSlider("size"+getName()).setPosition(0, 55).setSize(395, 45).setRange(200, maxSize).setGroup(controlGroup);
sizeSlider.getCaptionLabel().set("Size").align(ControlP5.RIGHT, ControlP5.CENTER);
sizeSlider.setValue(maxSize/4*3);

speedSlider = cp5.addSlider("speed"+getName()).setPosition(0, 105).setSize(395, 45).setRange(-45, 45).setGroup(controlGroup);
speedSlider.getCaptionLabel().set("Speed").align(ControlP5.RIGHT, ControlP5.CENTER);
speedSlider.setValue(7.5);

gapSlider = cp5.addSlider("gap"+getName()).setPosition(0, 155).setSize(395, 45).setRange(0, 180).setGroup(controlGroup);
gapSlider.getCaptionLabel().set("gap").align(ControlP5.RIGHT, ControlP5.CENTER);
gapSlider.setValue(90);

hueSlider = cp5.addSlider("hue"+getName()).setPosition(0, 205).setSize(395, 45).setRange(0, 360).setGroup(controlGroup);
hueSlider.getCaptionLabel().set("hue").align(ControlP5.RIGHT, ControlP5.CENTER);
hueSlider.setValue(50);

hue2Slider = cp5.addSlider("hue2"+getName()).setPosition(0, 255).setSize(395, 45).setRange(0, 360).setGroup(controlGroup);
hue2Slider.getCaptionLabel().set("hue2").align(ControlP5.RIGHT, ControlP5.CENTER);
hue2Slider.setValue(300);

bwToggle = ctrl.cp5.addToggle("bw"+getName()).setPosition(0, 305).setSize(45, 45).setGroup(controlGroup);
bwToggle.getCaptionLabel().set("BW").align(ControlP5.CENTER, ControlP5.CENTER);
bwToggle.setState(false);

dualColourToggle = ctrl.cp5.addToggle("link"+getName()).setPosition(50, 305).setSize(110, 45).setGroup(controlGroup);
dualColourToggle.getCaptionLabel().set("Dual Colours").align(ControlP5.CENTER, ControlP5.CENTER);
dualColourToggle.setState(true);

swapColourToggle = ctrl.cp5.addToggle("swapclolour"+getName()).setPosition(165, 305).setSize(110, 45).setGroup(controlGroup);
swapColourToggle.getCaptionLabel().set("Swap Colours").align(ControlP5.CENTER, ControlP5.CENTER);
swapColourToggle.setState(false);

pulseToggle = ctrl.cp5.addToggle("pulse"+getName()).setPosition(280, 305).setSize(115, 45).setGroup(controlGroup);
pulseToggle.getCaptionLabel().set("pulse").align(ControlP5.CENTER, ControlP5.CENTER);
pulseToggle.setState(false);
}

int weight, circleSize, hue, hue2;

void draw() {
stg.noFill();
stg.strokeWeight(weight);
offset += speedSlider.getValue();
offset = getDegree(offset);
gap = 180 - gapSlider.getValue();
weight = int(weightSlider.getValue());
circleSize = int(sizeSlider.getValue());
hue = int(hueSlider.getValue());
hue2 = int(dualColourToggle.getState()?hue2Slider.getValue():hue);

if (isKick()) {
currentPulseValue = maxSize - circleSize;
}
if (currentPulseValue > 0) {
currentPulseValue -= sqrt(currentPulseValue);
}

if (pulseToggle.getState()) {
circleSize += currentPulseValue;
}


if (dualColourToggle.getState() && swapColourToggle.getState()) {
if (isHat()) {
swap=!swap;
}
if (swap) {
int tmp=hue;
hue=hue2;
hue2=tmp;
}
}

stg.stroke(hue%360, bwToggle.getState()?0:100, 100);
stg.arc(0, 0, circleSize, circleSize, radians(offset), radians(getDegree(offset+gap)));
stg.stroke(hue2%360, bwToggle.getState()?0:100, 100);
stg.arc(0, 0, circleSize, circleSize, radians(getDegree(offset + 180)), radians(getDegree(offset + gap + 180)));
}

void keyPressed(char key, int keyCode)
{
super.keyPressed(key, keyCode);
if (key == CODED) {
if (keyCode == LEFT)
sizeSlider.setValue(sizeSlider.getValue() - maxSize/20);
else if (keyCode == RIGHT)
sizeSlider.setValue(sizeSlider.getValue() + maxSize/20);
else if (keyCode == DOWN)
speedSlider.setValue(speedSlider.getValue()-1);
else if (keyCode == UP)
speedSlider.setValue(speedSlider.getValue()+1);
else if (keyCode == CONTROL)
bwToggle.setValue(!bwToggle.getState());
}
}
float getDegree(float in) {
if (in<0) {
return in+360;
}
if (offset>=360) {
return in-360;
}
return in;
}
}

0 comments on commit 98a134d

Please sign in to comment.