Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import processing.sound.*;
- float bpm = 0;
- int count = 0;
- int fullCount = 8;
- int bar = 3;
- float timeStart = 0;
- float lastTime = 0;
- float flash;
- float reset = 2000;
- SoundFile beep;
- void setup() {
- size(800, 600);
- noStroke();
- beep = new SoundFile(this, "beep.wav");
- flash = 0;
- }
- void draw() {
- background(#3B3B3B);
- fill(#EA4242);
- textSize(height / 4);
- textAlign(CENTER);
- text(floor(bpm), width / 2, height / 2);
- textSize(height / 12);
- text(bpm, width / 2, height / 2 + height / 12);
- for (int i = 0; i < count; i++) {
- rect(width / fullCount * i, height - 32, width / fullCount, 32);
- }
- fill(255, 255, 255, flash);
- rect(0, 0, width, height);
- flash = flash + (0 - flash) * 0.1;
- }
- void mousePressed() {
- tap();
- flash = 100;
- }
- void keyPressed() {
- tap();
- flash = 100;
- }
- void tap() {
- float time = millis();
- if (time - lastTime > reset) {
- count = 0;
- bar = 3;
- bpm = 0;
- }
- if (count == 0) {
- timeStart = time;
- count++;
- } else {
- bpm = 60000 * count / (time - timeStart);
- count++;
- }
- lastTime = time;
- //SOUND
- bar++;
- if (bar >= 4) {
- bar = 0;
- beep.rate(1.3);
- } else {
- beep.rate(1);
- }
- beep.play();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement