Created
July 2, 2018 14:21
-
-
Save sknjpn/454a57ceb0254acad14a4a6654d720f1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# include <Siv3D.hpp> // OpenSiv3D v0.2.7 | |
class WatchfulEye | |
{ | |
Vec2 m_position; | |
Vec2 m_aimed; | |
Vec2 m_target; | |
double m_degree; | |
double m_timer; | |
double m_size; | |
public: | |
WatchfulEye(const Vec2& position, double size) | |
: m_size(size) | |
, m_position(position) | |
, m_degree(0.5) | |
, m_aimed(0.0, 0.0) | |
, m_target(0.0, 0.0) | |
, m_timer(0.0) | |
{} | |
void update() | |
{ | |
auto base = Circle(m_position, m_size / 2.0).asPolygon(); | |
m_degree += Min(Max(m_timer - m_degree, -0.025), 0.025); | |
if (m_degree == m_timer) | |
{ | |
if (RandomBool(0.005)) { m_timer = 0.5; } | |
if (RandomBool(0.0025)) { m_timer = 0.0; } | |
if (RandomBool(0.00125)) { m_timer = 0.75; } | |
} | |
if (RandomBool(0.01)) { m_target = RandomVec2(Random(m_size / 12.0)); } | |
if ((m_target - m_aimed).length() > 1.0) { m_aimed += (m_target - m_aimed).setLength(m_size / 128.0); } | |
base.draw(Palette::White); | |
{ | |
Array<Vec2> points; | |
for (double t = 0.0; t < Math::TwoPi; t += 0.1) | |
{ | |
points.emplace_back((Vec2(cos(t), sin(t) * m_degree) * m_size / 8.0).movedBy(-m_size / 4.0, 0.0).movedBy(m_position)); | |
} | |
base.addHole(points); | |
points.clear(); | |
for (double t = 0.0; t < Math::TwoPi; t += 0.1) | |
{ | |
points.emplace_back((Vec2(cos(t), sin(t) * m_degree) * m_size / 8.0).movedBy(+m_size / 4.0, 0.0).movedBy(m_position)); | |
} | |
base.addHole(points); | |
} | |
Circle(m_position, m_size / 12.0).movedBy(m_aimed).movedBy(-m_size / 4.0, 0.0).draw(Palette::Darkred); | |
Circle(m_position, m_size / 18.0).movedBy(m_aimed).movedBy(-m_size / 4.0, 0.0).draw(Palette::Red); | |
Circle(m_position, m_size / 12.0).movedBy(m_aimed).movedBy(+m_size / 4.0, 0.0).draw(Palette::Darkred); | |
Circle(m_position, m_size / 18.0).movedBy(m_aimed).movedBy(+m_size / 4.0, 0.0).draw(Palette::Red); | |
base.draw(Color(11, 22, 33)); | |
} | |
bool intersects(const Circle& circle) const { return Circle(m_position, m_size / 2.0).intersects(circle); } | |
}; | |
void Main() | |
{ | |
Graphics::SetBackground(Color(11, 22, 33)); | |
Array<WatchfulEye> eyes; | |
for (int i = 0; i < 128; i++) | |
{ | |
auto p = RandomVec2(Window::ClientRect()); | |
auto s = Random(64, 128); | |
if (!eyes.any([&p, &s](const WatchfulEye& e) { return e.intersects(Circle(p, s)); })) { eyes.emplace_back(p, s); } | |
} | |
while (System::Update()) | |
{ | |
for (auto& e : eyes) { e.update(); } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment