how to display GIF in the background?

I would like to create a disco light effect on a dance gif. So the gif is on the bottom layer, then a rectangle is flashing on top according to framerate. But somehow the gif is alway on the top, even though I place it before the rectangle. Could someone help me review the code?

var img;  
function preload() {   
img = createImg("dancegif.gif");
}

function setup(){
    createCanvas(window.innerWidth,window.innerHeight); 
}

function draw(){
    background(255);

  img.position(0,0);

    // flashing effect 
    noStroke();
    if(frameCount % 7 < 3 ){
      noFill(); //pic 33%  12 
    } else if(frameCount % 7 > random(3,4) ){
        fill(255);//white 33% 56 
    } else{
        fill(0);//black 34% 
    }
    rect(0,0,window.innerWidth,window.innerHeight);

}

Answers

Sign In or Register to comment.