Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. import processing.sound.*;
  2.  
  3. float bpm = 0;
  4. int count = 0;
  5. int fullCount = 8;
  6. int bar = 3;
  7. float timeStart = 0;
  8. float lastTime = 0;
  9. float flash;
  10. float reset = 2000;
  11. SoundFile beep;
  12.  
  13. void setup() {
  14.   size(800, 600);
  15.   noStroke();
  16.   beep = new SoundFile(this, "beep.wav");
  17.   flash = 0;
  18. }
  19.  
  20. void draw() {
  21.   background(#3B3B3B);
  22.   fill(#EA4242);
  23.   textSize(height / 4);
  24.   textAlign(CENTER);
  25.   text(floor(bpm), width / 2, height / 2);
  26.   textSize(height / 12);
  27.   text(bpm, width / 2, height / 2 + height / 12);
  28.  
  29.   for (int i = 0; i < count; i++) {
  30.     rect(width / fullCount * i, height - 32, width / fullCount, 32);
  31.   }
  32.  
  33.   fill(255, 255, 255, flash);
  34.   rect(0, 0, width, height);
  35.  
  36.   flash = flash + (0 - flash) * 0.1;
  37. }
  38.  
  39. void mousePressed() {
  40.   tap();
  41.   flash = 100;
  42. }
  43.  
  44. void keyPressed() {
  45.   tap();
  46.   flash = 100;
  47. }
  48.  
  49. void tap() {
  50.    float time = millis();
  51.    
  52.    if (time - lastTime > reset) {
  53.       count = 0;
  54.       bar = 3;
  55.       bpm = 0;
  56.    }
  57.    
  58.    if (count == 0) {
  59.      timeStart = time;
  60.      count++;
  61.    } else {
  62.      bpm = 60000 * count / (time - timeStart);
  63.      count++;
  64.    }
  65.    lastTime = time;
  66.    //SOUND
  67.    bar++;
  68.    if (bar >= 4) {
  69.      bar = 0;
  70.      beep.rate(1.3);
  71.    } else {
  72.      beep.rate(1);
  73.    }
  74.    
  75.    beep.play();
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement