/* jquery */ /* jquery accordion style*/ /* jquery init */

22 June 2013

Learn Python - PyGame Colours

There's a number of ways to specify colours in PyGame. So, it's worth examining the options available.

Arguably the simplest option is to specify basic colours is by name, as here:

backgroundCol = pygame.Color('black')
textCol = pygame.Color('white')
lineCol = pygame.Color('magenta')

However, assigning a name (and recalling that name) for every possible colour isn't practical. So, a more flexibility solution is to use RGB colour values.

Here's an example:

backgroundCol = [0,0,0]
textCol = [255,255,255]
lineCol = [255,100,100]

The three numbers relate to the red, green and blue components of a colour. As each RGB number ranges from 0 to 255, the total number of RGB colour combinations is 256 x 256 x 256, or over 16 million.

Setting a value of [0,0,0] means no red, green or blue colour. So the backgroundCol setting will be black. To define white we'd need to set all three colours to their maximum value, namely [255,255,255], as in the textCol variable. While the lineCol variable has pinkish colour value due to the dominance of red.

A post from my Learn Python on the Raspberry Pi tutorial.