EightDiagram共有8个符号,由阴爻(yáo)(“- -”,虚线,按二进制0处理),阳爻(“—”,实线,按二进制1处理)按二进制处理组成。每个符号由三个爻组成,因此共有8种=2*2*2。恰好对应我们程序语言中的八进制【由0~7共八个数字组成】。
上次本人使用中文,结果审批未通过【违法违规】,难不成被认为宣传封建迷信了!
我们按照爻从下往上的顺序,则:坤为0,震为1,坎为2,兑为3,艮为4,离为5,巽为6,乾为7.
阳爻:实线,由三个连续的宽度为40,高度为20的小矩形组成
阴爻:虚线,由两个宽度为40,高度为20的小矩形 与 中间的宽度和高度都为0的小矩形组成
阴爻我们可以认为阳爻中间挖空即可【即:中间的小矩形宽和高都为0】
因此 EightDiagram的每一个符号都由9个小矩形组成
将默认的Form1重命名为FormEightDiagram,窗体FormEightDiagram设计如图:
并为8个按钮绑定事件:button_Click
(忽略设计器自动生成的部分类代码):
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace EightDiagramDemo
{
public partial class FormEightDiagram : Form
{
public FormEightDiagram()
{
InitializeComponent();
}
private void FormEightDiagram_Load(object sender, EventArgs e)
{
rtxtDisplay.Text = @"乾三连,坤六断,
震仰盂,艮覆碗,
离中虚,坎中满,
兑上缺,巽下断。
----------------------------------------
八卦对应五行:
乾、兑为金,坤、艮为土,震、巽为木,坎为水,离为火。";
//面板宽度为200,高度为200
GenerateEightDiagramSymbol(panel1, "乾三连", 7, Color.Green);
}
///
/// 绘制某一个八卦图片
///
/// 显示的面板控件
/// 八卦中文描述
/// 坤为0,震为1,坎为2,兑为3,艮为4,离为5,巽为6,乾为7
/// 颜色,【乾坎艮】为绿色,【巽离】为黄色,【坤震兑】为红色
private void GenerateEightDiagramSymbol(Panel panel, string diagramChar, int diagramIndex, Color color)
{
panel.BackgroundImage = null;//清除背景
//面板宽度为200,高度为200
Bitmap bitmap = new Bitmap(panel.Width, panel.Height);
Graphics graphics = Graphics.FromImage(bitmap);
//爻是按照从下往上的顺序:坤为0,震为1,坎为2,兑为3,艮为4,离为5,巽为6,乾为7.
//阳爻:实线,由三个连续的宽度为40,高度为20的小矩形组成
//阴爻:虚线,由两个宽度为40,高度为20的小矩形 与 中间的宽度和高度都为0的小矩形组成
//因此 八卦的每一个符号都由9个小矩形组成
int lineWidth1 = 0;
int lineHeight1 = 0;
int lineWidth2 = 0;
int lineHeight2 = 0;
int lineWidth3 = 0;
int lineHeight3 = 0;
if (diagramIndex == 1)
{
lineWidth1 = 40;
lineHeight1 = 20;
}
else if (diagramIndex == 2)
{
lineWidth2 = 40;
lineHeight2 = 20;
}
else if (diagramIndex == 3)
{
lineWidth1 = 40;
lineHeight1 = 20;
lineWidth2 = 40;
lineHeight2 = 20;
}
else if (diagramIndex == 4)
{
lineWidth3 = 40;
lineHeight3 = 20;
}
else if (diagramIndex == 5)
{
lineWidth1 = 40;
lineHeight1 = 20;
lineWidth3 = 40;
lineHeight3 = 20;
}
else if (diagramIndex == 6)
{
lineWidth2 = 40;
lineHeight2 = 20;
lineWidth3 = 40;
lineHeight3 = 20;
}
else if (diagramIndex == 7)
{
lineWidth1 = 40;
lineHeight1 = 20;
lineWidth2 = 40;
lineHeight2 = 20;
lineWidth3 = 40;
lineHeight3 = 20;
}
Rectangle[] rects = new Rectangle[9]
{
new Rectangle(40, 40, 40, 20), new Rectangle(80, 40, lineWidth3, lineHeight3), new Rectangle(120, 40, 40, 20),
new Rectangle(40, 80, 40, 20), new Rectangle(80, 80, lineWidth2, lineHeight2), new Rectangle(120, 80, 40, 20),
new Rectangle(40, 120, 40, 20), new Rectangle(80, 120, lineWidth1, lineHeight1), new Rectangle(120, 120, 40, 20),
};
//奇门遁甲八门中:
//开门,休门,生门是吉祥的;绿色标识
//杜门和景门可以说是中性的,又是吉祥,有时应凶;黄色标识
//死门,惊门,伤门是三个容易应凶、出凶的门;红色标识
//开门在乾金宫,休门在坎水宫,生门在艮土宫,伤门在震木宫,
//杜门在巽木宫,景门在离火宫,死门在坤土宫,惊门在兑金宫。
graphics.FillRectangles(new SolidBrush(color), rects);
graphics.DrawRectangles(new Pen(color), rects);
SizeF sizeF = graphics.MeasureString(diagramChar, new Font("华文楷体", 25));
graphics.DrawString(diagramChar, new Font("华文楷体", 25), new SolidBrush(Color.Black), 100 - sizeF.Width / 2, 170 - sizeF.Height / 2);
graphics.Dispose();
panel.BackgroundImage = bitmap;
}
private void button_Click(object sender, EventArgs e)
{
Button button = sender as Button;
if (button == null)
{
return;
}
switch (button.Text)
{
case "乾":
GenerateEightDiagramSymbol(panel1, "乾三连", 7, Color.Green);
break;
case "坤":
GenerateEightDiagramSymbol(panel1, "坤六断", 0, Color.Red);
break;
case "震":
GenerateEightDiagramSymbol(panel1, "震仰盂", 1, Color.Red);
break;
case "艮":
GenerateEightDiagramSymbol(panel1, "艮覆碗", 4, Color.Green);
break;
case "离":
GenerateEightDiagramSymbol(panel1, "离中虚", 5, Color.Yellow);
break;
case "坎":
GenerateEightDiagramSymbol(panel1, "坎中满", 2, Color.Green);
break;
case "兑":
GenerateEightDiagramSymbol(panel1, "兑上缺", 3, Color.Red);
break;
case "巽":
GenerateEightDiagramSymbol(panel1, "巽下断", 6, Color.Yellow);
break;
}
}
}
}