Alpha Channel not Changing
in
Core Library Questions
•
5 months ago
Hi, I am pretty new to Processing, have been working on it for a few months. I have searched through the internet but my problem doesn't make sense.
I have two videos playing and want to have a fade transition between them. I access directly each pixel but no matter what the alpha value is there is no change. For now I just have my code prepared to fade from a specific video to the other. If I can make it fade from this video to the other I will be able to adapt and fade for the video that currently will be playing.
Here is my code:
- import processing.video.*;
- Movie movie1, movie2;
- float alpha;
- void setup() {
- alpha = 255.0;
- size(320, 240, P2D);
- movie1 = new Movie(this, "Video1.mov");
- movie2 = new Movie(this, "Video2.mov");
- movie1.loop();
- movie2.loop();
- }
- void movieEvent(Movie mov) {
- mov.read();
- }
- void draw() {
- if (fade) { // Fade Transition
- image(movie1, 0, 0, width, height);
- fade(movie1, movie2, movie1Playing);
- } else {
- image(movie2, 0, 0, width, height);
- }
- }
- void fade(Movie mov1, Movie mov2) {
- float r = 0.0;
- float g = 0.0;
- float b = 0.0;
- int x = 0;
- int y = 0;
- int pos = 0;
- loadPixels();
- mov1.loadPixels();
- mov2.loadPixels();
- if(alpha > 0) {
- alpha--;
- }
- for (x = 0; x < mov2.width; x++) {
- for (y = 0; y < mov2.height; y++ ) {
- pos = x + y*mov2.width;
- r = red(mov2.pixels[pos]);
- g = green(mov2.pixels[pos]);
- b = blue(mov2.pixels[pos]);
- color newColor = color(r,g,b, alpha);
- pixels[pos] = newColor;
- }
- }
- updatePixels();
- }
- void keyPressed() {
- switch (key) {
- case 'f':
- fade = !fade;
- break;
- }
- }
I don't know why it's not working. I would appreciate any help you can give me.
Thanks in advance!
1