Skip to content

Instantly share code, notes, and snippets.

@comefrombottom
comefrombottom / makeRegularRationalShapeLineString.cpp
Last active June 28, 2024 08:50
既約分数n/m角形の頂点を求める
# include <Siv3D.hpp> // Siv3D v0.6.14
//既約分数n/m角形の頂点を求める
LineString makeRegularRationalShapeLineString(const Vec2& center, double r, int32 n, int32 m)
{
LineString points(n);
for (auto i : step(n))
{
const double theta = Math::TwoPi / n * i * m;
points[i] = center + Circular(r, theta);
@comefrombottom
comefrombottom / InputPair.cpp
Last active May 31, 2024 18:52
InputAndPair と InputOrPair は、2つの入力を組み合わせた入力を表すクラスです。二つの入力が、downとupを必ず交互によびだすとき、そのペアもdownとupを必ず交互によびだします。
# include <Siv3D.hpp> // Siv3D v0.6.14
//InputAndPair と InputOrPair は、2つの入力を組み合わせた入力を表すクラスです。
//二つの入力が、downとupを必ず交互によびだすとき、そのペアもdownとupを必ず交互によびだします。
//InputManageFlag は、入力と一緒にペアを作ることが出来るフラグです。
// update(bool currentPressed) で、入力の状態を更新します。
//※おそらくOpenSiv3Dの実装内にあるInputStateを縮小したもの
@comefrombottom
comefrombottom / MiniWindow.cpp
Created May 25, 2024 08:51
Transformer2D, Scoped...みたいな感じで使えるWindow
# include <Siv3D.hpp> // OpenSiv3D v0.6.14
//宣言
class MiniWindow {
public:
MiniWindow(const Rect& rect, double scale ,const Color& backgroundColor = ColorF(0.4));
void update(const Size parentSceneSize);
@comefrombottom
comefrombottom / ScrollBar.cpp
Created May 20, 2024 18:14
SasaGUI [https://github.com/sthairno/SasaGUI/tree/siv067_dev] のScrollBarを掴んだ位置からずらせるようにしただけの差分
class ScrollBar
{
public:
using Config = Config::ScrollBar;
constexpr static int32 Thickness = Config::TrackMargin * 2 + Config::ThumbThickness;
constexpr static int32 MinLength = Config::TrackMargin * 2 + Config::ThumbMinLength;
constexpr static double ThumbRoundness = Config::ThumbThickness * 0.5;
# include <Siv3D.hpp> // Siv3D v0.6.14
struct Ball
{
P2Body body;
double r;
Color color;
};
void Main()
@comefrombottom
comefrombottom / Main.cpp
Created May 5, 2024 00:58
電撃エッフェクトのhlslシェーダサンプル(Siv3D)
# include <Siv3D.hpp>
struct Electrification {
Float2 scale;
float time;
float speed;
uint32 octaves;
};
void Main() {
@comefrombottom
comefrombottom / Siv3DKawaiiLogo.cpp
Last active April 25, 2024 14:46
Xでバズっていた、さわらつき氏によるプログラミング言語のkawaii logo のSiv3D版をSiv3Dを用いて作ってみました。ロゴマーク含め手打ち座標で作っているため、コピペして即実行できます。Debug実行の場合、前計算に割と時間がかかるので注意してください。
# include <Siv3D.hpp> // Siv3D v0.6.14
MultiPolygon createLogoPolygon() {
Bezier3 bezier(Vec2(230, 429), Vec2(404, 490), Vec2(573, 375), Vec2(573, 277));
Bezier3 bezier2(Vec2(573, 277), Vec2(573, 194), Vec2(467, 141), Vec2(425, 244));
Bezier3 bezier3(Vec2(401, 245), Vec2(456, 124), Vec2(626, 165), Vec2(626, 304));
Bezier3 bezier4(Vec2(626, 304), Vec2(626, 440), Vec2(420, 530), Vec2(230, 429));
auto moveBy = [](Bezier3& bezier, Vec2 v) {
bezier.p0 += v;
@comefrombottom
comefrombottom / NeighbourSearcher.cpp
Created April 13, 2024 08:20
Gridを近いところから探索できる仕組み
#include<Siv3D.hpp>
class NeighbourSearcher {
struct DistancePoint {
double distance;
int32 x;
int32 y;
auto operator<=>(const DistancePoint&) const = default;
};
# include <Siv3D.hpp>
# include "Multiplayer_Photon.hpp"
# include "PHOTON_APP_ID.SECRET"
SIV3D_CONCEPT_URBG
Array<Vec2> createPieceEdgePoints(URBG&& urbg) {
double centerX = Random(-0.15, 0.15, urbg) + 0.5;
double headwidth = Random(0.25, 0.35, urbg);
double headheight = -Random(0.12, 0.18, urbg);
double neckWidth = Random(0.12, 0.18, urbg);
@comefrombottom
comefrombottom / WaterSurface.cpp
Created February 22, 2024 17:50
水面の揺らぎをシェーダで作ってみた。
# include <Siv3D.hpp> // Siv3D v0.6.12
void Main()
{
const PixelShader wavePropagatePS = HLSL{ U"wave_propagate.hlsl", U"PS" };
if (not wavePropagatePS)
{
throw Error{ U"Failed to load a shader file" };
}