Color3データ型

データ型日本語解説あり

ひとことで言うと

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

公式の説明(英語):A color value comprised of red, green, and blue components.

使用例

クリックで色が変わるパーツ
Script置く場所:パーツの中
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)

スクリプトは、Luauの型チェック(luau-lsp)で確認しています。

コンストラクター(作り方)(4)

名前と書き方説明
new
Color3.new(red: number, green: number, blue: number)
赤・緑・青を0〜1で指定して色を作ります。Returns a Color3 with the given red, green, and blue values.
fromRGB
Color3.fromRGB(red: number, green: number, blue: number)
赤・緑・青を0〜255で指定して色を作ります。Returns a Color3 from given components within the range of 0 to 255.
fromHSV
Color3.fromHSV(hue: number, saturation: number, value: number)
色相・彩度・明度から色を作ります。Returns a Color3 from the given hue, saturation, and value components.
fromHex
Color3.fromHex(hex: string)
Returns a Color3 from a given hex value.

プロパティ(3)

名前と書き方説明
R
Color3.R: number
The red value of the color.
G
Color3.G: number
The green value of the color.
B
Color3.B: number
The blue value of the color.

メソッド(6)

名前と書き方説明
Lerp
Color3:Lerp(color: Color3, alpha: number): Color3
2つの色のあいだの色を作ります。Returns a Color3 interpolated between two colors.
ToHSV
Color3:ToHSV(): number, number, number
Returns the hue, saturation, and value of a Color3.
ToHex
Color3:ToHex(): string
Returns the hex code of a Color3.
GetLuminance
Color3:GetLuminance(): number
Returns the relative luminance of a Color3.
GetContrastRatio
Color3:GetContrastRatio(other: Color3): number
Returns the WCAG contrast ratio between a Color3 and another color.
GetContrastingColor
Color3:GetContrastingColor(...: Color3): Color3
Returns whichever candidate color has the highest contrast against a Color3.

Color3を使う記事

英語の説明とメンバーの一覧は、Roblox Creator Documentation(Color3)をもとにしています(CC BY 4.0)。日本語の解説は、このサイトで独自に書いたものです。

執筆:鈴木孝昌官公庁のWeb・システム開発を担当する現役プロジェクトマネージャー。沖縄マイクラ部 クロスウェーブで、ロブロックス(Roblox)・マインクラフト(マイクラ)・Scratchなどのプログラミングを指導。マイクラカップ沖縄代表チームを指導(第6回・第7回、第7回TBS賞)。
沖縄マイクラ部で、子どもたちにロブロックス(Roblox)やマインクラフト(マイクラ)のプログラミングを教えています。プロフィールと編集方針
Instagramで教室の様子を見る
noteで記事を読む