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

**URL:** https://discourse.processing.org/t/how-to-change-image-rbg-value-when-image-hits-x-or-y-axis/40114
**Category:** Coding Questions
**Created:** [December 11, 2022, 12:21am UTC](https://discourse.processing.org/t/how-to-change-image-rbg-value-when-image-hits-x-or-y-axis/40114 "2022-12-11T00:21:44Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Mikella](https://avatars.discourse-cdn.com/v4/letter/m/b9bd4f/32.png) [@Mikella](https://discourse.processing.org/u/Mikella)
#### Post date: [December 11, 2022, 12:21am UTC](https://discourse.processing.org/t/how-to-change-image-rbg-value-when-image-hits-x-or-y-axis/40114/1 "2022-12-11T00:21:44Z")

</div>

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!

```auto

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;
   
  
  }

```

---

<div class="post-metadata">

### Author: ![Mikey83](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mikey83/32/17956_2.png) [@Mikey83](https://discourse.processing.org/u/Mikey83)
#### Post date: [December 11, 2022, 1:02pm UTC](https://discourse.processing.org/t/how-to-change-image-rbg-value-when-image-hits-x-or-y-axis/40114/2 "2022-12-11T13:02:38Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Mikella](https://avatars.discourse-cdn.com/v4/letter/m/b9bd4f/32.png) [@Mikella](https://discourse.processing.org/u/Mikella)
#### Post date: [December 11, 2022, 6:22pm UTC](https://discourse.processing.org/t/how-to-change-image-rbg-value-when-image-hits-x-or-y-axis/40114/3 "2022-12-11T18:22:51Z")

</div>

Hey, yeah that definitely makes sense, thank you!
