Re: [pygame] Is there some type of hex codes to rgb converter or something?

2007-09-11 Thread Lamonte Harris
Oh nice, thanks for the alternative But how do u know if ur gonna get a
red/blue...etc.. out the colors, kinda confusing.

On 9/11/07, Peter Shinners <[EMAIL PROTECTED]> wrote:
>
> Lamonte Harris wrote:
> > I like using HTML hex, is there a library or something on pygame or
> > python it self to convert hex to rgb
>
> Pygame comes with a color module. Just noticed it wasn't in the docs
> though.
>
>
> import pygame.color
>
> red = pygame.color.Color("#ff")
> blue = pygame.color.Color("cornflowerblue")
>
> It also includes some simple math, so you can mix colors yourself.
>
> purple = pygame.color.add(red, blue)
>


Re: [pygame] Is there some type of hex codes to rgb converter or something?

2007-09-11 Thread Peter Shinners

Lamonte Harris wrote:
I like using HTML hex, is there a library or something on pygame or 
python it self to convert hex to rgb


Pygame comes with a color module. Just noticed it wasn't in the docs though.


import pygame.color

red = pygame.color.Color("#ff")
blue = pygame.color.Color("cornflowerblue")

It also includes some simple math, so you can mix colors yourself.

purple = pygame.color.add(red, blue)


Re: [pygame] Is there some type of hex codes to rgb converter or something?

2007-09-10 Thread Noah Kantrowitz

#abc -> #aabbcc -> (0xaa, 0xbb, 0xcc)

--Noah

On Sep 10, 2007, at 7:08 PM, Lamonte Harris wrote:

I like using HTML hex, is there a library or something on pygame or  
python it self to convert hex to rgb




Re: [pygame] Is there some type of hex codes to rgb converter or something?

2007-09-10 Thread Luke Paireepinart

Lamonte Harris wrote:

It works well for me.  Its just a snippet i grabed from my class O_o.

The fact that it works doesn't mean it's good practice.
This also works:
a = 1
b = a + 1
c = b + 1
d = c + 1
e = d + 1
but it's much more common (and better practice) to just straight-away say
e = 5
unless you really need all those intermediate values.  And still that 
wouldn't be the best way to assign them.
Your class isn't designed correctly if your methods don't do anything 
but return values.
This is for many reasons: efficiency, maintainability, readability, etc. 
etc.
But in general, the Object Oriented paradigm is centered around objects 
that are collections of data and methods (related functions) that act on 
data.  If your classes just take in external data and output data 
externally to the class, they're not objects.  Then you're just using 
classes to group functions which may or may not be related, and no data 
involving them.
I was trying to word it in a way that was less critical, but that's the 
general meaning I was trying to get across: your class should be 
modifying data internally.
It's possible that the rest of your class does, and for some reason or 
another you just had to code this method this way, but since I can't see 
your code I can only assume.

-Luke


Re: [pygame] Is there some type of hex codes to rgb converter or something?

2007-09-10 Thread Lamonte Harris
It works well for me.  Its just a snippet i grabed from my class O_o.

On 9/10/07, Luke Paireepinart <[EMAIL PROTECTED]> wrote:
>
> Lamonte Harris wrote:
> > I came up w/ this for my class:
> > def hex_converter(self,hexcolorcode):
> > hexcolorcode = hexcolorcode[1:]
> > red = hexcolorcode[0:2]
> > red = int(red,16)
> > blue = hexcolorcode[2:4]
> > blue = int(blue,16)
> > green = hexcolorcode[4:6]
> > green = int(green,16)
> > return (red,green,blue)
> >
> > Thanks. again
> Sure.  Are you sure you're using your classes right, though?  A method
> of a class should change instance attributes, and only secondly return
> values.  That shouldn't be its primary focus.
> If you have more questions that are python-specific but not
> pygame-specific, try asking on the python-tutor mailing list.  It's a
> nice list geared specifically toward people learning Python.
> -Luke
>


Re: [pygame] Is there some type of hex codes to rgb converter or something?

2007-09-10 Thread Luke Paireepinart

Lamonte Harris wrote:

I came up w/ this for my class:
def hex_converter(self,hexcolorcode):
hexcolorcode = hexcolorcode[1:]
red = hexcolorcode[0:2]
red = int(red,16)
blue = hexcolorcode[2:4]
blue = int(blue,16)
green = hexcolorcode[4:6]
green = int(green,16)
return (red,green,blue)

Thanks. again
Sure.  Are you sure you're using your classes right, though?  A method 
of a class should change instance attributes, and only secondly return 
values.  That shouldn't be its primary focus.
If you have more questions that are python-specific but not 
pygame-specific, try asking on the python-tutor mailing list.  It's a 
nice list geared specifically toward people learning Python.

-Luke


Re: [pygame] Is there some type of hex codes to rgb converter or something?

2007-09-10 Thread Lamonte Harris
I came up w/ this for my class:
def hex_converter(self,hexcolorcode):
hexcolorcode = hexcolorcode[1:]
red = hexcolorcode[0:2]
red = int(red,16)
blue = hexcolorcode[2:4]
blue = int(blue,16)
green = hexcolorcode[4:6]
green = int(green,16)
return (red,green,blue)

Thanks. again

On 9/10/07, Lamonte Harris <[EMAIL PROTECTED]> wrote:
>
> Freaking thank you "Tries it out now"
>
> On 9/10/07, Luke Paireepinart <[EMAIL PROTECTED]> wrote:
> >
> > Lamonte Harris wrote:
> > > I like using HTML hex, is there a library or something on pygame or
> > > python it self to convert hex to rgb
> > HTML hex colors are defined as such:
> > color = "#DEFFC3"
> > I.E. a pound sign, then 2 hex digits for red, 2 for green, and 2 for
> > blue.
> > This is very easy to convert between.
> > First let's get rid of the # sign
> > color = color[1:]
> > Next let's separate these into 3 different strings.
> > red = color[0:2]
> > green = color[2:4]
> > blue = color[4:6]
> >
> > Next let's convert these all to integers
> > red = int(red, 16)
> > green = int(green, 16)
> > blue = int(blue, 16)
> >
> > I'll leave it as an exercise for the reader to simplify this (I.E. I
> > have food on the stove and I have to go take it off.)
> > HTH,
> > -Luke
> >
>
>


Re: [pygame] Is there some type of hex codes to rgb converter or something?

2007-09-10 Thread Lamonte Harris
Freaking thank you "Tries it out now"

On 9/10/07, Luke Paireepinart <[EMAIL PROTECTED]> wrote:
>
> Lamonte Harris wrote:
> > I like using HTML hex, is there a library or something on pygame or
> > python it self to convert hex to rgb
> HTML hex colors are defined as such:
> color = "#DEFFC3"
> I.E. a pound sign, then 2 hex digits for red, 2 for green, and 2 for blue.
> This is very easy to convert between.
> First let's get rid of the # sign
> color = color[1:]
> Next let's separate these into 3 different strings.
> red = color[0:2]
> green = color[2:4]
> blue = color[4:6]
>
> Next let's convert these all to integers
> red = int(red, 16)
> green = int(green, 16)
> blue = int(blue, 16)
>
> I'll leave it as an exercise for the reader to simplify this (I.E. I
> have food on the stove and I have to go take it off.)
> HTH,
> -Luke
>


Re: [pygame] Is there some type of hex codes to rgb converter or something?

2007-09-10 Thread Luke Paireepinart

Lamonte Harris wrote:
I like using HTML hex, is there a library or something on pygame or 
python it self to convert hex to rgb

HTML hex colors are defined as such:
color = "#DEFFC3"
I.E. a pound sign, then 2 hex digits for red, 2 for green, and 2 for blue.
This is very easy to convert between.
First let's get rid of the # sign
color = color[1:]
Next let's separate these into 3 different strings.
red = color[0:2]
green = color[2:4]
blue = color[4:6]

Next let's convert these all to integers
red = int(red, 16)
green = int(green, 16)
blue = int(blue, 16)

I'll leave it as an exercise for the reader to simplify this (I.E. I 
have food on the stove and I have to go take it off.)

HTH,
-Luke


[pygame] Is there some type of hex codes to rgb converter or something?

2007-09-10 Thread Lamonte Harris
I like using HTML hex, is there a library or something on pygame or python
it self to convert hex to rgb