# Color3（ロブロックス データ型）

> 赤・緑・青の3つの値で色を表すデータ型です。Color3.fromRGB(255, 0, 0) のように、0〜255の数で作るのが分かりやすい方法です。

- URL：https://roblox.minecraft-okinawa.com/reference/datatypes/Color3/
- 公式：https://create.roblox.com/docs/reference/engine/datatypes/Color3

## 使用例：クリックで色が変わるパーツ

（Script／置く場所：パーツの中）

```lua
local part = script.Parent :: BasePart
local clickDetector = Instance.new("ClickDetector")
clickDetector.Parent = part

clickDetector.MouseClick:Connect(function()
	part.Color = Color3.fromRGB(math.random(0, 255), math.random(0, 255), math.random(0, 255))
end)
```

## コンストラクター

- `Color3.new(red: number, green: number, blue: number)`：赤・緑・青を0〜1で指定して色を作ります。
- `Color3.fromRGB(red: number, green: number, blue: number)`：赤・緑・青を0〜255で指定して色を作ります。
- `Color3.fromHSV(hue: number, saturation: number, value: number)`：色相・彩度・明度から色を作ります。
- `Color3.fromHex(hex: string)`：Returns a Color3 from a given hex value.

## プロパティ

- `Color3.R: number`：The red value of the color.
- `Color3.G: number`：The green value of the color.
- `Color3.B: number`：The blue value of the color.

## メソッド

- `Color3:Lerp(color: Color3, alpha: number): Color3`：2つの色のあいだの色を作ります。
- `Color3:ToHSV(): number, number, number`：Returns the hue, saturation, and value of a Color3.
- `Color3:ToHex(): string`：Returns the hex code of a Color3.
- `Color3:GetLuminance(): number`：Returns the relative luminance of a Color3.
- `Color3:GetContrastRatio(other: Color3): number`：Returns the WCAG contrast ratio between a Color3 and another color.
- `Color3:GetContrastingColor(...: Color3): Color3`：Returns whichever candidate color has the highest contrast against a Color3.

英語の説明とメンバー一覧：Roblox Creator Documentation（CC BY 4.0）。日本語の解説はこのサイト独自のものです。

執筆：鈴木孝昌（現役プロジェクトマネージャー／プログラミング講師）／運営：沖縄マイクラ部 プログラミングスクール「クロスウェーブ」（https://minecraft-okinawa.com/）