アプリ開発コース 3
◆Slack アニメ絵文字作成
Step 1. スクリーンショットの出力
code:cpp
# include <Siv3D.hpp>
void Main()
{
// ウィンドウを正方形に
Window::Resize(128, 128);
Graphics::SetBackground(ColorF(1.0, 1.0, 1.0));
const Font font(60, Typeface::Bold);
while (System::Update())
{
// 次の System::Update() で現在のフレームのスクリーンキャプチャを作成
ScreenCapture::RequestCurrentFrame();
// 新しいスクリーンキャプチャがあれば
if (ScreenCapture::HasNewFrame())
{
// 取得して保存
ScreenCapture::GetFrame().save(U"emoji.png");
// メインループを抜けて終了
break;
}
//////
//
// 描画
//
font(U"尊い").drawAt(64, 64, Palette::Red);
//
//
//////
}
}
Step 2. GIF アニメーションの出力
スクリーンショットを AnimatedGIFWriter に追加していくと GIF アニメーションを作れる
Slack Emoji の 64KB 制限に注意
code:cpp
# include <Siv3D.hpp>
void Main()
{
Window::Resize(128, 128);
Graphics::SetBackground(ColorF(1.0, 1.0, 1.0));
const Font font(60, Typeface::Bold);
// GIF アニメ出力クラス
AnimatedGIFWriter gif(U"emoji.gif", 64, 64);
int32 i = 0;
while (System::Update())
{
ScreenCapture::RequestCurrentFrame();
if (ScreenCapture::HasNewFrame())
{
// 取得して (64x64) に縮小し、GIF アニメのフレームとして書き出し
// 0.1 秒の間隔
gif.writeFrame(ScreenCapture::GetFrame().scaled(64, 64), 0.1s);
// 20 フレームの書き出しで終了
if (++i >= 20)
{
break;
}
}
//////
//
// 描画
//
// (64, 64) を中心に回転する座標変換を適用
Transformer2D transform(Mat3x2::Rotate(-18_deg * i, Vec2(64, 64)));
font(U"尊い").drawAt(64, 64, Palette::Red);
//
//
//////
}
}
Step 3. 応用
いい感じの文章や絵文字や画像やアニメーションを使う
色を変えてみる