{"id":18979641,"url":"https://github.com/reputeless/siv3dexamples-ipsj17","last_synced_at":"2026-02-03T14:01:58.620Z","repository":{"id":67723640,"uuid":"83222661","full_name":"Reputeless/Siv3DExamples-ipsj17","owner":"Reputeless","description":"情報処理 2017 年 6 月号「音や画像で遊ぼう」サンプルコード","archived":false,"fork":false,"pushed_at":"2017-05-10T02:29:17.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-21T08:47:16.774Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Reputeless.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-26T16:18:25.000Z","updated_at":"2017-05-10T02:21:43.000Z","dependencies_parsed_at":"2024-04-19T08:47:15.397Z","dependency_job_id":null,"html_url":"https://github.com/Reputeless/Siv3DExamples-ipsj17","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Reputeless/Siv3DExamples-ipsj17","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Reputeless%2FSiv3DExamples-ipsj17","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Reputeless%2FSiv3DExamples-ipsj17/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Reputeless%2FSiv3DExamples-ipsj17/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Reputeless%2FSiv3DExamples-ipsj17/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Reputeless","download_url":"https://codeload.github.com/Reputeless/Siv3DExamples-ipsj17/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Reputeless%2FSiv3DExamples-ipsj17/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261604158,"owners_count":23183601,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T15:44:17.296Z","updated_at":"2026-02-03T14:01:53.589Z","avatar_url":"https://github.com/Reputeless.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"## 音や画像で遊ぼう ～インタラクティブアプリケーションのための C++ フレームワーク「Siv3D」～  \nサンプルコード（『情報処理』2017 年 6 月号 掲載）  \n\n### Siv3D のインストール方法 (Windows)\nSiv3D Web ページ https://github.com/Siv3D/Reference-JP/wiki/ダウンロードとインストール\n\n## 1. コンピュータ画伯\n```cpp\n# include \u003cSiv3D.hpp\u003e\n\n// ① 2つの画像の差分を計算\ndouble Diff(const Image\u0026 a, const Image\u0026 b)\n{\n\tdouble d = 0.0;\n\n\tfor (auto p : step(a.size))\n\t{\n\t\td += Abs(int(a[p].r) - int(b[p].r));\n\t\td += Abs(int(a[p].g) - int(b[p].g));\n\t\td += Abs(int(a[p].b) - int(b[p].b));\n\t}\n\n\treturn d;\n}\n\nvoid Main()\n{\n\t// ② 目標とする画像を開く\n\tconst Image target = Dialog::OpenImage().fit(Window::Size());\n\n\t// ③ 同じ大きさの白い画像を用意\n\tImage image(target.size, Palette::White);\n\tImage old = image;\n\tDynamicTexture texture(old);\n\n\tdouble d1 = Diff(target, image); // ④\n\n\twhile (System::Update())\n\t{\n\t\tfor (int i = 0; i \u003c 100; ++i)\n\t\t{\n\t\t\told = image; // ⑤\n\n\t\t\t// ⑥ 画像内のランダムな位置\n\t\t\tPoint pos = RandomPoint(image.width, image.height);\n\n\t\t\t// ⑦ ランダムな色\n\t\t\tColorF color;\n\t\t\tcolor.r = Random();\n\t\t\tcolor.g = Random();\n\t\t\tcolor.b = Random();\n\t\t\tcolor.a = Random();\n\n\t\t\t// ⑧ ランダムな大きさ\n\t\t\tint size = Random(1, 10);\n\n\t\t\t// ⑨ 円を描いてみる\n\t\t\tCircle(pos, size).write(image, color);\n\n\t\t\t// ⑩ 目標に近づけば採用\n\t\t\tdouble d2 = Diff(target, image);\n\t\t\n\t\t\tif (d2 \u003c d1)\n\t\t\t{\n\t\t\t\td1 = d2;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\timage = old; // ⑪\n\t\t\t}\n\t\t}\n\n\t\t// ⑫ テクスチャを更新して描画\n\t\ttexture.fill(image);\n\t\ttexture.draw();\n\t}\n}\n```\n\n\n## 2. あなたの声はどんな形\n\n```cpp\n# include \u003cSiv3D.hpp\u003e\n\nvoid Main()\n{\n\t// ① マイク録音開始\n\tRecorder mic;\n\tmic.open(0, 5s, RecordingFormat::S44100, true);\n\tmic.start();\n\n\t// ② 加算ブレンドを有効に\n\tGraphics2D::SetBlendState(BlendState::Additive);\n\n\twhile (System::Update())\n\t{\n\t\t// ③ FFT で周波数成分を解析\n\t\tconst auto fft = FFT::Analyze(mic);\n\n\t\tfor (int i = 0; i \u003c fft.length(); ++i)\n\t\t{\n\t\t\t// ④ 音階\n\t\t\tdouble s = Log2((fft.resolution() * (i + 1)) / 27.5);\n\n\t\t\t// ⑤ パワー\n\t\t\tdouble p = fft.buffer[i];\n\n\t\t\t// ⑥ 円の中心位置\n\t\t\tconst Vec2 pos = Window::Center() + Circular(Pow(p, 0.5) * 600, s * TwoPi);\n\n\t\t\t// ⑦ 円の色\n\t\t\tconst Color c = HSV(s * 360).toColorF(0.05 * s);\n\n\t\t\t// ⑧ 円を描く\n\t\t\tCircle(pos, 15 - s).draw(c);\n\t\t}\n\t}\n}\n```\n\n## 3. 幸せになれる画像ビューア\n\n```cpp\n# include \u003cSiv3D.hpp\u003e\n\n// ① コメントの文章と位置\nstruct Comment\n{\n\tString text;\n\tVec2 pos;\n};\n\nvoid Main()\n{\n\t// ② 画像を選択する\n\tTexture photo(Dialog::OpenImage().fit(Window::Size()));\n\n\t// ③ 事前に用意したコメントを読み込む\n\tTextReader reader(L\"comments.txt\");\n\tArray\u003cComment\u003e comments;\n\tComment c;\n\twhile (reader.readLine(c.text))\n\t{\n\t\tc.pos.x = Random(1000, 2000); // ④\n\t\tc.pos.y = Random(0, 420);\n\t\tcomments.push_back(c);\n\t}\n\n\t// ⑤ コメント用のフォント\n\tFont font(30, Typeface::Bold, FontStyle::Outline);\n\tfont.changeOutlineStyle(TextOutlineStyle(Palette::Gray, Palette::White, 1));\n\n\twhile (System::Update())\n\t{\n\t\tphoto.draw(); // ⑥\n\n\t\tfor (auto\u0026 c : comments)\n\t\t{\n\t\t\tfont(c.text).draw(c.pos); // ⑦\n\t\t\t\n\t\t\t// ⑧ コメントを左に流す\n\t\t\tc.pos.x -= 4 + c.text.length * 0.2;\n\n\t\t\t// ⑨ 画面外に出たらまた右へ\n\t\t\tif (c.pos.x \u003c -500)\n\t\t\t{\n\t\t\t\tc.pos.x = Random(1000, 2000);\n\t\t\t\tc.pos.y = Random(0, 420);\n\t\t\t}\n\t\t}\n\t}\n}\n```\n\n## 4. めちゃくちゃな音楽プレイヤ\n\n```cpp\n# include \u003cSiv3D.hpp\u003e\n\nvoid Main()\n{\n\t// ① 表示用のフォントを用意\n\tFont font(20);\n\n\t// ② 音楽ファイルを開く\n\tSound sound = Dialog::OpenSound();\n\n\t// ③ 音楽を再生\n\tsound.play();\n\n\twhile (System::Update())\n\t{\n\t\t// ④ 線を描く\n\t\tLine(0, 240, 640, 240).draw(4);\n\t\tLine(320, 480, 320, 0).draw(4);\n\n\t\t// ⑤ カーソルの位置に円を描く\n\t\tPoint pos = Mouse::Pos();\n\t\tCircle(pos, 20).draw(Palette::Orange);\n\n\t\t// ⑥ テンポを計算\n\t\tdouble tempo = Exp2((pos.x - 320) / 240.0);\n\n\t\t// ⑦ ピッチを計算\n\t\tdouble pitch = -(pos.y - 240) / 60.0;\n\n\t\t// ⑧ 音楽にテンポとピッチを適用\n\t\tsound.changeTempo(tempo);\n\t\tsound.changePitchSemitones(pitch);\n\n\t\t// ⑨ 現在のテンポとピッチを表示\n\t\tfont(L\"tempo: \", tempo).draw(20, 20);\n\t\tfont(L\"pitch: \", pitch).draw(20, 60);\n\t}\n}\n```\n\n## 5. 数式の大地を探検する\n\n\u003e :warning: Release ビルドで、「デバッグなしで実行」をしないとちょっと重いです。\n```cpp\n# include \u003cSiv3D.hpp\u003e\n\nvoid Main()\n{\n\t// ① 背景を明るい色に\n\tGraphics::SetBackground(Color(120, 180, 160));\n\n\t// ② メッシュを用意\n\tMeshData meshData = MeshData::Grid(25, 160);\n\tDynamicMesh mesh(meshData);\n\n\t// ③ 数式を入力するテキストエリアを用意\n\tGUI gui(GUIStyle::Default);\n\tgui.addln(L\"exp\", GUITextArea::Create(2, 30));\n\n\twhile (System::Update())\n\t{\n\t\tif (!gui.textArea(L\"exp\").active)\n\t\t{\n\t\t\tGraphics3D::FreeCamera(); // ④\n\t\t}\n\n\t\t// ⑤ 数式が変更されたら\n\t\tif (gui.textArea(L\"exp\").hasChanged)\n\t\t{\n\t\t\tif (const ParsedExpression exp{ gui.textArea(L\"exp\").text })\n\t\t\t{\n\t\t\t\tgui.textArea(L\"exp\").style.color = Palette::Black; // ⑥\n\t\t\t\t\n\t\t\t\t// ⑦ 数式に基づきメッシュの座標を計算\n\t\t\t\tfor (auto\u0026 v : meshData.vertices)\n\t\t\t\t{\n\t\t\t\t\tv.position.y = exp.evaluateOpt({\n\t\t\t\t\t\t{ L\"x\", v.position.x },\n\t\t\t\t\t\t{ L\"y\", v.position.z } })\n\t\t\t\t\t\t.value_or(0);\n\t\t\t\t}\n\n\t\t\t\t// ⑧ 法線を更新\n\t\t\t\tmeshData.computeNormals();\n\n\t\t\t\t// ⑨ メッシュを更新\n\t\t\t\tmesh.fillVertices(meshData.vertices);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tgui.textArea(L\"exp\").style.color = Palette::Red; // ⑩\n\t\t\t}\n\t\t}\n\n\t\t// ⑪ メッシュを描画\n\t\tmesh.draw().drawShadow();\n\t}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freputeless%2Fsiv3dexamples-ipsj17","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freputeless%2Fsiv3dexamples-ipsj17","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freputeless%2Fsiv3dexamples-ipsj17/lists"}