SHARE
TWEET

Untitled

a guest Jan 15th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. var threshold = 30;
  3. var accChangeX = 0;
  4. var accChangeY = 0;
  5. var accChangeT = 0;
  6. var max_shake = 0;
  7.  
  8. var notes =
  9. {
  10.     C:20,
  11.     D:40,
  12.     E:60,
  13.     F:80,
  14.     G:100,
  15.     A:120,
  16.     B:140
  17. };
  18. function setup() {
  19.   createCanvas(displayWidth, displayHeight);
  20.   frameRate(2);
  21. }
  22.  
  23. function draw() {
  24.   background(255);
  25.  
  26.   checkForShake();
  27.  }
  28.  
  29. function checkForShake() {
  30.   // Calculate total change in accelerationX and accelerationY
  31.   accChangeX = abs(accelerationX - pAccelerationX);
  32.   accChangeY = abs(accelerationY - pAccelerationY);
  33.   accChangeT = accChangeX + accChangeY;
  34.   // If shake
  35.   if(accChangeT > max_shake){
  36.       max_shake = accChangeT;
  37.   }
  38.   textSize(32);
  39.   fill(0);
  40.   stroke(0);
  41. //   text(max_shake,displayWidth/2,200);
  42. //   text(accChangeT,displayWidth/2,displayHeight/2);
  43.   if(accChangeT < notes.C){
  44.     text("C",displayWidth/2,displayHeight/2);
  45.     music("F4");
  46.     }
  47.     else if(accChangeT < notes.D){
  48.         text("D",displayWidth/2,displayHeight/2);
  49.         music("G4");
  50.     }
  51. else if(accChangeT < notes.E){
  52.     text("E",displayWidth/2,displayHeight/2);
  53.     music("G4#");
  54.    
  55. }
  56. else if(accChangeT < notes.F){
  57.     text("F",displayWidth/2,displayHeight/2);
  58.     music("A5#");
  59.    
  60. }
  61. else if(accChangeT < notes.G){
  62.     text("G",displayWidth/2,displayHeight/2);
  63.     music("C5");
  64.    
  65. }
  66. else if(accChangeT < notes.A){
  67.     text("A",displayWidth/2,displayHeight/2);
  68.     music("C5#");
  69.    
  70. }
  71. else if(accChangeT < notes.B){
  72.     text("B",displayWidth/2,displayHeight/2);
  73.     music("D5#");
  74.  
  75.   }
  76. //   if (accChangeT >= threshold) {
  77.  
  78. //   }
  79. //   // If not shake
  80. //   else {
  81. //  // do something
  82. //   }
  83. }
  84.  
  85.  
  86.  
  87. function music(note){
  88.     var synth = new Tone.Synth().toMaster();
  89.     synth.triggerAttackRelease(note, "8n");
  90. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top