/** * Gives the worlds background image a gradient between 2 colors. * Example call to this: createGradientBGImage(Color.RED, Color.BLUE); * This requires "import java.awt.Color;" and must be in a class that * extends greenfoot.World */ private void createGradientBGImage(Color left, Color right) { int width = getWidth(), height = getHeight(), leftMult, rightMult, r, g, b; GreenfootImage img = new GreenfootImage(width, height); for(int x = 0; x < width; x++) { leftMult = 255 - (x*255/width); rightMult = 255 - leftMult; r = ((left.getRed() *leftMult) + (right.getRed() *rightMult))/510; g = ((left.getGreen()*leftMult) + (right.getGreen()*rightMult))/510; b = ((left.getBlue() *leftMult) + (right.getBlue() *rightMult))/510; Color c = new Color(r, g, b); for(int y = 0; y < height; y++) img.setColorAt(x, y, c); } setBackground(img); }