Advertisement
Guest User

Text Snow, Open Frameworks

a guest
Oct 14th, 2016
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.03 KB | None | 0 0
  1. #include "ofApp.h"
  2.  
  3. #define RAIN_COUNT 50
  4.  
  5. void ofApp::setup(){
  6.     grabber.setup(320, 240);
  7.     image.allocate(320, 240, OF_IMAGE_COLOR);
  8.     gui.setup();
  9.     gui.add(thresh.setup("Threshold", 80, 0, 255));
  10.     gui.add(showVideo.setup("Show Video"));
  11.     ofSetFullscreen(true);
  12.    
  13.     for(int i = 0; i < RAIN_COUNT; i++){
  14.         ofPoint point = ofPoint(ofRandom(ofGetWidth()),
  15.                                 ofRandom(ofGetHeight()) );
  16.         rain.push_back(point);
  17.         velocity.push_back(0.1);
  18.         text.push_back(ofRandom('A', 'Z'));
  19.     }
  20. }
  21.  
  22. void ofApp::update(){
  23.     // image
  24.     grabber.update();
  25.     unsigned char *imgPixels = image.getPixels().getData();
  26.     unsigned char *vidPixels = grabber.getPixels().getData();
  27.     for(int i = 0; i < 320*240; i++){
  28.         unsigned char gray = (vidPixels[i*3+0] + vidPixels[i*3+1] + vidPixels[i*3+2])/3.0;
  29.         if(gray < thresh){
  30.             imgPixels[i*3+0] = imgPixels[i*3+1] = imgPixels[i*3+2] = 0;
  31.         }else{
  32.             imgPixels[i*3+0] = imgPixels[i*3+1] = imgPixels[i*3+2] = 255;
  33.         }
  34.     }
  35.     image.update();
  36.    
  37.     // rain
  38.     for(int i = 0; i < RAIN_COUNT; i++){
  39.        
  40.         int smW = rain[i].x / ofGetWidth() * 320;
  41.         int smH = rain[i].y / ofGetHeight() * 240;
  42.         int p = (smW + smH*320)*3;
  43.         if(imgPixels[p] > thresh){
  44.             rain[i].y += velocity[i];
  45.             velocity[i] += 0.1;
  46.         }
  47.         else{
  48.             rain[i].x = ofRandom(ofGetWidth());
  49.             rain[i].y = 0;
  50.             velocity[i] = 0;
  51.             text[i] = ofRandom('A', 'Z');
  52.         }
  53.     }
  54. }
  55.  
  56. void ofApp::draw(){
  57.     ofBackground(0);
  58.     ofSetColor(255, 255);
  59.     if(showVideo){
  60.         grabber.draw(0, 0, ofGetWidth(), ofGetHeight());
  61.     } else{
  62.         image.draw(0, 0, ofGetWidth(), ofGetHeight());
  63.     }
  64.    
  65. //  ofSetColor(50, 50, 255, 255);
  66.     for(int i = 0; i < RAIN_COUNT; i++){
  67. //      ofDrawCircle(rain[i], 5);
  68.         ofDrawBitmapString(text[i], rain[i]);
  69.     }
  70.    
  71.     if(showGui){
  72.         gui.draw();
  73.     }
  74. }
  75.  
  76. //--------------------------------------------------------------
  77. void ofApp::keyPressed(int key){
  78.     if(key == ' '){
  79.         showGui = !showGui;
  80.     }
  81. }
  82.  
  83. //--------------------------------------------------------------
  84. void ofApp::keyReleased(int key){
  85.  
  86. }
  87.  
  88. //--------------------------------------------------------------
  89. void ofApp::mouseMoved(int x, int y ){
  90.  
  91. }
  92.  
  93. //--------------------------------------------------------------
  94. void ofApp::mouseDragged(int x, int y, int button){
  95.  
  96. }
  97.  
  98. //--------------------------------------------------------------
  99. void ofApp::mousePressed(int x, int y, int button){
  100.  
  101. }
  102.  
  103. //--------------------------------------------------------------
  104. void ofApp::mouseReleased(int x, int y, int button){
  105.  
  106. }
  107.  
  108. //--------------------------------------------------------------
  109. void ofApp::mouseEntered(int x, int y){
  110.  
  111. }
  112.  
  113. //--------------------------------------------------------------
  114. void ofApp::mouseExited(int x, int y){
  115.  
  116. }
  117.  
  118. //--------------------------------------------------------------
  119. void ofApp::windowResized(int w, int h){
  120.  
  121. }
  122.  
  123. //--------------------------------------------------------------
  124. void ofApp::gotMessage(ofMessage msg){
  125.  
  126. }
  127.  
  128. //--------------------------------------------------------------
  129. void ofApp::dragEvent(ofDragInfo dragInfo){
  130.  
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement