This site requires JavaScript, please enable it in your browser!
Greenfoot back
ItzTigerr
ItzTigerr wrote ...

2020/2/11

Repaint and GetRandomNumber

ItzTigerr ItzTigerr

2020/2/11

#
How would I use these two to repaint my world random colors?
Super_Hippo Super_Hippo

2020/2/11

#
You probably won’t need the repaint method at all. What exactly do you mean with random colors? Do you want to give every pixel on your background image a random color? Or one random color for the whole background?
ItzTigerr ItzTigerr

2020/2/11

#
Super_Hippo wrote...
You probably won’t need the repaint method at all. What exactly do you mean with random colors? Do you want to give every pixel on your background image a random color? Or one random color for the whole background?
no I just want the color of the background to change every time I click reset.
Super_Hippo Super_Hippo

2020/2/11

#
Use this in the world’s constructor:
GreenfootImage img = new GreenfootImage(getWidth(), getHeight());
img.setColor(new Color(Greenfoot.getRandomNumber(255), Greenfoot.getRandomNumber(255), Greenfoot.getRandomNumber(255)));
img.fill();
setBackground(img);
You need to login to post a reply.