Colorクラスの色彩情報はRGBA形式で表され、(赤,緑,青,透明度)といった色を構成する各値を0から255までの数字を使って設定します。新しい色を作成するための基本的な計算処理を行え、HSVやHSLのような他のカラー形式への変換もサーポートしており、(赤,緑,青,透明度)値の調整だけで色の作成ができます。 透明度が設定されていない場合は、255が既定値として設定されます。
RGB形式の色彩情報は 、HTMLで使用されるような文字列で指定する形式と 数字で指定する形式のどちらかで設定することができます。 HTML 形式とは '#rrggbbaa'というように 赤(rr)、緑(gg)、青( bb)、透明度(aa)を2桁の16進数で表記するものです。透明度の指定は任意で行います。Colorクラスにおいて文字列で色を設定する場合には'0xrrggbbaa'という書式で表記し、透明度(aa)部分については任意で設定します。
Colorクラスによって作成された色は、他の色と色彩情報(赤,緑,青,設定している場合は透明度も)の各数値を比較し、同じ色かどうか調べることができます (ver1.9.0にて追加された機能)。以前、pygameのバージョン1.8.1にて透明度の既定値が255ではなく0として設定されているバグがありました。
Colorクラスはpygame 1.8.1から新しく実装されたものです。
The Color class represents RGBA color values using a value range of 0-255. It allows basic arithmetic operations to create new colors, supports conversions to other color spaces such as HSV or HSL and lets you adjust single color channels. Alpha defaults to 255 when not given.
'rgbvalue' can be either a color name, an HTML color format string, a hex number string, or an integer pixel value. The HTML format is '#rrggbbaa', where rr, gg, bb, and aa are 2 digit hex numbers. The alpha aa is optional. A hex number string has the form '0xrrggbbaa', where aa is optional.
Color objects support equality comparison with other color objects and 3 or 4 element tuples of integers (New in 1.9.0). There was a bug in pygame 1.8.1 where the default alpha was 0, not 255 like previously.
New implementation of Color was done in pygame 1.8.1.
赤の輝度。
The red value of the Color.
緑の輝度。
The green value of the Color.
青の輝度。
The blue value of the Color.
透明度
The alpha value of the Color.
CMY形式の色彩情報です。 CMYの構成値はシアン(c)、マゼンタ(m)、イエロー(y)の三つがあり、0から1の範囲内で値が設定できます。注意してほしいのですが、CMY形式で色彩情報を取得した時、RGB形式で設定した色彩情報と完全に同じものが取得できるわけではありません。RGB形式は0から255の範囲内で値を設定し、CMY形式は0から1の範囲内で値を設定するため、丸め誤差によって想定したものとは少し違うCMY形式の色彩情報 になってしまいます。
The CMY representation of the Color. The CMY components are in the ranges C = [0, 1], M = [0, 1], Y = [0, 1]. Note that this will not return the absolutely exact CMY values for the set RGB values in all cases. Due to the RGB mapping from 0-255 and the CMY mapping from 0-1 rounding errors may cause the CMY values to differ slightly from what you might expect.
HSVA形式の色彩情報です。HSVAの構成値は色相(H)、彩度(S)、明度(V)、透明度(A)の四つがあり 、色相は0から360の範囲内で値が設定でき、他の三つは0から10の範囲内で値が設定できます。注意してほしいのですが、HSVA形式で色彩情報を取得した時、RGB形式で設定した色彩情報と完全に同じものが取得できるわけではありません。RGB形式は0から255の範囲内で値を設定し、HSVA形式は0から100、もしくは0から360の範囲内で値を設定するため、 丸め誤差によって想定したものとは少し違うHSVA形式の色彩情報になってしまいます。
The HSVA representation of the Color. The HSVA components are in the ranges H = [0, 360], S = [0, 100], V = [0, 100], A = [0, 100]. Note that this will not return the absolutely exact HSV values for the set RGB values in all cases. Due to the RGB mapping from 0-255 and the HSV mapping from 0-100 and 0-360 rounding errors may cause the HSV values to differ slightly from what you might expect.
HSLA形式の色彩情報です。HSLAの構成値は色相(H)、彩度(S)、輝度(L)、透明度(A)の四つがあり、色相は0から360の範囲内で値が設定でき、他の三つは0から10の範囲内で値が設定できます。注意してほしいのですが、HSLA形式で色彩情報を取得した時、RGB形式で設定した色彩情報と完全に同じものが取得できるわけではありません。RGB形式は0から255の範囲内で値を設定し、HSLA形式は0から100、もしくは0から360の範囲内で値を設定するため、 丸め誤差によって想定したものとは少し違うHSLA形式の色彩情報になってしまいます。
※原文にはV = [0, 100]と表記されていますが、間違いの可能性があるのでその部分をL = [0, 100]と読み替えて訳しています。
The HSLA representation of the Color. The HSLA components are in the ranges H = [0, 360], S = [0, 100], V = [0, 100], A = [0, 100]. Note that this will not return the absolutely exact HSL values for the set RGB values in all cases. Due to the RGB mapping from 0-255 and the HSL mapping from 0-100 and 0-360 rounding errors may cause the HSL values to differ slightly from what you might expect.
I1I2I3形式の色彩情報です。I1I2I3の構成値はI1、I2、I3の三つがあり、I1は0から1の範囲内で値を設定でき、 I2とI3は-0.5から0.5の範囲内で値を設定できます。 注意してほしいのですが、I1I2I3形式で色彩情報を取得した時、RGB形式で設定した色彩情報と完全に同じものが取得できるわけではありません。RGB形式は0から255の範囲内で値を設定し、I1I2I3形式は0から1、もしくは-0.5から0.5の範囲内で値を設定するため、丸め誤差によって想定したものとは少し違うI1I2I3形式の色彩情報になってしまいます。
※原文にはI1I2I3 mapping from 0-1とのみ表記されていますが、間違いの可能性があるのでその部分をI1I2I3 mapping from 0-1 and -0.5-0.5読み換えて訳しています。
The I1I2I3 representation of the Color. The I1I2I3 components are in the ranges I1 = [0, 1], I2 = [-0.5, 0.5], I3 = [-0.5, 0.5]. Note that this will not return the absolutely exact I1I2I3 values for the set RGB values in all cases. Due to the RGB mapping from 0-255 and the I1I2I3 mapping from 0-1 rounding errors may cause the I1I2I3 values to differ slightly from what you might expect.
浮動小数点数として正規化されたRGBA形式の色彩情報を取得します。
Returns the normalized RGBA values of the Color as floating point values.
色彩情報にガンマ値を設定し、それによって変更された新しい RGBA形式の色彩情報が取得できます。
Applies a certain gamma value to the Color and returns a new Color with the adjusted RGBA values.
色の構成要素は既定では4個となっています。要素数は1から4の範囲内で変更することができます。これは(赤、緑、青、透明度)の要素うち、(赤、緑、青)だけを操作したい時に便利です。色の要素数を調べたいときはlen()命令を使ってlen(調べたい色) とすることで調べられます。
The default Color length is 4. Colors can have lengths 1,2,3 or 4. This is useful if you want to unpack to r,g,b and not r,g,b,a. If you want to get the length of a Color do len(acolor).