Skip to content

Instantly share code, notes, and snippets.

@voidproc
Created September 24, 2021 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save voidproc/f439389981aae5537d9b6a64020755f3 to your computer and use it in GitHub Desktop.
Save voidproc/f439389981aae5537d9b6a64020755f3 to your computer and use it in GitHub Desktop.
SimpleAnimationを視る
# include <Siv3D.hpp> // OpenSiv3D v0.6.0
void Main()
{
Scene::SetBackground(ColorF{ 0, 0, 0 });
Font font{ 16 };
SimpleAnimation anim;
anim.setLoop(5s)
.set(U"value", { 0s, 0 }, { 2s, 0.5 }, EaseInOutCubic)
.set(U"value", { 2.5s, 0.5 }, { 3.5s, 1.0 }, EaseInOutSine)
.set(U"value", { 3.75s, 1.0 }, { 4.99s, 0 }, EaseInOutCubic)
.start();
while (System::Update())
{
const SizeF graphSize{ 300, 300 };
const Vec2 graphPos = Scene::Size() / 2 - graphSize / 2;
RectF{ graphPos, graphSize }.drawFrame();
const double x = anim.posSec() / 5.0 * graphSize.x + graphPos.x;
const double y = (1.0 - anim[U"value"]) * graphSize.y + graphPos.y;
Line{ x, graphPos.y, x, graphPos.y + graphSize.y }.draw(LineStyle::SquareDot, 1);
Line{ graphPos.x, y, graphPos.x + graphSize.x, y }.draw(LineStyle::SquareDot, 1);
font(U"{:.1f}"_fmt(anim.posSec())).drawAt(x, graphPos.y + graphSize.y + 16);
font(U"{:.1f}"_fmt(anim[U"value"])).drawAt(graphPos.x - 24, y);
Circle{ Vec2{ x, y }, 10 }.draw();
}
}
@voidproc
Copy link
Author

17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment