PImageRead through Chapter 6 of Getting Started with Processing and work all the code examples. This chapter includes an introduction to PImage and PFont. You can get a basic idea of how to use both from the book, but you'll learn a lot more by delving into the pages for both in the Processing Reference.
For example, a quick read of PImage shows the functions I used in my video above:
Thing to Try - Create a program that applies some filters or blends with images dynamically. That is to say the user controls it in some way. Mouse motion or dragging would work well here.
Generate SoundWe can make tones in processing using the Minim library. The easiest way to experiment with it is to go to File->Examples->Libraries->Minim. For this Lesson you should open up SineWaveSignal.
Run the program. As you move your mouse around in the window you should hear changes in the sound. You'll notice that both the volume and the pitch change.
Lets break down what we see:
The opening block imports the piece of the Minim library that we need, just like we had to import the Arduino library.
These names could be anything. For example you could just as easily have: SineWave bob;
![]() Our setup procedure has some new stuff. The comments do a pretty good job of explaining, I'll just expand a little. Portamento is an actual term used in music and is very important for electronic synthesizers. It deals with how quickly the note will change. Set it to 20 and then 2000, or try sine.noPortamento(). You should hear clear differences.
If you're going to want to play more than one note at a time you'll need to create more instances of SineWave at the top and then reproduce some of the setup lines, for example:
The code above will set us up to play two notes at the same time. Think chords here. If you want three or four notes you'll need three or four instances of SineWave. The draw procedure of this sketch just shows us the wave form of the sound we're hearing. We'll go into how it works in another lesson.
In the mouseMoved() procedure you see where the frequency changes happen. The table below shows some basic commands.
Other fun stuff to try. This sketch produces a sine wave, but can als produce a square wave or sawtooth wave. Try each and see how the sound differs. To do this you need to change the SineWave instance to SquareWave or SawWave. You need to do this both at the top and in the setup procedure.
Working with Audio FilesLoadFileYou can have processing grab an audio file and play it. Stick with mp3 or wav files. Lets play with the LoadFile example sketch (File->Examples->Libraries->Minim->LoadFile).Time to Break it Down:
The first bit imports the Minim Library, Starts Minim, and create an instance of AudioPlayer called player. Again, "player" is just a name, it could be anything.
The comments do a good job of explaining. One thing to know. Processing will look for the audio file in the sketch's "data" folder. The important piece here is player.play(); This is the command that plays the file. If you take it out of the setup() and do something like:
Then the song will wait till you press a key. If you're working on a touchscreen interface you could change this to void mousePressed() instead.
Player Commands (remember, "player" is just an instance of AudioPlayer you could use any word you want instead of "player"):
To learn more check out the Minim Code Library for a more thorough explanation of Playable procedures.
LoadSampleThis works just like LoadFile, but is used for short audio samples you will play over and over again. Grab it from File-Examples-Libraries-Minim and take a look. It should look very familiar. In fact, I'm not going to explain it all. You should be able to understand it all without my help. The only new bit is name.trigger() which basically just plays the file.
The main difference between LoadSample and LoadFile is when the audio file is copied into the computer's RAM. If you have short audio files you should use LoadSample. It will take slightly longer for the program to start when you run it, but it will run better.
You have all the same control options in AudioSample as you did with AudioPlayer. Again, your audio files need to be in the data folder so Processing can find them. Things to try:
|
Intro to Processing >