Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "testApp.h"
- #include "stdio.h"
- //--------------------------------------------------------------
- void testApp::setup(){
- bFill = true;
- screenWidth = ofGetScreenWidth();
- screenHeight = ofGetScreenHeight();
- fingerMovie.loadMovie("zombies.mov");
- fingerMovie.play();
- ofSetFrameRate(60);
- }
- //--------------------------------------------------------------
- void testApp::update(){
- fingerMovie.idleMovie();
- }
- //--------------------------------------------------------------
- void testApp::draw(){
- int w = fingerMovie.getWidth();
- int h = fingerMovie.getHeight();
- //----------------------------
- // Bonuse :)
- // Mouse draw - with curved line
- //
- ofBackground(0, 0, 0);
- if( pts.size() > 0 ){
- int numPts = pts.size();
- float radius = 15.0;
- output.fill();
- output.setColor(0xFFFFFF);
- for(int i = 0; i < numPts; i++){
- output.circle(pts[i].x, pts[i].y, radius);
- }
- }
- //--------------------
- // Grab Screen for Mask
- mask.grabScreen(0, 0, w, h);
- mask.setImageType(OF_IMAGE_GRAYSCALE);
- //----------------------------
- // Video
- // Apply Mask
- unsigned char * pixels = new unsigned char[w*h*4];
- unsigned char * moviePixels = fingerMovie.getPixels();
- unsigned char * alphaPixels = mask.getPixels();
- for (int i = 0; i < w; i++){
- for (int j = 0; j < h; j++){
- int pos = (j * w + i);
- pixels[pos*4 ] = moviePixels[pos * 3];
- pixels[pos*4+1] = moviePixels[pos * 3+1];
- pixels[pos*4+2] = moviePixels[pos * 3+2];
- pixels[pos*4+3] = alphaPixels[pos];
- }
- }
- rgbaMixture.allocate(w,h,GL_RGBA);
- rgbaMixture.loadData(pixels, w,h,GL_RGBA);
- delete [] pixels;
- // Draw Video
- ofEnableAlphaBlending();
- rgbaMixture.draw(0,0);
- ofDisableAlphaBlending();
- }
- //--------------------------------------------------------------
- void testApp::keyPressed(int key){
- switch (key){
- case ' ':
- pts.clear();
- break;
- }
- }
- //--------------------------------------------------------------
- void testApp::keyReleased(int key){
- }
- //--------------------------------------------------------------
- void testApp::mouseMoved(int x, int y ){
- }
- //--------------------------------------------------------------
- void testApp::mouseDragged(int x, int y, int button){
- //we add a new point to our line
- pts.push_back(ofPoint());
- int last = pts.size()-1;
- if(last <= 0){
- pts[0].x = x;
- pts[0].y = y;
- } else {
- pts[last].x = x;
- pts[last].y = y;
- }
- }
- //--------------------------------------------------------------
- void testApp::mousePressed(int x, int y, int button){
- pts.push_back(ofPoint());
- int last = pts.size()-1;
- if(last <= 0){
- pts[0].x = x;
- pts[0].y = y;
- } else {
- pts[last].x = x;
- pts[last].y = y;
- }
- }
- //--------------------------------------------------------------
- void testApp::mouseReleased(int x, int y, int button){
- }
- //--------------------------------------------------------------
- void testApp::windowResized(int w, int h){
- }
Add Comment
Please, Sign In to add comment