Skip to content

Instantly share code, notes, and snippets.

@voidproc
Last active June 6, 2017 16:13
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/939f70b67c821c4a05915b328d43a51b to your computer and use it in GitHub Desktop.
Save voidproc/939f70b67c821c4a05915b328d43a51b to your computer and use it in GitHub Desktop.
opensiv3d glyph
# include <Siv3D.hpp>
void Main()
{
Graphics::SetBackground(Color(240));
const Font font(50, Typeface::Bold);
const String text = L"Glyph in Siv3D 🐣";
const RectF region = font(text).regionAt(Window::Center());
const auto g2 = font.getGlyph(U'2');
while (System::Update())
{
const double t = Min(1.0, System::FrameCount() / 50.0);
Vec2 pos{ region.tl() };
for (const auto& g : font(text))
{
if (g.codePoint == U'🐣')
{
g.texture.draw(pos + g.offset + Vec2{ 0, 500 * EaseInOut(Easing::Back, 1.0 - t) }, Color(48));
}
else if (g.codePoint == U'G')
{
g.texture.draw(pos + g.offset + RandomVec2(200.0 * (1.0 - t)), Color(48));
}
else if (g.codePoint == U'S')
{
g.texture.draw(pos + g.offset - Vec2{ 0, 1000 * EaseIn(Easing::Cubic, 1.0 - t) }, Color(48));
}
else if (g.codePoint == U'3' && t < 1.0)
{
g2.texture.draw(pos + g2.offset, Color(48, 255 * ((System::FrameCount() / 3) % 2)));
pos.x += g2.xAdvance;
continue;
}
else if (g.codePoint == U'D')
{
const double ratio = cos(Math::TwoPi * t * 4);
g.texture.scale(ratio, 1.0).draw(pos + g.offset + Vec2(g.xAdvance * (1 - ratio) / 2, 0), Color(48));
}
else
{
g.texture.draw(pos + g.offset, Color(48));
}
pos.x += g.xAdvance;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment