/**
* Helmholtz Resonator v1.0.0 by cdmb architects (cc) 2008
* is a simple resonance calculator based on input frequencies, volumes,
* bottle neck radii and the speed of sound at sea level in SI units.
*
* Use the scroll bars to adjust the variables.
*
* Check the output dimensions to spec your resonator.
*
* For further information and questions about Helmholtz Resonator please
* take a look at the documentation, the examples, or the
* website at http://barlieb.com/index.php?option=com_content&task=view&id=75&Itemid=88
*
* key combinations:
* ALT+h hide and show controllers
* ALT+k bring the key menu to the front. use the arrow keys.
* Hold the ALT key and move controllers by dragging them.
*/
import controlP5.*;
ControlP5 controlP5;
float c = 340.29; // Constant Speed of Sound at Sea Level in SI Units m/s
float f = 32; // Wave Frequency
//float H = 400; // Neck Height in cm
float r = 10; // Neck Radius in cm
float x = 44.8; // Width in cm
float y = 44.8; // Breadth in cm
float z = 44.8; // Height in cm
void setup() { // Scrollbar Settings
size(500,500);
background(255);
frameRate(25);
controlP5 = new ControlP5(this);
controlP5.addSlider("Width cm",0,800,x,1,50,400,12).setId(1);
controlP5.addSlider("Breadth cm",0,800,y,1,65,400,12).setId(2);
controlP5.addSlider("Height cm",0,800,z,1,80,400,12).setId(3);
controlP5.addSlider("Neck Radius cm",0,200,r,1,95,400,12).setId(4);
controlP5.addSlider("Frequency Hz",0,400,f,1,110,400,12).setId(5);
controlP5.setColorBackground(255);
controlP5.setColorForeground(0);
controlP5.setColorActive(0xffff0000);
controlP5.setColorLabel(0);
}
void controlEvent(ControlEvent theEvent) { // Controls the Scrollbar and Variables
println("got a control event from controller with id "+theEvent.controller().id());
switch(theEvent.controller().id()) {
case(1):
x = (float)(theEvent.controller().value());
break;
case(2):
y = (float)(theEvent.controller().value());
break;
case(3):
z = (float)(theEvent.controller().value());
break;
case(4):
r = (float)(theEvent.controller().value());
break;
case(5):
f = (float)(theEvent.controller().value());
break;
}
}
void draw() {
background(255);
float V = x*y*z/1000; // Volume in Liters
float H = (PI*sq(r))/(V*(sq(2*PI*f/c))); // Neck Height Helmholtz Resonator
noFill();
stroke(0);
strokeWeight(1);
smooth();
rect(width/4-r,140,2*r,H*10); // Draws the Neck Section
rect(width/4-(x/2),140+H*10,x,z); // Draws the Body Section
ellipse(width*3/4,height/2,r*2,r*2); // Draws the Neck Plan
rect(width*3/4-(x/2),height/2-(y/2),x,y); // Draws the Body Plan
PFont font; // Prints all the Info to the window.
font=loadFont("CourierNewPSMT-12.vlw");
textFont(font);
fill(0);
text("Helmholtz Resonator v1.0.0 ",0,12);
text("cdmb architects (cc) 2008 ",0,24);
text("Neck",width/4+r+3,140+(H*10)-3); // Neck Text Section
text("Neck",width*3/4-13,height/2-r-3); // Neck Text Plan
text("Body",width/4+x/2+3,(140+H*10)+z); // Body Text Section
text("Body",width*3/4+(x/2)+3,height/2+(y/2)); // Body Text Plan
text("Section",width/4-25,(140+H*10)+z+15); // Text Section
text("Plan",width*3/4-13,height/2+(y/2)+15); // Text Section
text("Width = " + x + " cm",300,385);
text("Breadth = " + y + " cm",300,400);
text("Height = " + z + " cm",300,415);
text("Neck Diameter = " + r*2 + " cm",300,430);
text("Neck Height = " + H*10 + " cm",300,445);
text("Volume = " + V + " Liters",300,460);
text("Frequency = " + f + " Hz",300,475);
}