/** * WaveMaker v1.0.1 by cdmb architects (cc) 2008
* is a simple wave calculator based on input frequencies and
* the speed of sound at sea level in SI units.
*
* Use the scroll bars to adjust the variables.
*
* Check the wavelength output.
*
* For further information and questions about WaveMaker 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 amp = 100.0; //Initial Variables float f = 31.5; //Amplitude & Frequency void setup() { // Scrollbar Settings size(480,480); background(255); frameRate(25); controlP5 = new ControlP5(this); controlP5.addSlider("frequency",0,800,f,1,50,400,12).setId(1); controlP5.addSlider("amplitude",0,100,amp,1,65,400,12).setId(2); 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): f = (float)(theEvent.controller().value()); break; case(2): amp = (float)(theEvent.controller().value()); break; } } void draw() { background(255); smooth(); float c = 340.29; //Speed of Sound float w = c/f; //Wavelength float angle = 0.0; //Initial Angle for (int x = 0; x <= width; x+= 1){ //For loop float y = (height/2)+sin(angle/w)*amp; //Sine function stroke(240); point (x,(height/2)+amp); //Lowerline point (x,(height/2)-amp); //Upperline line(120,(height/2)+amp,120,(height/2)-amp); line(120*2,(height/2)+amp,120*2,(height/2)-amp); line(120*3,(height/2)+amp,120*3,(height/2)-amp); line(120*4,(height/2)+amp,120*4,(height/2)-amp); stroke(255,0,0); point (x,height/2); //Centerline point (x,y); //Plots the Sine Curve line(w*120,(height/2)+amp,w*120,(height/2)-amp); angle += PI/60; //Angular Frequency (Pi/(Number of Seconds/Rotation)) } PFont font; // Prints all the Info to the window. font=loadFont("CourierNewPSMT-12.vlw"); textFont(font); fill(0); text("WaveMaker v1.0.1 ",0,12); text("cdmb architects (cc) 2008 ",0,24); text("Speed of Sound at Sea Level & 20°C = " + 340.29 + " m/s",0,90); fill(255,0,0); text("0",7,(height/2)-5); text("1",124,(height/2)-5); text("2",244,(height/2)-5); text("3 m",364,(height/2)-5); text(amp,0,(height/2)-amp-5); text(-amp,0,(height/2)+amp+15); text("Wavelength = " + w + " m",300,460); }