CurlNoise
https://gyazo.com/8a5d98a1e24b566c989ba2b7b915a92b
説明
PerlinNoiseを使って流体っぽい動きをするCurlNoiseクラスを作りました。
code:Main.cpp
class CurlNoise
{
private:
PerlinNoise perlin{ RandomUint32() };
const double delta = 0.1;
const double scale = 128.0;
public:
CurlNoise()
{}
Vec2 noise2D(double x, double y, int32 octave = 1)
{
double dx = perlin.normalizedOctave2D((x + delta) / scale, y / scale, octave) -
perlin.normalizedOctave2D((x - delta) / scale, y / scale, octave);
double dy = perlin.normalizedOctave2D(x / scale, (y + delta) / scale, octave) -
perlin.normalizedOctave2D(x / scale, (y - delta) / scale, octave);
return Vec2(dy, -dx) / delta;
}
Vec2 noise2D(Vec2 pos, int32 octave = 1)
{
return noise2D(pos.x, pos.y, octave);
}
};
void Main()
{
Scene::SetBackground(Palette::Black);
CurlNoise curl;
Array<Vec2> particles(300);
for (auto& particle : particles)
{
particle = RandomVec2(Scene::Rect());
}
while (System::Update())
{
for (auto& particle : particles)
{
Vec2 force = curl.noise2D(particle);
particle += force * 10000 * Scene::DeltaTime();
// 画面の範囲内に留める
if (!Scene::Rect().contains(particle))
{
particle = RandomVec2(Scene::Rect());
}
Circle(particle, 2).draw(Palette::White);
}
}
}
作者
たのれん