Guest User

Untitled

a guest
Jul 21st, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. #include "testApp.h"
  2. #include "stdio.h"
  3.  
  4.  
  5. //--------------------------------------------------------------
  6. void testApp::setup(){
  7. bFill = true;
  8.  
  9. screenWidth = ofGetScreenWidth();
  10. screenHeight = ofGetScreenHeight();
  11.  
  12. fingerMovie.loadMovie("zombies.mov");
  13. fingerMovie.play();
  14.  
  15. ofSetFrameRate(60);
  16. }
  17.  
  18. //--------------------------------------------------------------
  19. void testApp::update(){
  20. fingerMovie.idleMovie();
  21. }
  22.  
  23. //--------------------------------------------------------------
  24. void testApp::draw(){
  25. int w = fingerMovie.getWidth();
  26. int h = fingerMovie.getHeight();
  27.  
  28. //----------------------------
  29. // Bonuse :)
  30. // Mouse draw - with curved line
  31. //
  32. ofBackground(0, 0, 0);
  33.  
  34. if( pts.size() > 0 ){
  35.  
  36. int numPts = pts.size();
  37. float radius = 15.0;
  38.  
  39. output.fill();
  40. output.setColor(0xFFFFFF);
  41. for(int i = 0; i < numPts; i++){
  42. output.circle(pts[i].x, pts[i].y, radius);
  43. }
  44. }
  45.  
  46. //--------------------
  47. // Grab Screen for Mask
  48. mask.grabScreen(0, 0, w, h);
  49. mask.setImageType(OF_IMAGE_GRAYSCALE);
  50.  
  51. //----------------------------
  52. // Video
  53.  
  54. // Apply Mask
  55. unsigned char * pixels = new unsigned char[w*h*4];
  56. unsigned char * moviePixels = fingerMovie.getPixels();
  57. unsigned char * alphaPixels = mask.getPixels();
  58.  
  59. for (int i = 0; i < w; i++){
  60. for (int j = 0; j < h; j++){
  61. int pos = (j * w + i);
  62. pixels[pos*4 ] = moviePixels[pos * 3];
  63. pixels[pos*4+1] = moviePixels[pos * 3+1];
  64. pixels[pos*4+2] = moviePixels[pos * 3+2];
  65. pixels[pos*4+3] = alphaPixels[pos];
  66. }
  67. }
  68.  
  69. rgbaMixture.allocate(w,h,GL_RGBA);
  70. rgbaMixture.loadData(pixels, w,h,GL_RGBA);
  71.  
  72. delete [] pixels;
  73.  
  74.  
  75. // Draw Video
  76. ofEnableAlphaBlending();
  77. rgbaMixture.draw(0,0);
  78. ofDisableAlphaBlending();
  79. }
  80.  
  81. //--------------------------------------------------------------
  82. void testApp::keyPressed(int key){
  83. switch (key){
  84. case ' ':
  85. pts.clear();
  86.  
  87. break;
  88. }
  89. }
  90.  
  91. //--------------------------------------------------------------
  92. void testApp::keyReleased(int key){
  93.  
  94. }
  95.  
  96. //--------------------------------------------------------------
  97. void testApp::mouseMoved(int x, int y ){
  98.  
  99. }
  100.  
  101. //--------------------------------------------------------------
  102. void testApp::mouseDragged(int x, int y, int button){
  103.  
  104. //we add a new point to our line
  105. pts.push_back(ofPoint());
  106. int last = pts.size()-1;
  107.  
  108. if(last <= 0){
  109. pts[0].x = x;
  110. pts[0].y = y;
  111.  
  112. } else {
  113. pts[last].x = x;
  114. pts[last].y = y;
  115. }
  116. }
  117.  
  118. //--------------------------------------------------------------
  119. void testApp::mousePressed(int x, int y, int button){
  120. pts.push_back(ofPoint());
  121. int last = pts.size()-1;
  122.  
  123. if(last <= 0){
  124. pts[0].x = x;
  125. pts[0].y = y;
  126.  
  127. } else {
  128. pts[last].x = x;
  129. pts[last].y = y;
  130. }
  131. }
  132.  
  133.  
  134. //--------------------------------------------------------------
  135. void testApp::mouseReleased(int x, int y, int button){
  136.  
  137. }
  138.  
  139. //--------------------------------------------------------------
  140. void testApp::windowResized(int w, int h){
  141.  
  142. }
Add Comment
Please, Sign In to add comment