揺れ動く画像
https://scrapbox.io/files/668fdd33a76d29001d874537.mp4
code:swinging_texture.cpp
# include <Siv3D.hpp> // Siv3D v0.6.15
Quad DrawSwingingTexture(const Texture& texture, const Vec2& bottomCenter, double swingAngle = 0.0, const ColorF& color = Palette::White)
{
const SizeF quadSize = texture.size();
const Vec2 bottomLeft = bottomCenter + Vec2{ -quadSize.x / 2, 0 };
const Vec2 bottomRight = bottomCenter + Vec2{ quadSize.x / 2, 0 };
const OffsetCircular topCenter{ bottomCenter, Arg::r = quadSize.y, Arg::theta = swingAngle };
const OffsetCircular topLeft{ topCenter, Arg::r = quadSize.x / 2, Arg::theta = -90_deg + swingAngle };
const OffsetCircular topRight{ topCenter, Arg::r = quadSize.x / 2, Arg::theta = 90_deg + swingAngle };
return Quad{ topLeft, topRight, bottomRight, bottomLeft }(texture).draw(color);
}
void Main()
{
Scene::SetBackground(ColorF{ 0.6, 0.8, 0.7 });
const Texture texture{ U"example/siv3d-kun.png" };
Timer timer{ 0.5s, StartImmediately::Yes };
timer.setRemaining(0s);
while (System::Update())
{
const Quad quad = DrawSwingingTexture(
texture,
Scene::CenterF() + Vec2{ 0, texture.height() / 2 },
Periodic::Sine1_1(0.2s) * 30_deg * EaseInSine(timer.progress1_0()),
Palette::Magenta.lerp(Palette::White, EaseOutCubic(timer.progress0_1())));
if (quad.leftClicked() && not timer.isRunning())
{
timer.restart();
}
}
}
https://gyazo.com/5351dfefca10c26e173e7cc71ee54d4d