If you’re working on the TextRain assignment, here is some advice which may help.
The BrightnessThresholding example in Processing (which comes with the download) has some good components to get started with. Specifically:
- It shows how to create a connection to the live camera, by importing the video library, and then creating and starting a Capture object;
- It shows how to access the camera’s array of pixels, using myCapture.read(), myCapture.loadPixels(), and the myCapture.pixels[ ] array;
- It shows how to obtain the brightness of a given pixel, using brightness().
The similarities end there, however. For example,
- The BrightnessThresholding example compares the brightness of every pixel with a threshold. TextRain doesn’t need to test the brightness of all pixels: in only needs to test the brightness of the one pixel under each letter. Thus you won’t need updatePixels().
- TextRain doesn’t set any pixels in a new image; it only moves a letter up or down depending on the brightness of the underlying pixel.
There are two technical concepts that would be very helpful in implementing TextRain:
- A little object-oriented programming isn’t absolutely essential, but it would really help a lot. You could make each letter its own object, that stores its position and character. These letter objects should provide methods for testing pixel brightness and drawing itself. If you don’t understand this, then you should consult one of the Processing books where they discuss Objects.
- It will help to know how to calculate the index number (in the camera’s array of pixels) of the pixel under a given letter located at (x,y). The general formula for this is: index = y*videoWidth + x. If you don’t understand this, then you should consult one of the Processing books where they discuss array index numbering in image pixel buffers.