背景
古人展现了非凡的智慧,孕育了《易经》这一博大精深的经典之作。然而,多数人对《易经》的认知往往局限于其占卜的层面,误以为它仅仅是预测未来的工具。实则,《易经》蕴含了深刻的哲学思想、宇宙观以及道德伦理,是探讨自然法则、人生智慧与社会和谐的宝库。由于缺乏对其全面而系统的学习,我们往往难以窥见其全貌,错过了深入领略这一文化瑰宝精髓的机会。
见解
六十四卦
就比如乾卦,潜龙勿用,阳在下也。见龙在田,德施普也。终日乾乾,反复道也。或跃在渊,进无咎也。飞龙在天,大人造也。亢龙有悔,盈不可久也。可能看不懂具体说了个啥事情,我大致说一下我的见解。
///////////////////////////////////////////////////
// 程序名称:卜卦人生
// 编译环境:Mictosoft Visual Studio 2022, EasyX_20200315(beta)
// 作 者:luoyh <2864292458@qq.com>
// 最后修改:2024-8-19
// 公 众 号:C语言研究
//
void DrawYAO(int num, int x, int y); // 绘制爻
void ISYD(int NUM);
int Nums;
void decimalToBinaryIntArray(int decimal, int binaryArray[6]);
int generateRandomNumber(int min, int max);
const char* yiJingGuaNames[64] =
{
"坤为地","地雷复","地水师","地泽临",
"地山谦","地火明夷","地风升","地天泰",
"雷地豫","震为雷","雷水解","雷泽归妹",
"雷山小过","雷火丰","雷风恒","雷天大壮",
"水地比","水雷屯","坎为水","水泽节",
"水山蹇","水火既济","水风井","水天需",
"泽地萃","泽雷随","泽水困","兑为泽",
"泽山咸","泽火革","泽风大过","泽天夬",
"山地剥","山雷颐","山水蒙","山泽损",
"艮为山","山火贲","山风蛊","山天大畜",
"火地晋","火雷噬嗑","火水未济","火泽睽",
"火山旅","离为火","火风鼎","火天大有",
"风地观","风雷益","风水涣","风泽中孚",
"风山渐","风火家人","巽为风","风天小畜",
"天地否","天雷无妄","天水讼","天泽履",
"天山遁","天火同人","天风姤","乾为天"
};
int main()
{
initgraph(640, 480);
setbkcolor(WHITE);
cleardevice();
srand(time(0));
ExMessage msg; // 定义一个鼠标消息
BeginBatchDraw();
flushmessage();
while (true)
{
peekmessage(&msg, EX_MOUSE);
FlushBatchDraw();
cleardevice();
// 鼠标按下,开发摇动
if (msg.lbutton)
{
Nums = generateRandomNumber(0, 63);
ISYD(Nums);
}
else
{
ISYD(Nums);
}
}
return 0;
}
void ISYD(int NUM)
{
settextcolor(BLACK);
settextstyle(50, 0, _T("楷体"));
setbkmode(TRANSPARENT);
RECT r = { 0,0,640,120 };
drawtext(yiJingGuaNames[Nums], &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
int binaryArray[6]; // 整数数组,但每个元素只存储一个二进制位
decimalToBinaryIntArray(NUM, binaryArray);
for (int i = 5; i >= 0; i--)
{
DrawYAO(binaryArray[i], 220, 320 - i * 40);
}
}
int generateRandomNumber(int min, int max)
{
// 确保max大于等于min
if (max < min)
{
int temp = min;
min = max;
max = temp;
}
// 使用rand()生成随机数,并通过取模确保结果在min到max之间
int random = rand() % (max - min + 1) + min;
return random;
}
void DrawYAO(int num, int x, int y)
{
setfillcolor(BLACK);
if (num == 1)
{
solidrectangle(x, y, x + 200, y + 20); // 二进制为1时,绘制长实线
}
if (num == 0)
{
solidrectangle(x, y, x + 100 - 10, y + 20); // 二进制为0时,绘制短实线
solidrectangle(x + 100 + 10, y, x + 200, y + 20);
}
}
// 将一个十进制数转换为二进制存储到数组中
void decimalToBinaryIntArray(int decimal, int binaryArray[6])
{
for (int i = 0; i < 6; i++)
{
// 从最低位开始填充
binaryArray[i] = decimal % 2;
decimal /= 2;
}
}
效果