Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. /*******************************************
  2. * *
  3. * Theremin (Audio Generator) *
  4. * *
  5. * UTeach CSP *
  6. * Bradley Beth *
  7. * rev. 20160920 *
  8. * *
  9. *******************************************/
  10.  
  11. import processing.sound.*;
  12.  
  13. ArrayList<SinOsc> waves; // ArrayList of sines
  14. int numWaves = 0; // Number of waves to play
  15.  
  16. void setup() {
  17. size(600, 600);
  18. background(255);
  19. waves = new ArrayList<SinOsc>();
  20. mouseClicked();
  21. }
  22.  
  23. void draw() {
  24. drawLegend();
  25. stroke(0);
  26. fill(0);
  27. ellipse(mouseX,mouseY,10,10);
  28. waves.get(waves.size()-1).freq(map(mouseX,0,width,32.70,4186.01));
  29. waves.get(waves.size()-1).amp(1.0-map(mouseY,0,height,0,1));
  30. }
  31.  
  32. void mouseClicked() {
  33. waves.add(new SinOsc(this));
  34. waves.get(waves.size()-1).play();
  35. }
  36.  
  37. void drawLegend() {
  38. background(255);
  39. strokeWeight(2);
  40. stroke(#BF5700);
  41. fill(#BF5700);
  42. textSize(16);
  43. float pExtension = map(mouseX,0,width,0,width/4);
  44. line(width/2-40,height/2+30,width/2-30+pExtension,height/2+30);
  45. triangle(width/2+pExtension-30,height/2+35,
  46. width/2+pExtension-30,height/2+25,
  47. width/2+pExtension-15,height/2+30);
  48. text("pitch",width/2+pExtension,height/2+35);
  49. float vExtension = map(mouseY,height,0,0,height/4);
  50. line(width/2-40,height/2+30,width/2-40,height/2+20-vExtension);
  51. triangle(width/2-35,height/2+20-vExtension,
  52. width/2-45,height/2+20-vExtension,
  53. width/2-40,height/2+5-vExtension);
  54. text("volume",width/2-65,height/2-vExtension);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement