How to Change Image RBG value when image hits x or y axis

Hi so I’m brand new to coding, just started maybe a week ago for a class. I’m trying to code the “dvd logo.png” image to hit a random RGB value when it hits the x and y borders of the window. So far it will load a random color when the program is started, but it stays the same until the program is closed. Is there any way to execute the random color value code each time it hits a side?
Thanks!


int R;

int G;

int B;

PImage img;

float xpos = 0;

float ypos = 0;

float speedx = 10;

float speedy= 15;

PImage screen;


void setup(){

   screen= loadImage("wp6985856.jpg");
    
   size(400,400);
  
   background(screen);
 
   img = loadImage("dvd logo.png");
   
   frameRate(15);
  
   int R = (int)random(0,255);
    
   int G = (int)random(0,255);
    
   int B = (int)random(0,255);


 tint(color(R,G,B));

}

  void draw(){
   
   background(screen);
 
   image(img, xpos, ypos);  
  
  if (((xpos+10)< 0) || (xpos>width-60))
  
   speedx=speedx* -1;
      
      
   if (((ypos+10)< 0) || (ypos>height-28))

   speedy = speedy * -1;
  
 
   xpos=xpos+speedx;
     
ypos=ypos+speedy;
   
  
  }

Hi and welcome to the coding world lol.

You already have the RGB as global variables so theres no need to declare them as ints in setup aswell, but what you want instead is to generate new values for them in your if statements in draw(), then add the tint() above the image in draw() aswell, setup is only called at the beginning of the program, draw is called every frame which is 60 times a second as default

Hope that makes sense

Hey, yeah that definitely makes sense, thank you!