Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Re : mask on a videoloop is blinking

$
0
0
All right, that's a bit easier with all the assets.

Made some changes:
  • Put all the read()'s into draw which indeed seems to solve the flickering issue. Plus it allows for more efficient masking. Once per new frame, instead of once per circle.
  • Adapted shape selection.
  • Adapted shape movement.

Adapted Code
  1. // Processing 2.0b8
  2.  
  3. import processing.video.*;
  4.  
  5. int numCircles = 16;
  6. PImage maskImage;
  7. Movie[] eye = new Movie[2];
  8. Circle[] circles = new Circle[numCircles];
  9. int selectedCircle = -1;
  10.  
  11. void setup() {
  12.   size(1920, 1000);
  13.   imageMode(CENTER);
  14.   smooth();
  15.  
  16.   maskImage = loadImage("mask-bg.jpg");
  17.  
  18.   eye[0] = new Movie(this, "eye.mov");
  19.   eye[1] = new Movie(this, "eye2.mov");
  20.  
  21.   for (int i=0; i<eye.length; i++) {
  22.     eye[i].loop();
  23.   }
  24.  
  25.   for (int i=0; i<circles.length; i++) {
  26.     circles[i] = new Circle();
  27.   }
  28. }
  29.  
  30. void draw() {
  31.   background(0);
  32.   for (int i=0; i<eye.length; i++) {
  33.     if (eye[i].available()) {
  34.       eye[i].read();
  35.       eye[i].mask(maskImage);
  36.     }
  37.   }
  38.  
  39.   for (int i=0; i< circles.length; i++) {
  40.     circles[i].display();
  41.   }
  42. }
  43.  
  44. void mousePressed() {
  45.   for (int i=0; i<circles.length; i++) {
  46.     if (circles[i].mouseOverCircle()) {
  47.       selectedCircle = i;
  48.       break;
  49.     }
  50.   }
  51. }
  52.  
  53. void mouseDragged() {
  54.   if (selectedCircle>-1) {
  55.     circles[selectedCircle].move();
  56.   }
  57. }
  58.  
  59. void mouseReleased() {
  60.   selectedCircle = -1;
  61. }
  62.  
  63. class Circle {
  64.   float r, xpos, ypos;
  65.   int selectedMovie;
  66.  
  67.   Circle() {
  68.     xpos = random(width);
  69.     ypos = random(height);
  70.     r = 100;
  71.     selectedMovie = (int) random(eye.length);
  72.   }
  73.  
  74.   void display() {  
  75.     image(eye[selectedMovie], xpos, ypos);
  76.   }
  77.  
  78.   boolean mouseOverCircle() {
  79.     return (dist(mouseX, mouseY, xpos, ypos)<r);
  80.   }
  81.  
  82.   void move() {
  83.     xpos += (mouseX-pmouseX);
  84.     ypos += (mouseY-pmouseY);
  85.     if (xpos>width) { xpos = 0; }
  86.     if (ypos>height) { ypos = 0; }
  87.   }
  88. }

Viewing all articles
Browse latest Browse all 1768

Trending Articles