生不帶來,死不帶去;留與來者,照著鏡去。人體節律【智力、情緒、體力】
阿新 • • 發佈:2019-01-11
人體節律【智力、情緒、體力】軟體編寫,雖然在這個論壇上得不到任何程式碼支援和幫助,花2天時間學習例子,修改引數,溫習知識(三角函式、圓周、正弦、餘弦...)終於弄明白了該如何寫出正確程式碼,主要演算法程式碼不過幾行即可,記錄如下:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Windows.Forms.DataVisualization.Charting; namespace 人體節律 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { 三曲線(生日.Value); } private void 三曲線(DateTime 生日) { //曲線顯示.ChartAreas.Clear(); //曲線顯示.ChartAreas.Add("Default"); 曲線顯示.ChartAreas["Default"].AxisX.LabelStyle.Interval = 1; //曲線顯示.ChartAreas["Default"].AxisX.LabelStyle.Format = "##.##"; 曲線顯示.ChartAreas["Default"].AxisX.MajorGrid.Interval = 1; 曲線顯示.ChartAreas["Default"].AxisY.MajorGrid.Interval = 0.1;//Y軸間隔 曲線顯示.ChartAreas["Default"].AxisY.LabelStyle.Interval = 0.1;//Y軸標註 //曲線顯示.ChartAreas["Default"].Area3DStyle.Enable3D = true; //曲線顯示.ChartAreas["Default"].AxisX.MinorGrid.Interval = 1; //曲線顯示.ChartAreas["Default"].AxisX.MinorTickMark.Interval = 1; //曲線顯示.ChartAreas["Default"].AxisX.MajorTickMark.Interval = 1; //曲線顯示.ChartAreas["Default"].AxisY.MinorGrid.Interval = 0.1; //------------------------------------ DateTime 當前日期 = System.DateTime.Now; DateTime 假定日期 = Convert.ToDateTime("1900-1-1"); if (生日 != 當前日期) { 假定日期 = 生日; } System.TimeSpan 日差值 = 當前日期 - 假定日期; int 間隔 = 日差值.Days, 智力 = 間隔 % 33, 情緒 = 間隔 % 28, 體力 = 間隔 % 23; double 均值 = (智力 + 情緒 + 體力) / 3; 曲線顯示.Series["智力"].Points.Clear(); 曲線顯示.Series["情緒"].Points.Clear(); 曲線顯示.Series["體力"].Points.Clear(); 曲線顯示.Series["均值"].Points.Clear(); for (double t = 0; t <= 2 * 16.5; t++)//畫多長的曲線 t <= 數值可調整如等於33則顯示完整的33一個正弦波形 { double ch1 = Math.Sin((t + 智力) * 2 * Math.PI / 33);//2*Math.PI*r一個圓周按R的步進增長乘以正弦函式得到點座標形成以時間為X軸展開的正弦波形/一個週期畫多少個點(週期) 曲線顯示.Series["智力"].Points.AddXY(t, ch1); double ch2 = Math.Sin((t + 情緒) * 2 * Math.PI / 28); 曲線顯示.Series["情緒"].Points.AddXY(t, ch2); double ch3 = Math.Sin((t + 體力) * 2 * Math.PI / 23); 曲線顯示.Series["體力"].Points.AddXY(t, ch3); double ch4 = 0.1 * Math.Sin((t + 均值) * 2 * Math.PI / 23); 曲線顯示.Series["均值"].Points.AddXY(t, ch4); } } private void Form1_Paint(object sender, PaintEventArgs e) { 畫網格(); } private void 畫網格() { int 小時 = DateTime.Now.Hour; int 秒 = DateTime.Now.Second; int 分鐘 = DateTime.Now.Minute; //Graphics 例項 = 曲線顯示.CreateGraphics(); Graphics 例項 = this.CreateGraphics(); //例項.Clear(Color.White); Pen 線條 = new Pen(Color.Green, 1); Pen 線條1 = new Pen(Color.Orange, 1); for (int 線 = 10; 線 < 210; 線 += 10) { 例項.DrawLine(線條, new Point(線 + 30, 10), new Point(線 + 30, 200));//豎線需X座標=同 例項.DrawLine(線條1, new Point(40, 線), new Point(230, 線));//橫線需Y座標=同 } string[] 標註 = { "100", "90", "80", "70", "60", "50", "40", "30", "20", "10", "0", "-10", "-20", "-30", "-40", "-50", "-60", "-70", "-80", "-90", "-100" }; int y = 0; Font font = new System.Drawing.Font("Arial", 9, FontStyle.Regular); for (int i = 0; i < 21; i++) { 例項.DrawString(標註[i].ToString(), font, Brushes.Red, 0, y); y += 10; } PointF[] 絃線值 = new PointF[200], 絃線值1 = new PointF[180]; for (int i = 0; i < 絃線值.Length; i++) { 絃線值[i].X = 40 + i;//起始位置 絃線值[i].Y = 220 / 2 * (1 - (float)0.8 * (float)Math.Sin(i * 2 * Math.PI / 33)); }// 軸位置 幅度 for (int i = 0; i < 絃線值1.Length; i++) { 絃線值1[i].X = 40 + i;//起始位置 絃線值1[i].Y = 220 / 2 * (1 - (float)0.8 * (float)Math.Sin(i * 2 * Math.PI / 28)); } 例項.DrawLines(new Pen(SystemColors.WindowText), 絃線值); 例項.DrawLines(new Pen(SystemColors.WindowText), 絃線值1); } private void 生日_ValueChanged(object sender, EventArgs e) { 三曲線(生日.Value); } private void button1_Click(object sender, EventArgs e) { //三曲線(生日.Value); } private void 曲線顯示_Paint(object sender, PaintEventArgs e) { //三曲線(生日.Value); } } }
// // 曲線顯示 // this.曲線顯示.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); chartArea1.AxisX.IsMarginVisible = false; chartArea1.AxisX.ScaleBreakStyle.MaxNumberOfBreaks = 1; chartArea1.AxisX.ScaleBreakStyle.Spacing = 1D; chartArea1.AxisY.IsMarginVisible = false; chartArea1.IsSameFontSizeForAllAxes = true; chartArea1.Name = "Default"; this.曲線顯示.ChartAreas.Add(chartArea1); legend1.Name = "Legend1"; this.曲線顯示.Legends.Add(legend1); this.曲線顯示.Location = new System.Drawing.Point(2, 3); this.曲線顯示.Name = "曲線顯示"; series1.ChartArea = "Default"; series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; series1.IsXValueIndexed = true; series1.Legend = "Legend1"; series1.Name = "智力"; series2.ChartArea = "Default"; series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; series2.IsXValueIndexed = true; series2.Legend = "Legend1"; series2.Name = "情緒"; series3.ChartArea = "Default"; series3.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; series3.IsXValueIndexed = true; series3.Legend = "Legend1"; series3.MarkerSize = 1; series3.Name = "體力"; series4.ChartArea = "Default"; series4.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; series4.IsXValueIndexed = true; series4.Legend = "Legend1"; series4.Name = "均值"; this.曲線顯示.Series.Add(series1); this.曲線顯示.Series.Add(series2); this.曲線顯示.Series.Add(series3); this.曲線顯示.Series.Add(series4); this.曲線顯示.Size = new System.Drawing.Size(780, 186); this.曲線顯示.TabIndex = 0; this.曲線顯示.Text = "曲線"; this.曲線顯示.Paint += new System.Windows.Forms.PaintEventHandler(this.曲線顯示_Paint);
執行效果如圖:
點選開啟[圖表控制元件—Chart-200個示例]連結,下載其中ASP的示例壓縮包,FORM的好像無更新,如何開啟示例及檢視程式碼看最後圖示。
一些較早開發的類似軟體已經顯得不太好用,採用新的控制元件設計出來,在操作上更好用,比如輸入生日,新的控制元件點選選擇年月日更方便,而且可以使用鍵盤上的4個方向鍵調節,即時得到曲線的滾動變化,還可以做到3D影象、漂亮的背景圖片顯示等......
以上初步完成主要功能和演算法,有這個基礎,再想怎麼開發就看開發的人是怎麼想的了,哈哈......;“前不見古人,後不見來者,念天地之悠悠,沒人支援幾下愴然愴然”哈哈哈哈......
private void 標註提示(int 線序, int 位置, int[] 顏色, string 內容, string 圖表名, string 形狀) { if (形狀 == "標註形") { CalloutAnnotation 標註形 = new CalloutAnnotation(); 標註形.AnchorDataPoint = 曲線顯示.Series[線序].Points[位置]; 標註形.Text = 內容; 標註形.BackColor = Color.FromArgb(顏色[0], 顏色[1], 顏色[2]); 標註形.ClipToChartArea = 圖表名; 曲線顯示.Annotations.Add(標註形); } if (形狀 == "矩形") { RectangleAnnotation 矩形 = new RectangleAnnotation(); 矩形.Text = 內容; 矩形.BackColor = Color.FromArgb(顏色[0], 顏色[1], 顏色[2]); 矩形.AnchorX = 線序; 矩形.AnchorY = 位置; 曲線顯示.Annotations.Add(矩形); } }
200例示例如何檢視圖示:
多少年才遇到哦啊