Play Siv3D!

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

2D 図形の変形

2D 図形の変形

Siv3D June 2015 v2

三角形を回転させる

# include <Siv3D.hpp>

void Main()
{
	const Triangle triangle1(320, 240, 200);

	const Triangle triangle2(320, 400, 80);

	const Triangle triangle3(320, 60, 80);

	TimerMillisec timer;

	timer.start();

	while (System::Update())
	{
		const double t = timer.elapsed() / 1000.0;

		triangle1.rotated(t).draw();

		triangle2.rotatedAt(320, 240, t).draw(Palette::Orange);

		triangle3.rotated(t).rotatedAt(320, 240, t).draw(Palette::Skyblue);
	}
}


長方形を拡大縮小する

# include <Siv3D.hpp>

void Main()
{
	const Rect rect = Rect(300, 200).setCenter(Window::Center());

	while (System::Update())
	{
		rect.stretched(40, 30, 20, 10).draw(Palette::Skyblue);

		rect.draw();

		rect.stretched(-20).draw(Palette::Orange);
	}
}


長方形を回転させる
Rect::rotated() は長方形の中心を軸に、指定した角度だけ時計回りに回転させた Quad を返します。
Rect::rotatedAt() は指定した座標を軸に、指定した角度だけ時計回りに回転させた Quad を返します。

# include <Siv3D.hpp>

void Main()
{
	const Rect rect(200, 200, 300, 100);

	while (System::Update())
	{
		rect.draw();

		rect.rotated(Radians(30)).draw(Palette::Orange);

		rect.rotatedAt(rect.pos, Radians(45)).draw(Palette::Yellowgreen);
	}
}


円を拡大縮小する

# include <Siv3D.hpp>

void Main()
{
	const Circle circle(Window::Center(), 100);

	while (System::Update())
	{
		circle.scaled(1.5).draw(Palette::Orange);

		circle.draw();

		circle.stretched(-20).draw(Palette::Yellowgreen);
	}
}


楕円を拡大縮小する

# include <Siv3D.hpp>

void Main()
{
	const Ellipse ellipse(Window::Center(), 200, 100);

	while (System::Update())
	{
		ellipse.stretched(50).draw(Palette::Orange);

		ellipse.draw();

		ellipse.stretched(-20).draw(Palette::Yellowgreen);
	}
}


角丸長方形を拡大縮小する

# include <Siv3D.hpp>

void Main()
{
	const RoundRect rect = RoundRect(Rect(300, 200).setCenter(Window::Center()), 40);

	while (System::Update())
	{
		rect.stretched(60, 20).draw(Palette::Orange);

		rect.draw();

		rect.stretched(-20).draw(Palette::Yellowgreen);
	}
}


多角形を拡大縮小する

# include <Siv3D.hpp>

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

	while (System::Update())
	{
		star.scaled(1.5).draw(Window::Center(), Palette::Orange);

		star.draw(Window::Center());
	}
}


多角形を回転させる

# include <Siv3D.hpp>

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

	while (System::Update())
	{
		star.rotated(Radians(30)).draw(Window::Center(), Palette::Orange);

		star.draw(Window::Center());

		star.rotatedAt({ 100, 100 }, Radians(30)).draw(Window::Center(), Palette::Yellowgreen);
	}
}