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