Last active
February 3, 2019 07:41
-
-
Save falrnd/90e66137b4e2355cdab51b4cad7784f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// OpenSiv3D 0.3.1 | |
# include <Siv3D.hpp> | |
namespace fal::rnd { | |
template<class T = void> | |
struct Rnd { | |
using value_type = T; | |
Rnd(const T& from, const T& to) : f(from), t(to) {} | |
Rnd() = delete; | |
T f, t; | |
}; | |
template<> | |
struct Rnd<void> {}; | |
using All = Rnd<void>; | |
template<class V, class W, class X> | |
constexpr auto num(const V& v, const W& from, const X& to) { | |
return Clamp(v, from, to); | |
} | |
template<class V, class W, class X> | |
auto num(const Rnd<V>& v, const W& from, const X& to) { | |
if constexpr (std::is_same_v<Rnd<V>, All>) | |
return Random(from, to); | |
else | |
return Random(Max(v.f, from), Min(v.t, to)); | |
} | |
} | |
using namespace fal::rnd; | |
template<class A, class B> | |
auto f(const A& x, const B& y) { | |
return Circle(num(x, 0, 320), num(y, 0, 240), 5); | |
} | |
void Main() { | |
Window::Resize(320, 240); | |
while (System::Update()) { | |
f(200, 200).draw(); | |
f(Rnd(100, 150), Rnd(100, 150)).draw(Palette::Pink); | |
f(Rnd(), Rnd()).draw(Palette::Red); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment