Play Siv3D!

ゲームとメディアアートのための C++ ライブラリ「Siv3D」

HSV カラー

HSV カラー

Siv3D June 2015 v2

HSV カラー

# include <Siv3D.hpp>

void Main()
{
	GUI gui(GUIStyle::Default);

	gui.add(GUIText::Create(L"H", 15));
	gui.add(L"h", GUISlider::Create(0, 360, 120, 360));
	gui.addln(L"h", GUIText::Create(L"120", 40));

	gui.add(GUIText::Create(L"S", 15));
	gui.add(L"s", GUISlider::Create(0.0, 1.0, 0.6, 360));
	gui.addln(L"s", GUIText::Create(L"0.6", 40));

	gui.add(GUIText::Create(L"V", 15));
	gui.add(L"v", GUISlider::Create(0.0, 1.0, 0.6, 360));
	gui.addln(L"v", GUIText::Create(L"0.6", 40));

	while (System::Update())
	{
		const double h = gui.slider(L"h").value;
		const double s = gui.slider(L"s").value;
		const double v = gui.slider(L"v").value;

		gui.text(L"h").text = Format(DecimalPlace(0), h);
		gui.text(L"s").text = Format(DecimalPlace(2), s);
		gui.text(L"v").text = Format(DecimalPlace(2), v);

		Graphics::SetBackground(HSV(h, s, v));
	}
}


RGB への変換

# include <Siv3D.hpp>

void Main()
{
	while (System::Update())
	{
		Rect(640, 240).draw();

		Circle(120, 240, 100).draw(HSV(200, 0.8, 1.0));

		Circle(320, 240, 100).draw(HSV(200, 0.8, 1.0).toColor(127));

		Circle(520, 240, 100).draw(HSV(200, 0.8, 1.0).toColorF(0.8));
	}
}


色の計算

# include <Siv3D.hpp>

void Main()
{
	const Color color(40, 200, 120);

	while (System::Update())
	{
		Circle(120, 240, 100).draw(color);

		Circle(320, 240, 100).draw(color + HSV(20, 0, 0));

		Circle(520, 240, 100).draw(color + HSV(0, 0, 0.3));
	}
}