Created
October 5, 2023 09:14
-
-
Save naga-karupi/5e0eb0dcaa67ec3a8415dd41633f8af1 to your computer and use it in GitHub Desktop.
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> | |
using namespace s3d; | |
namespace globals | |
{ | |
uint32 counter = 0; | |
Stopwatch sw; | |
Array<Vec2> target(0); | |
} | |
void countup() | |
{ | |
if (not globals::sw.isRunning()) | |
{ | |
globals::sw.start(); | |
} | |
while (1) | |
{ | |
const auto start = globals::sw.ms(); | |
Print(globals::counter); | |
globals::counter++; | |
globals::counter %= 8000; | |
System::Sleep(1ms); | |
} | |
} | |
void ToLineString(const Array<double>& values_x, const Array<double>& values_y, const Vec2& start, LineString& ls, double scale) | |
{ | |
ls.resize(values_x.size()); | |
for (size_t i = 0; i < values_x.size(); ++i) | |
{ | |
ls[i] = (start + Vec2{ values_x[i] * scale + 350, (values_y[i] * -scale)}); | |
} | |
} | |
void Main() | |
{ | |
Scene::SetBackground(Palette::White); | |
constexpr size_t N = 800; | |
constexpr size_t N_point = 8000; | |
globals::target.resize(N_point + 1); | |
constexpr double theta_start = 0.0; | |
constexpr double theta_end = 2.0 * Math::Pi; | |
constexpr double theta_step = (theta_end - theta_start) / N; | |
Array<double> values_x(N + 1); | |
Array<double> values_y(N + 1); | |
for (size_t i = 0; i < N + 1; i++) | |
{ | |
const double theta = theta_start + theta_step * i; | |
values_x.at(i) = 4 * Math::Sin(3 * theta); | |
values_y.at(i) = 4 * Math::Sin(4 * theta); | |
} | |
constexpr double theta_step_point = (theta_end - theta_start) / N_point; | |
for (size_t i = 0; i < N_point; i++) | |
{ | |
const double theta = theta_start + theta_step_point * i; | |
globals::target.at(i).x = 4 * Math::Sin(3 * theta); | |
globals::target.at(i).y = 4 * Math::Sin(4 * theta); | |
} | |
LineString ls(N + 1); | |
ToLineString(values_x, values_y, Vec2{50, 300}, ls, 50); | |
AsyncTask<void> task; | |
task = Async(countup);// ここをコメントアウトするとウィンドウが閉じる | |
while (System::Update()) | |
{ | |
ls.draw(Palette::Blue); | |
Circle(globals::target.at(globals::counter).x + 50, globals::target.at(globals::counter).y + 300, 5).draw(Palette::Red); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment