Category:LSL Color/ja

From Second Life Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.


Color in LSL

Color in LSL

LSLは自身が特別な色の形式を持っています。LSLは色の記憶にvectorを使用します。伝統的なRGB各チャンネルの0から255のようなものではなく、LSLのカラーチャンネルは0から1です。

形式: <R, G, B>

• float x Red value [0, 1]
• float y Green value [0, 1]
• float z Blue value [0, 1]

サンプル

vector white = <1.0, 1.0, 1.0>;
vector grey = <0.5, 0.5, 0.5>;
vector black = <0.0, 0.0, 0.0>;
vector red = <1.0, 0.0, 0.0>;
vector green = <0.0, 1.0, 0.0>;
vector blue = <0.0, 0.0, 1.0>;
vector yellow = <1.0, 1.0, 0.0>;
vector cyan = <0.0, 1.0, 1.0>;
vector magenta = <1.0, 0.0, 1.0>;

便利なスニペット

色とアルファを(から)integerへ(に)記憶(回収)するための応用しやすい関数です

integer ColorAlphatoRGBA(vector color, float alpha) {
	return (((integer)(alpha * 255.0) & 0xFF) << 24) |
		(((integer)(color.x * 255.0) & 0xFF) << 16) |
		(((integer)(color.y * 255.0) & 0xFF) << 8) |
		((integer)(color.z * 255.0) & 0xFF);
}

vector RGBAtoColor(integer rgba) {
	return < ((rgba >> 16) & 0xFF) / 255.0, ((rgba >> 8) & 0xFF) / 255.0, (rgba & 0xFF) / 255.0 >;
}

float RGBAtoAlpha(integer rgba) {
	return ((rgba >> 24) & 0xFF) / 255.0;
}