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

2018/4/7

Changing color

VladislavMoldovan VladislavMoldovan

2018/4/7

#
How can I change the color of drawn oval?
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class MyWorld here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class MyWorld extends World
{

    private static int _Width = 50;
    private static int _Height = 50;
    
    /**
     * Constructor for objects of class MyWorld.
     * 
     */
    public MyWorld()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(600, 400, 1);
        
        for(int i = 0; i < 10; i++)
        {
            GreenfootImage image = new GreenfootImage(_Width, _Height);
            image.fillOval(0, 0, _Width, _Height);
            Ball ball = new Ball();
            ball.setImage(image);
            addObject(ball, Greenfoot.getRandomNumber(getWidth()), Greenfoot.getRandomNumber(getHeight()));
        }
    }
}
bravdwal bravdwal

2018/4/7

#
I think the setColor(color color)-method of the GreenfootImage class should suffice. More info: https://www.greenfoot.org/files/javadoc/greenfoot/GreenfootImage.html#setColor-greenfoot.Color- and: https://www.greenfoot.org/files/javadoc/greenfoot/Color.html
You need to login to post a reply.