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

2011/11/12

GreenfootImage set' and get' ColorAt methods

1
2
bourne bourne

2011/11/12

#
The following will print out: "r199,g0,b0,a50" when I believe it should be "r200,g0,b0,a50"
GreenfootImage pic = new GreenfootImage(5, 5);
        pic.setColor(new Color(255, 0, 0, 60));
        pic.fill();
        for (int i = 0; i < pic.getHeight(); i++)
            for (int k = 0; k < pic.getWidth(); k++)
                pic.setColorAt(k, i, new Color(200, 0, 0, 50));
        Color c = pic.getColorAt(0, 0);
        System.out.println("r" + c.getRed() + ",g" + c.getGreen() + ",b" + c.getBlue() + ",a" + c.getAlpha());
Fernando Fernando

2011/11/12

#
I tried it and I got: r200,g0,b0,a50
Fernando Fernando

2011/11/12

#
Why can't i upload pics?
bourne bourne

2011/11/12

#
What the heck. What's wrong with my computer then
bourne bourne

2011/11/12

#
It's really bad when c.equals(new Color(200, 0, 0, 50)) will return false when I need it to return true. You running on a pc or mac?
Fernando Fernando

2011/11/12

#
On a PC.
bourne bourne

2011/11/12

#
Okay I'm on a mac. Anyone else on a mac want to try this?
Builderboy2005 Builderboy2005

2011/11/12

#
I got r200,g0,b0,a50 as well. Does this happen even if you open a new scenario and use only the code you posted?
bourne bourne

2011/11/12

#
Yep just tried it. =/
bourne bourne

2011/11/12

#
Okay I exported as a webpage and a jar and both worked correctly, from the same greenfoot project that makes it not work.
bourne bourne

2011/11/12

#
I tried redownloading Greenfoot and it still acts this way
Builderboy2005 Builderboy2005

2011/11/12

#
Sounds like a bug o.O Try making an image 256 pixels long, and setting each pixel to one value from 1-256, and see if it consistently is incorrect, and in what way.
bourne bourne

2011/11/12

#
I did the following test that outputted the following..
GreenfootImage pic = new GreenfootImage(256, 5);
for (int i = 0; i < 256; i++)
{
        pic.setColorAt(i, 0, new Color(i, 0, 0, 60));
        System.out.println(i + "," + pic.getColorAt(i, 0).equals(new Color(i, 0, 0, 60)));
}
0,true 1,false 2,false 3,false 4,true 5,false 6,false 7,false 8,false 9,true 10,false 11,false 12,false 13,true 14,false 15,false 16,false 17,true 18,false 19,false 20,false 21,true 22,false 23,false 24,false 25,false 26,true 27,false 28,false 29,false 30,true 31,false 32,false 33,false 34,true 35,false 36,false 37,false 38,true 39,false 40,false 41,false 42,false 43,true 44,false 45,false 46,false 47,true 48,false 49,false 50,false 51,true 52,false 53,false 54,false 55,true 56,false 57,false 58,false 59,false 60,true 61,false 62,false 63,false 64,true 65,false 66,false 67,false 68,true 69,false 70,false 71,false 72,true 73,false 74,false 75,false 76,false 77,true 78,false 79,false 80,false 81,true 82,false 83,false 84,false 85,true 86,false 87,false 88,false 89,true 90,false 91,false 92,false 93,false 94,true 95,false 96,false 97,false 98,true 99,false 100,false 101,false 102,true 103,false 104,false 105,false 106,true 107,false 108,false 109,false 110,false 111,true 112,false 113,false 114,false 115,true 116,false 117,false 118,false 119,true 120,false 121,false 122,false 123,true 124,false 125,false 126,false 127,false 128,true 129,false 130,false 131,false 132,true 133,false 134,false 135,false 136,true 137,false 138,false 139,false 140,true 141,false 142,false 143,false 144,false 145,true 146,false 147,false 148,false 149,true 150,false 151,false 152,false 153,true 154,false 155,false 156,false 157,true 158,false 159,false 160,false 161,false 162,true 163,false 164,false 165,false 166,true 167,false 168,false 169,false 170,true 171,false 172,false 173,false 174,true 175,false 176,false 177,false 178,false 179,true 180,false 181,false 182,false 183,true 184,false 185,false 186,false 187,true 188,false 189,false 190,false 191,true 192,false 193,false 194,false 195,false 196,true 197,false 198,false 199,false 200,true 201,false 202,false 203,false 204,true 205,false 206,false 207,false 208,true 209,false 210,false 211,false 212,false 213,true 214,false 215,false 216,false 217,true 218,false 219,false 220,false 221,true 222,false 223,false 224,false 225,true 226,false 227,false 228,false 229,false 230,true 231,false 232,false 233,false 234,true 235,false 236,false 237,false 238,true 239,false 240,false 241,false 242,true 243,false 244,false 245,false 246,false 247,true 248,false 249,false 250,false 251,true 252,false 253,false 254,false 255,true
bourne bourne

2011/11/12

#
Changing the printout to be System.out.println(i + "," + pic.getColorAt(i, 0).getRed()); The output is 0,0 1,0 2,0 3,4 4,4 5,4 6,4 7,9 8,9 9,9 10,9 11,13 12,13 13,13 14,13 15,17 16,17 17,17 18,17 19,17 20,21 21,21 22,21 23,21 24,26 25,26 26,26 27,26 28,30 29,30 30,30 31,30 32,34 33,34 34,34 35,34 36,34 37,38 38,38 39,38 40,38 41,43 42,43 43,43 44,43 45,47 46,47 47,47 48,47 49,51 50,51 51,51 52,51 53,51 54,55 55,55 56,55 57,55 58,60 59,60 60,60 61,60 62,64 63,64 64,64 65,64 66,68 67,68 68,68 69,68 70,68 71,72 72,72 73,72 74,72 75,77 76,77 77,77 78,77 79,81 80,81 81,81 82,81 83,85 84,85 85,85 86,85 87,85 88,89 89,89 90,89 91,89 92,94 93,94 94,94 95,94 96,98 97,98 98,98 99,98 100,102 101,102 102,102 103,102 104,102 105,106 106,106 107,106 108,106 109,111 110,111 111,111 112,111 113,115 114,115 115,115 116,115 117,119 118,119 119,119 120,119 121,119 122,123 123,123 124,123 125,123 126,128 127,128 128,128 129,128 130,132 131,132 132,132 133,132 134,136 135,136 136,136 137,136 138,136 139,140 140,140 141,140 142,140 143,145 144,145 145,145 146,145 147,149 148,149 149,149 150,149 151,153 152,153 153,153 154,153 155,153 156,157 157,157 158,157 159,157 160,162 161,162 162,162 163,162 164,166 165,166 166,166 167,166 168,170 169,170 170,170 171,170 172,170 173,174 174,174 175,174 176,174 177,179 178,179 179,179 180,179 181,183 182,183 183,183 184,183 185,187 186,187 187,187 188,187 189,187 190,191 191,191 192,191 193,191 194,196 195,196 196,196 197,196 198,200 199,200 200,200 201,200 202,204 203,204 204,204 205,204 206,204 207,208 208,208 209,208 210,208 211,213 212,213 213,213 214,213 215,217 216,217 217,217 218,217 219,221 220,221 221,221 222,221 223,221 224,225 225,225 226,225 227,225 228,230 229,230 230,230 231,230 232,234 233,234 234,234 235,234 236,238 237,238 238,238 239,238 240,238 241,242 242,242 243,242 244,242 245,247 246,247 247,247 248,247 249,251 250,251 251,251 252,251 253,255 254,255 255,255
Builderboy2005 Builderboy2005

2011/11/13

#
Strange, it seems that for some reason, Greenfoot is limiting your colors to 5 bit instead of 8 bit or something. Definitely a bug, I would send them an email about it so they know
There are more replies on the next page.
1
2