Created
December 24, 2024 03:39
-
-
Save sthairno/a01b24097ada2b9a53fd1be630f3b33b to your computer and use it in GitHub Desktop.
OpenSiv3Dで縞模様を描く
This file contains 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> | |
void DrawStripe(const Rect& rect, double angle, double barWidth, const Array<ColorF>& pattern = { Palette::Yellow, Palette::Black }) | |
{ | |
// 傾けたときの描画範囲を計算 | |
const auto renderRect = | |
RectF{ 0, 0, rect.size }.asQuad() | |
.rotatedAt(0, 0, -angle) | |
.boundingRect(); | |
// 切り抜き | |
ScopedViewport2D view(rect); | |
// angle分だけ傾ける | |
Transformer2D t(Mat3x2::Rotate(angle)); | |
// 縞模様を描画 | |
for (int32 i = 0; | |
i * barWidth < renderRect.w; | |
i++) | |
{ | |
const auto color = pattern[i % pattern.size()]; | |
RectF{ renderRect.x + i * barWidth, renderRect.y, barWidth, renderRect.h } | |
.draw(color); | |
} | |
} | |
void Main() | |
{ | |
double angle = 45_deg; | |
double barWidth = 20; | |
while (System::Update()) | |
{ | |
Rect rect = Scene::Rect().stretched(-100); | |
DrawStripe(rect, angle, barWidth); | |
rect.drawFrame(2, 0, Palette::Red); | |
SimpleGUI::Slider(U"Angle", angle, 0_deg, 360_deg, { 0, 0 }, 100); | |
SimpleGUI::Slider(U"BarWidth", barWidth, 10.0, 100.0, { 0, 36 }, 100); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment