I am wondering how to change the audio amp and the bars to be inside of the musical note image ?

Hello, I was wondering how to change the audio amp and the bars to be inside of the musical note image I added in the code. I am a beginner just need a little help for the solution. Also, I added a clear feature, but when I click "c" to clear it doesn't clear it and you have to take multiple button pressing c to see what I mean.

PImage img;
import processing.sound.*;
Amplitude amp;
AudioIn in;
float volume = 0;
int x = 0;

void setup() {
  amp = new Amplitude(this);
  in = new AudioIn(this, 0);
  in.start();
  amp.input(in);
  frameRate(50);
  background(0, 255, 255);
  size(600, 800);
  img= loadImage("Musical Note.png");
  PFont font;
  font = loadFont("UrbanClass-10.vlw");
  textFont(font, 12);  
  text("Use microphone to change color of note and click to draw.", 10, 20);
}

void draw() {
  image(img, 25, 80);
  //Draw normal
  if (mousePressed && (mouseButton == LEFT)) {
    ellipse(mouseX, mouseY, 40, 40);
    fill(random(255), random(255), random(255));
    noStroke();
    //draw coin like pattern
  } else if (mousePressed && (mouseButton == RIGHT)) {
    ellipse(mouseX, mouseY, 40, 40);
    fill(0, 255, 255);
    noStroke();
  }
  volume = amp.analyze();  // get volume level
  println(volume);
  float graph = map(volume, 0, 1, height, 0);  //Scale 0-1 volume to height of canvas
  fill(random(255), random(255), random(255));
  rect(x, graph, 5, height);
  x += 5;   // increase x to draw rectangles of graph next to each other
  if (x > width) {
    x = 0;
    if (keyPressed == true) {
      if (key == 'c')
        background(0, 255, 255);
      text("Use microphone to change color of note and click to draw.", 10, 20);
    }
  }
}
Tagged:

Answers

Sign In or Register to comment.