Play Siv3D!

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

2D 図形の特殊効果

2D 図形の特殊効果

Siv3D June 2015 v2

長方形の影を描く

# include <Siv3D.hpp>

void Main()
{
	Graphics::SetBackground(Color(160, 200, 100));

	const Rect rect(200, 100, 300, 200);

	while (System::Update())
	{
		rect.drawShadow({ 0, 0 }, 24.0, 2.0);

		rect.draw(Palette::Orange);
	}
}


円の影を描く

# include <Siv3D.hpp>

void Main()
{
	Graphics::SetBackground(Color(160, 200, 100));

	const Circle circle(320, 240, 160);

	while (System::Update())
	{
		circle.drawShadow({ 0, 0 }, 24.0, 2.0);

		circle.draw(Palette::Orange);
	}
}


角丸長方形の影を描く

# include <Siv3D.hpp>

void Main()
{
	Graphics::SetBackground(Color(160, 200, 100));

	const RoundRect rect({ 200, 100, 300, 200 }, 30);

	while (System::Update())
	{
		rect.drawShadow({ 0, 0 }, 24.0, 2.0);

		rect.draw(Palette::Orange);
	}
}


任意の図形の影を描く

ぼかし範囲を考慮したサイズの Image に図形を書き込み、ガウスぼかしをかけたものを影テクスチャとして使います。

# include <Siv3D.hpp>

void Main()
{
	Graphics::SetBackground(Color(160, 200, 100));

	const Polygon star = Geometry2D::CreateStar(150, 0.0);

	Image image(360, 360, Color(255, 0));

	const Point offset(image.size / 2);

	star.movedBy(offset).overwrite(image, Color(255));

	const Texture shadowTexture(image.gaussianBlurred(24, 24));

	while (System::Update())
	{
		const Point pos = Mouse::Pos();

		shadowTexture.draw(pos + Point(8, 8) - offset, ColorF(0.0, 0.5));

		star.draw(pos, Palette::Yellow);
	}
}


グラデーションのある線分を描く

# include <Siv3D.hpp>

void Main()
{
	while (System::Update())
	{
		Line(50, 400, 600, 50).draw({ Palette::Yellow, Palette::Red });

		Line(50, 200, 600, 250).draw(25, { Color(0, 100, 200), Color(0, 100, 200, 0) });
	}
}


グラデーションのある三角形を描く

# include <Siv3D.hpp>

void Main()
{
	while (System::Update())
	{
		Triangle({ 50, 50 }, { 600, 400 }, { 100, 400 })
			.draw({ Color(255, 0, 0), Color(0, 255, 0), Color(0, 0, 255) });
	}
}


グラデーションのある長方形を描く

# include <Siv3D.hpp>

void Main()
{
	while (System::Update())
	{
		Rect(100, 100, 400, 100)
			.draw({ Palette::Red, Palette::Red, Palette::Yellow, Palette::Yellow });

		Rect(100, 250, 400, 100)
			.draw({ Palette::White, Palette::Blue, Palette::Blue, Palette::White });
	}
}


グラデーションのある四角形を描く

# include <Siv3D.hpp>

void Main()
{
	while (System::Update())
	{
		Quad(100, 100, 400, 100, 500, 200, 100, 200)
			.draw({ Palette::Red, Palette::Red, Palette::Yellow, Palette::Yellow });

		Rect(100, 250, 400, 100)
			.rotated(Radians(10))
			.draw({ Palette::White, Palette::Blue, Palette::Blue, Palette::White });
	}
}