n00b request > how to trigger state with tap (color /audio etc)

edited October 2016 in p5.js

Hi Everyone, I'm trying to a sketch where, when I tap a screen (or key), there is some one shot sound that plays, and there is some brief visual. The visual can be timed, and doesn't have to actually read the audio.

I've been looking at examples, and watching tutorials, but I'm still kinda slow with this. If anyone has any suggestions, I'd love to hear it.

aS p.s. I know this is rookie stuff, so my apologies ;)

Tagged:

Answers

  • edited October 2016 Answer ✓

    Howdy @ArtStudent

    You want to look at the Events section in the p5js reference: https://p5js.org/reference/#group-Events

    Here there are loads of ways of triggering things off on user input. You might want to do something like this, which will generate random colours on key press:

    var value = 0;
    function draw() {
      if (keyIsPressed === true) {
        fill(random(255),random(255),random(255));
      } else {
        fill(0);
      }
      rect(25, 25, 50, 50);
    }
    

    To play sounds, you'll want the p5js sound library: https://p5js.org/reference/#/libraries/p5.sound

    With both these things you should be able to easily achieve what you want to.

    Thanks

    G

  • @georgehenryrowe Thank you very, very much for the quick reply! I'm in class today and your link helps me out quite a bit!

Sign In or Register to comment.