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

2015/11/16

changing colour

Psychpsyo Psychpsyo

2015/11/16

#
Hello. If I have an actor, that is just a square with gray shades. Is there any possibility, to let it change the colour? So it has green shades instead of gray.
danpost danpost

2015/11/16

#
It would help if you show or let us know how the image is set originally (it would be something to work off of).
Psychpsyo Psychpsyo

2015/11/16

#
http://abload.de/img/planet_clouds5kj94.png This is the image.
danpost danpost

2015/11/16

#
Psychpsyo wrote...
This is the image.
I want to know what code, if any, you used to initially set the image of the actor. If it is an image that is set as the default image for the class, then state so; otherwise, show the code you used to create and set the initial image. Also, you need to show how you are changing the gray shade of the image (if that is what you are doing). Maybe you were not clear enough as to what you want (or maybe showing the image was trying to portray this). Do you have one image with several gray shades in it? or, do you have the image changing the shade of gray it is?
Psychpsyo Psychpsyo

2015/11/17

#
The image is set as default image for the class. And I don't want to change the grey shades of the picture. I want greenfoot to replace the grey shades with another color. (blue for example) So the dark grey parts become dark blue, the brighter parts become a brighter blue.
danpost danpost

2015/11/17

#
Here is a method that might be useful:
private Color bluer(Color color)
{
    int r = color.getRed();
    int g = color.getGreen();
    int b = color.getBlue();
    return new Color(r/2, g/2, 255-(255-b)/2);
}
Here is an example of how the first pixel in the image can be made bluer:
Color color = image.getColorAt(0, 0); // gets original color
image.setColorAt(0, 0, bluer(color)); // sets new color
You will have to iterate through all the pixels of the image and change each one.
Psychpsyo Psychpsyo

2015/11/18

#
Can I use variables in the getColorAt(0, 0); code?
danpost danpost

2015/11/18

#
Psychpsyo wrote...
Can I use variables in the getColorAt(0, 0); code?
Absolutely. Use two 'for' loop variables.
You need to login to post a reply.