Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Using several 2D primitives as mask when masking one video out of another

$
0
0

Hi there,

I am trying to use different moving 2D primitives to mask out a video and play it on top of another video.

Here is how far I have gotten until now:

import processing.video.*;

Movie myMovie;
float a;
float b;
float c;
float d;
float theta = 0.0;
int threshold = 240;

void setup() {
  size(640, 360);
  myMovie = new Movie(this, "station.MOV");
  myMovie.loop();
  myMovie.volume(0);
  a = height/2;
}

void draw() {
  background(55);
  image(myMovie, 0, 0, width, height);

  Mask();
}

void Mask() {
  float x = (sin(theta) + 1) * width/8;
  theta += 0.005;

  //horizontal lines
  stroke(255);
  strokeWeight(1);
  line(0, a, width, a);
  a = a - 0.2;
  if (a < 0) {
    a = height;
  }

  strokeWeight(5);
  line(0, b, width, b);
  b = b + 0.1;
  if (b > height) {
    b = 0;
  }

  //Vertical lines
    noStroke();
  fill(155);
  rect(c, 0, 50+x, height);
  c = c -0.2;
  if (c < -50-x) {
    c = width;
  }

  noStroke();
  fill(255);
  rect(d, 0, (10+x), height);
  d = d +0.3;
  if (d > (width+100)) {
    d = -x;
  }

}
void movieEvent(Movie m) {
  m.read();
}

So as you can see I am running a video as a background. On top of this video there are several moving white and grey rectangles and lines.

My question is: How can I use the primitives all together to mask out a second video?

I would like to do it in a way that allows transparency in relation to the brightness of the mask (50% gray = 50% transparent).

Hope my question makes sense.

Best regards


Viewing all articles
Browse latest Browse all 2896

Trending Articles