Computer Science I Libraries. Sound. Saving frames as images. Classwork/Homework: Make sketch using sound. Add saving frames.
Libraries are collections of code. Why doesn't the Processing Development Environment (or IntelliJ, which comes next) provide everything? – Too big – New ones being developed all the time. So, the mechanism for including new stuff is the same as mechanism for including more of built-in stuff import libraryname;
Steps to using sound Make or find a sound file(s) you want. Download In Processing, use Sketch/Add file… find on your computer In Processing, use Sketch/Inport Library…/Add Library… find on list. If it isn't there, find it online and look up how to add!
Very simple example // using sound import processing.sound.*; SoundFile shutter; void setup() { size(600,400); shutter = new SoundFile(this,"camera-shutter-click-01.wav"); frameRate(.25); //notice slowing down of frames } void draw() { shutter.play(); } Notice this
About the reference this Remember: our Processing code actually is part of a larger Java program. Using sound (and video and other things) requires some attention to the rest of the coding. The this refers to the object, called a PApplet, that holds our code.
Saving frames Making the current frame into an image file and saving that image file to the Sketch folder. The function is saveFrame(your_choice_of_name); Can designate a folder AND series of numbers. I chose to add code to my path making Sketch and take the snapshot when user clicks on key.
Within a program void keyPressed(){ saveFrame("snaps/worms####.png"); }
When to trigger taking snapshot? Whenever you want! Caution: if you do it in draw, and have a high frameRate, that will be a lot of pictures. Possibilities: keyPressed, mouse action, condition determined by coding, etc.
To retrieve Processing/Sketch/Show Sketch folder
Family mark for my father
Classwork Incorporate sound – Find sound file(s) – Write your own program using sound. Add to data file Import library – Use headset to check? – Obvious choice is some kind of bump when bouncing thing hits the wall Incorporate saving image of frames – Obvious choice: make a sound like a camera shutter when taking a snapshot