[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Color, unpacking to r,g,b and r,g,b,a - ValueError: too many values to unpack
On Thu, Jun 18, 2009 at 11:47 AM, Brian Fisher<brian@xxxxxxxxxxxxxxxxxxx> wrote:
> On Wed, Jun 17, 2009 at 6:12 PM, René Dudfield <renesd@xxxxxxxxx> wrote:
>>
>> Yeah, that's another option to consider. Except returning Color is so
>> much nicer to use than a tuple for colors (and slightly quicker... but
>> that's not a big point). Also it should be more consistent to have
>> all the methods returning Colors for colors.
>>
> My response on the consistency front would be:
> 1. that I would rather a color object be consistent in how it "unpacks" than
> be inconsistent based on some length option for the sake of old code
yeah. However I think this brings up the use cases of 3 and 4 element colors.
> 2. the new version of pygame would not be adding any new inconsistency by
> making the palette stuff return 3-tuples instead of color object - clearly
> the palette functions were already inconsistent with the rest of
> color-getting functions, otherwise we wouldn't have this problem to deal
> with.
>
Yeah, these were already inconsistent in this way.
Except I think that returning a 3 element color is valid in this case.
It's more appropriate in this case because the colors are r,g,b,255
... as you mention below.
> ... so I assume a palette can not take alpha, which is why the functions
> didn't return one, right? it seems like to have those functions return an
> object which even has an alpha member would be an opportunity to allow for
> confusion about what should work.
>
>
Yeah, the alpha part is assumed to be 255 at the moment.
SDL_Palette structures are defined like this:
typedef struct{
int ncolors;
SDL_Color *colors;
} SDL_Palette;
typedef struct{
Uint8 r;
Uint8 g;
Uint8 b;
Uint8 unused;
} SDL_Color;
Since we already use 3, and 4 element colors I think it makes sense to
support them in Color. A Color3 and Color4 if you will.
The reason for not having a whole new Python type seems silly, when we
can have the same thing by letting Color set its length. So it's a
Color3-like type, in the same way a tuple (0,1,2) is a Color3-like
type, and a (0,1,2,3) is a Color4-like Color.
Perhaps Color3 should make the alpha part always be 255.
- References:
- [pygame] Color, unpacking to r,g,b and r,g,b,a - ValueError: too many values to unpack
- Re: [pygame] Color, unpacking to r,g,b and r,g,b,a - ValueError: too many values to unpack
- Re: [pygame] Color, unpacking to r,g,b and r,g,b,a - ValueError: too many values to unpack
- Re: [pygame] Color, unpacking to r,g,b and r,g,b,a - ValueError: too many values to unpack
- Re: [pygame] Color, unpacking to r,g,b and r,g,b,a - ValueError: too many values to unpack
- Re: [pygame] Color, unpacking to r,g,b and r,g,b,a - ValueError: too many values to unpack
- Re: [pygame] Color, unpacking to r,g,b and r,g,b,a - ValueError: too many values to unpack
- Re: [pygame] Color, unpacking to r,g,b and r,g,b,a - ValueError: too many values to unpack
- Re: [pygame] Color, unpacking to r,g,b and r,g,b,a - ValueError: too many values to unpack
- Re: [pygame] Color, unpacking to r,g,b and r,g,b,a - ValueError: too many values to unpack
- Prev by Author:
Re: [pygame] Color, unpacking to r,g,b and r,g,b,a - ValueError: too many values to unpack
- Next by Author:
Re: [pygame] Communicating with an event queue
- Previous by thread:
Re: [pygame] Color, unpacking to r,g,b and r,g,b,a - ValueError: too many values to unpack
- Next by thread:
Re: [pygame] Color, unpacking to r,g,b and r,g,b,a - ValueError: too many values to unpack
- Index(es):