4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

sinとcosだけで実現するよさげな背景

Last updated at Posted at 2022-12-09

はじめに

この記事は長野高専 Advent Calender 2022 9日目の記事です。

自分でもなんでそうなるかよくわからないけどいい感じの背景を共有します。

背景はこれ↓

コード

Siv3Dで書いたサンプルです。

main.cpp
# include <Siv3D.hpp> // OpenSiv3D v0.6.5

void Main()
{
	// 背景の色を設定 | Set background color
	Scene::SetBackground(ColorF{ 0.8, 0.9, 1.0 });

	while (System::Update())
	{
		for (double x : step(Scene::Width() / 5))
		{
			for (double y : step(Scene::Height() / 5))
			{
				int xd = x * 5;
				int yd = y * 5;
				double si = sin(y * y + x / y - Scene::Time() * 7.0);
				double co = cos(pow(y, 5) - x / y * 9.0 + Scene::Time());
				double cop = pow(co, 3);
				double width = (si + cop) * y / 15.0;
				RectF rect = RectF{ Arg::center(Vec2(xd, yd)), width, 5};
				rect.draw(ColorF(1, 0.75));
			}
		}
	}
}

説明

次の式で与えられる幅の四角形を画面全体に描画しているだけです。
i, jはそれぞれ四角形のx座標, y座標を、tは経過時間を表しています。

\left\{\sin\left(j\times j+\frac{i}{j}-t\times7\right)+\left(\cos\left(j^5-\frac{i}{j}\times6+t\right)\right)^3\right\}*\frac{j}{15}

見ての通り、sinとcosだけで実現できます。
なんで?

参考文献

95 by yonatan | Dwitter

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?