Skip to content

Instantly share code, notes, and snippets.

@furukawa1020
Last active January 1, 2026 03:22
Show Gist options
  • Select an option

  • Save furukawa1020/667d8bde39419cd62f3a2fb520745853 to your computer and use it in GitHub Desktop.

Select an option

Save furukawa1020/667d8bde39419cd62f3a2fb520745853 to your computer and use it in GitHub Desktop.
C++でおみくじ作りました。実行するとちゃんと出ます!正月も!正月以外のときでも!
#include <iostream>
#include <vector>
#include <thread>
#include <chrono>
#include <ctime>
#include <cstdlib>
using namespace std;
using namespace chrono;
void sleep(int ms) {
this_thread::sleep_for(milliseconds(ms));
}
void clear() {
cout << "\033[2J\033[1;1H";
}
int main() {
srand(time(nullptr));
// 起動演出
clear();
cout << "起動中";
for (int i = 0; i < 5; i++) {
cout << ".";
cout.flush();
sleep(300);
}
clear();
// 神社ASCII
cout << R"(
⛩ ⛩ ⛩
───────────
年 越 神 社
───────────
)" << endl;
sleep(1000);
cout << "おみくじ箱を振っています" << endl;
sleep(500);
// ガラガラ演出
vector<string> drum = {"◐", "◓", "◑", "◒"};
for (int i = 0; i < 20; i++) {
cout << "\r" << drum[i % drum.size()] << " ガラガラ…" << flush;
sleep(100);
}
cout << endl;
struct Omikuji {
string name;
string message;
int exit_code;
};
vector<Omikuji> fortunes = {
{"大吉", "世界はまだまだ面白くなる", 0},
{"中吉", "人との縁が後から効いてくる", 0},
{"小吉", "迷ってもちゃんと前進中", 0},
{"吉", "思ったより悪くない年", 0},
{"末吉", "来年に遅延実行される", 0},
{"凶", "今日は無理するな。寝ろ", 1}
};
Omikuji result = fortunes[rand() % fortunes.size()];
sleep(800);
clear();
// 結果表示
cout << "━━━━━━━━━━━━━━━━━━━" << endl;
cout << " 🎍 お み く じ 🎍 " << endl;
cout << "━━━━━━━━━━━━━━━━━━━" << endl;
cout << endl;
cout << " 運勢: 【 " << result.name << " 】" << endl << endl;
cout << " " << result.message << endl << endl;
// 特殊演出
if (result.name == "大吉") {
cout << " ✨✨✨✨✨✨✨✨✨" << endl;
cout << " 祝!生存&進行中!" << endl;
}
if (result.name == "凶") {
cout << " ⚠ SYSTEM WARNING ⚠" << endl;
cout << " 本日は無理をしないでください" << endl;
}
cout << endl;
cout << " 引いた時刻: " << time(nullptr) << endl;
cout << endl;
cout << "━━━━━━━━━━━━━━━━━━━" << endl;
return result.exit_code;
}

omikuji.cpp

おみくじです!正月も!正月以外も!

おみくじ

C++で動く、年越し用おみくじプログラムです。
動けば何でもOK。環境・流派・宗派は問いません。


スマホで実行する方法

ブラウザだけで動きます。インストール不要。

手順

  1. 下のサイトを開く
    https://www.onlinegdb.com/online_c++_compiler

  2. 左のエディタに omikuji.cpp の中身をそのままコピペ

  3. 右上の Run ▶️ を押す

  4. 下のコンソールにおみくじが表示されます 🎍

※ iPhone / Android 対応
※ 日本語・絵文字(⛩など)も表示されます


パソコンで実行する方法(例)

g++

bash g++ omikuji.cpp -o omikuji ./omikuji

clang++(macOS など)

clang++ omikuji.cpp -o omikuji ./omikuji

Visual Studio(Windows)

新規 C++ コンソールプロジェクトを作成

omikuji.cpp を追加

実行

CMake を使う場合(やりたい人向け)

cmake_minimum_required(VERSION 3.10) project(omikuji) add_executable(omikuji omikuji.cpp)

mkdir build cd build cmake .. cmake --build . ./omikuji

※ CMakeは必須ではありません。


その他の実行方法

以下もすべてOK!

Compiler Explorer

Docker

WSL

任意のオンラインC++実行環境

学校・研究室の環境

C++としてコンパイルできれば基本的に動きます。

深い知識は不要

main があって動けば勝ち

ビルド方法は宗教なので気にしない

引いて楽しみましょう!


#include <iostream>
#include <vector>
#include <thread>
#include <chrono>
#include <ctime>
#include <cstdlib>
using namespace std;
using namespace chrono;
void sleep(int ms) {
this_thread::sleep_for(milliseconds(ms));
}
void clear() {
cout << "\033[2J\033[1;1H";
}
void beep() {
cout << "\a" << flush;
}
// ゲーミング文字(色が流れる)
void rainbow(const string& text) {
vector<int> colors = {31, 33, 32, 36, 34, 35};
for (int i = 0; i < text.size(); i++) {
cout << "\033[1;" << colors[i % colors.size()] << "m"
<< text[i] << "\033[0m";
sleep(20);
}
cout << endl;
}
int main() {
srand(time(nullptr));
clear();
cout << "起動中";
for (int i = 0; i < 5; i++) {
cout << ".";
beep();
cout.flush();
sleep(300);
}
clear();
cout << R"(
⛩ ⛩ ⛩
───────────
年 越 神 社
───────────
)" << endl;
sleep(800);
cout << "おみくじ箱を振っています" << endl;
vector<string> drum = {"◐", "◓", "◑", "◒"};
for (int i = 0; i < 25; i++) {
cout << "\r\033[1;36m" << drum[i % drum.size()]
<< " ガラガラ…\033[0m" << flush;
beep();
sleep(100);
}
struct Omikuji {
string name;
string message;
int exit_code;
};
vector<Omikuji> fortunes = {
{"大吉", "世界はまだまだ面白くなる", 0},
{"超吉", "全部つながって後で効く", 0},
{"神吉", "今年は当たり年確定", 0},
{"覇吉", "調子に乗ってよい", 0},
{"強吉", "進め。止まる理由なし", 0},
{"凶", "今日は無理するな。寝ろ", 1}
};
Omikuji result = fortunes[rand() % fortunes.size()];
clear();
cout << "━━━━━━━━━━━━━━━━━━━" << endl;
rainbow("🎍 お み く じ 🎍");
cout << "━━━━━━━━━━━━━━━━━━━" << endl << endl;
cout << "\033[1;33m運勢:【 " << result.name << " 】\033[0m\n\n";
rainbow(result.message);
if (result.name != "凶") {
cout << "\n\033[1;32m✨✨✨ BLESSING ✨✨✨\033[0m\n";
for (int i = 0; i < 5; i++) beep();
} else {
cout << "\n\033[1;31m⚠ SYSTEM WARNING ⚠\033[0m\n";
}
cout << "\n引いた時刻: " << time(nullptr) << endl;
cout << "━━━━━━━━━━━━━━━━━━━" << endl;
return result.exit_code;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment