Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ofApp.h"
- #define RAIN_COUNT 50
- void ofApp::setup(){
- grabber.setup(320, 240);
- image.allocate(320, 240, OF_IMAGE_COLOR);
- gui.setup();
- gui.add(thresh.setup("Threshold", 80, 0, 255));
- gui.add(showVideo.setup("Show Video"));
- ofSetFullscreen(true);
- for(int i = 0; i < RAIN_COUNT; i++){
- ofPoint point = ofPoint(ofRandom(ofGetWidth()),
- ofRandom(ofGetHeight()) );
- rain.push_back(point);
- velocity.push_back(0.1);
- text.push_back(ofRandom('A', 'Z'));
- }
- }
- void ofApp::update(){
- // image
- grabber.update();
- unsigned char *imgPixels = image.getPixels().getData();
- unsigned char *vidPixels = grabber.getPixels().getData();
- for(int i = 0; i < 320*240; i++){
- unsigned char gray = (vidPixels[i*3+0] + vidPixels[i*3+1] + vidPixels[i*3+2])/3.0;
- if(gray < thresh){
- imgPixels[i*3+0] = imgPixels[i*3+1] = imgPixels[i*3+2] = 0;
- }else{
- imgPixels[i*3+0] = imgPixels[i*3+1] = imgPixels[i*3+2] = 255;
- }
- }
- image.update();
- // rain
- for(int i = 0; i < RAIN_COUNT; i++){
- int smW = rain[i].x / ofGetWidth() * 320;
- int smH = rain[i].y / ofGetHeight() * 240;
- int p = (smW + smH*320)*3;
- if(imgPixels[p] > thresh){
- rain[i].y += velocity[i];
- velocity[i] += 0.1;
- }
- else{
- rain[i].x = ofRandom(ofGetWidth());
- rain[i].y = 0;
- velocity[i] = 0;
- text[i] = ofRandom('A', 'Z');
- }
- }
- }
- void ofApp::draw(){
- ofBackground(0);
- ofSetColor(255, 255);
- if(showVideo){
- grabber.draw(0, 0, ofGetWidth(), ofGetHeight());
- } else{
- image.draw(0, 0, ofGetWidth(), ofGetHeight());
- }
- // ofSetColor(50, 50, 255, 255);
- for(int i = 0; i < RAIN_COUNT; i++){
- // ofDrawCircle(rain[i], 5);
- ofDrawBitmapString(text[i], rain[i]);
- }
- if(showGui){
- gui.draw();
- }
- }
- //--------------------------------------------------------------
- void ofApp::keyPressed(int key){
- if(key == ' '){
- showGui = !showGui;
- }
- }
- //--------------------------------------------------------------
- void ofApp::keyReleased(int key){
- }
- //--------------------------------------------------------------
- void ofApp::mouseMoved(int x, int y ){
- }
- //--------------------------------------------------------------
- void ofApp::mouseDragged(int x, int y, int button){
- }
- //--------------------------------------------------------------
- void ofApp::mousePressed(int x, int y, int button){
- }
- //--------------------------------------------------------------
- void ofApp::mouseReleased(int x, int y, int button){
- }
- //--------------------------------------------------------------
- void ofApp::mouseEntered(int x, int y){
- }
- //--------------------------------------------------------------
- void ofApp::mouseExited(int x, int y){
- }
- //--------------------------------------------------------------
- void ofApp::windowResized(int w, int h){
- }
- //--------------------------------------------------------------
- void ofApp::gotMessage(ofMessage msg){
- }
- //--------------------------------------------------------------
- void ofApp::dragEvent(ofDragInfo dragInfo){
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement