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

2011/11/30

Randombackground color

Scaldren Scaldren

2011/11/30

#
I know how to make the background a random image but what if i want a random blank color from the start?
bourne bourne

2011/11/30

#
Then create an image filled with a random Color. You could try (note you would need to have "import java.awt.Color;")
GreenfootImage pic = new GreenfootImage(600, 400);
pic.setColor(new Color(Greenfoot.getRandomNumber(255 + 1), Greenfoot.getRandomNumber(255 + 1), Greenfoot.getRandomNumber(255 + 1)));
pic.fill();
setBackground(pic);
Or if you want a select few Colors to randomly pick from: (note you would need to have "import java.awt.Color;" AND "import java.util.*;")
ArrayList<Color> colors = new ArrayList<Color>(){{ add(Color.RED); add(Color.BLUE); add(Color.YELLOW); }};
GreenfootImage pic = new GreenfootImage(600, 400);
pic.setColor(colors.get(Greenfoot.getRandomNumber(colors.size())));
pic.fill();
setBackground(pic);
You need to login to post a reply.