public frmMain() { InitializeComponent(); //Инициализация всех компонентов для рисования. //Фактически, полная загрузка приложения. btmp = new Bitmap(pictureBox.Width, pictureBox.Height); g = Graphics.FromImage(btmp); font = new Font("Segoe print", 12); pictureBox.Image = btmp; wmp = new WindowsMediaPlayer(); pl = new MySoundPlayer(); wmp.URL = "Music\\menu.mp3"; wmp.settings.setMode("Loop", true); wmp.settings.volume = 100; m_rnd = new Random(); //ship = new Ship(pictureBox.Width, pictureBox.Height); space = new Space(pictureBox.Width, pictureBox.Height); Draw = new MyDrawing(g, space.GetWidth, space.GetHeight); director = new StageDirector(pictureBox.Width, pictureBox.Height); x = space.GetWidth / 2; y = space.GetHeight - 100; pictureBox.Cursor.Dispose(); Draw.Menu(pictureBox.Width, pictureBox.Height); now = DateTime.Now; lastCurrent = now; }
private void pictureBox1_MouseUp_Click(object sender, EventArgs e) { if (mouseDown) { x1 = e.X; y1 = e.Y; MyDrawing.drawLine(x0, y0, x1, y1, bitmap, pictureBox1, color); mouseDown = false; } }
private void pictureBox1_MouseMove_Click(object sender, EventArgs e) { if (mouseDown) { bitmapClone = (Bitmap)bitmap.Clone(); x1 = e.X; y1 = e.Y; MyDrawing.drawline(x0, y0, x1, y1, bitmap, pictureBox1, color); bitmap = bitmapClone; } }
private void tabPage2_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; //for (int i = 0; i < 779; i += 100) //{ // g.DrawLine(pen1, i, 0, i, 10); //} //for (int i = 0; i < 490; i += 100) //{ // g.DrawLine(pen1, 0, i, 10, i); //} g.DrawString(" 首先对传动轴进行受力分析,轴总共受到7个力作用,分别为皮带轮D对传动轴的力F₂\n" + "和2F₂,皮带轮D₁对传动轴的力F₁和2F₁,齿轮D₂对传动轴的力F,还有皮带轮D的重力和G₂\n" + "皮带轮D₁的重力G₁.受力简图如下所示:\n", font1, brush1, 10, 10); g.DrawLine(pen1, 200, 200, 700, 200);//主轴线 MyDrawing.DrawX(g, "right", 100, 200, 150, 200); MyDrawing.DrawY(g, "up", 100, 200, 100, 150); MyDrawing.DrawDownLeftArrow(g, 100, 200, 65, 235); g.DrawString("X", font2, brush1, 150 + 5, 200 + 5); //x轴 g.DrawString("Y", font2, brush1, 100 - 20, 150 - 20); //y轴 g.DrawString("Z", font2, brush1, 65, 235); //z轴 MyDrawing.DrawY(g, "down", 200, 200, 200, 250); //fcos g.DrawString("Fcosα", font2, brush1, 170, 270); MyDrawing.DrawUpRightArrow(g, 200, 200, 200 + 35, 200 - 35); //fsin g.DrawString("Fsinα", font2, brush1, 210, 200 - 70); MyDrawing.DrawY(g, "up", 300, 200, 300, 150); //fay g.DrawString("Fay", font2, brush1, 300 - 20, 150 - 40); MyDrawing.DrawDownLeftArrow(g, 300, 200, 300 - 35, 200 + 35); //faz g.DrawString("Faz", font2, brush1, 300 - 35, 200 + 40); MyDrawing.DrawY(g, "down", 500, 200, 500, 250); //3f1+G1 g.DrawString("3F₁+G₁", font2, brush1, 500 - 30, 250 + 25); MyDrawing.DrawY(g, "up", 600, 200, 600, 150); //fby g.DrawString("Fby", font2, brush1, 600 - 20, 150 - 40); MyDrawing.DrawDownLeftArrow(g, 600, 200, 600 - 35, 200 + 35); //fbz g.DrawString("Fbz", font2, brush1, 600 - 35, 200 + 40); MyDrawing.DrawUpRightArrow(g, 700, 200, 700 + 35, 200 - 35); //3f2 g.DrawString("3F₂", font2, brush1, 700 + 30, 200 - 35 - 30); MyDrawing.DrawY(g, "down", 700, 200, 700, 250); //g2 g.DrawString("G₂", font2, brush1, 700 - 10, 250 + 20); g.DrawArc(pen1, 200 - 20, 200 - 30, 40, 60, 75, 195); MyDrawing.DrawX(g, "right", 200, 200 - 30, 200, 200 - 30);//M g.DrawString("M", font2, brush1, 200 - 10, 200 - 30 - 25); g.DrawArc(pen1, 500 - 20, 200 - 30, 40, 60, 75, 195); MyDrawing.DrawX(g, "right", 500, 200 - 30, 500, 200 - 30);//M1 g.DrawString("M₁", font2, brush1, 500 - 15, 200 - 30 - 25); g.DrawArc(pen1, 700 - 20, 200 - 30, 40, 60, 90, 195); MyDrawing.DrawX(g, "right", 700, 200 + 30, 700, 200 + 30);//M2 g.DrawString("M₂", font2, brush1, 700 + 25, 200 + 20); for (int i = 200; i <= 700; i += 100) { g.DrawLine(pen1, i, 200, i, 193); } g.DrawString(" 此传动轴受弯扭组合变形,把各力分解,使每组力只产生一种变形,如上图。", font1, brush1, 10, 300); }
public Form1() { InitializeComponent(); PerceptronInputs = new List <Input>(); myDrawing = new MyDrawing(); // Transfer function 0 == binary, 1 == sigmoid _neuralNetwork = new NeuralNetwork.NeuralNetwork(2, 2, 1); _perceptron = new Perceptron(ParseData("AND.txt")); //_perceptron.PerceptronNeuron.TrainUntil(_perceptron.TrainingSet, 0.2); myDrawing.DrawPerceptron(_perceptron, perceptronPictureBox); InitControls(); refreshNetwork(); errorChart.Series.Clear(); //Hopfield _hopfield = new Hopfield(5, 7, 50); _hopImage = new List <double>(); }
/// <summarly> /// Makes the color plot of the function whose values at the polygon polygons[i-1] is values[i-1] /// </summary> /// <param name="graphl">the object at which the plot will be drawn</param> /// <param name="polygons">the table of polygons</param> /// <param name="values">the table of values</param> /* static public void ColorAreas(ref Graphics graphl, List<MyPolygon> polygons, double[] values, MyGraphOperations.ColorsFunc ColFunc) * { * * if (graphl == null) throw new ArgumentNullException(); * if (polygons.Count() != values.Count()) throw new ArgumentException("The number of elements in polygons is not equal to the number of elements in values"); * for (int Iterator = 1; Iterator <= polygons.Count(); Iterator++) * { * * graphl.FillPolygon(BrushForColor(ColFunc, values[Iterator - 1]), polygons[Iterator - 1].Apexes()); * } * }*/ /// <summary> /// Makes the color plot of the function FunVal in the area Area at the Graphl - the number of divisions along each from both axes is NDiv /// </summary> /// <param name="FunVal"></param> /// <param name="ColFunc"></param> /// <param name="Area"></param> /// <param name="TrMatrix">The matrix which will be used for making transformations of coordinates from the Area to the coordinate system in which the function will be drawn </param> static public void ColorFunc(ref Graphics Graphl, FuncOnPoint FOP, MyGraphOperations.ColorsFunc ColFunc, RectangleF Area, int NDiv, Matrix TrMatrix) { MyPointDouble LeftDownCor = new MyPointDouble(Area.Left, Area.Top, 0.0); MyPointDouble HorizStep = new MyPointDouble(Area.Width / NDiv, 0.0, 0.0); MyPointDouble VertStep = new MyPointDouble(0.0, Area.Height / NDiv, 0.0); MyPointDouble LeftDownCorPlot = LeftDownCor; MyPointDouble HorizStepPlot = HorizStep; MyPointDouble VertStepPlot = VertStep; MyPointDouble PtIter = new MyPointDouble(0.0, 0.0, 0.0); MyPointDouble PtIterPlot = new MyPointDouble(0.0, 0.0, 0.0); MyDrawing.TransformPoint(TrMatrix, ref LeftDownCorPlot); MyDrawing.TransformVector(TrMatrix, ref HorizStepPlot); MyDrawing.TransformVector(TrMatrix, ref VertStepPlot); double heightl = Area.Height / NDiv; double widthl = Area.Width / NDiv; //Matrix AddTransf = new Matrix(1.0F, 0.0F, 0.0F, 1.0F, 0.0F, 50.0F); for (int i = 1; i <= NDiv; i++) { for (int j = 1; j <= NDiv; j++) { PtIter = LeftDownCor + (i - 0.5) * HorizStep + (j - 0.5) * VertStep; PtIterPlot = LeftDownCorPlot + (i - 1.0) * HorizStepPlot + (j - 1) * VertStepPlot; //TransformPoint(AddTransf, ref PtIterPlot); RectangleF RecLoc = new RectangleF((float)(PtIterPlot.x), (float)(PtIterPlot.y), (float)HorizStepPlot.x, (float)VertStepPlot.y); Graphl.FillRectangle(BrushForColor(ColFunc, FOP(PtIter.x, PtIter.y)), RecLoc); } } }
private void button1_Click(object sender, EventArgs e) { MyDrawing.drawline(50, 20, 200, 20, bitmap, pictureBox1, Color.Green); }
private void tabPage3_Paint(object sender, PaintEventArgs e) { double max; float[] stringUpOrDown = new float[10]; string[] plusOrMinus = new string[10]; Graphics g = e.Graphics; g.TranslateTransform(this.tabPage3.AutoScrollPosition.X, tabPage3.AutoScrollPosition.Y);//GDI绘图时滚动条必要操作 m2 = 9549 * p / n; f2 = m2 * 2 / d; m1 = 9549 * p1 / n; f1 = m1 * 2 / d1; m = m2 - m1; f = m * 2 / d2; fby = (-f * Math.Cos(degree) + 4 * g2 + 2 * (3 * f1 + g1)) / 3; fay = -fby + f * Math.Cos(degree) + (3 * f1 + g1) + g2; g.DrawString("F1=" + Math.Round(f1, 2) + "N\nF2=" + Math.Round(f2, 2) + "N\nF=" + Math.Round(f, 2) + "N", font1, brush1, 10, 10); g.DrawString("Fay=" + Math.Round(fay, 2) + "N\nFby=" + Math.Round(fby, 2) + "N", font1, brush1, 200, 10); //扭矩图 g.DrawString("扭矩图", font2, brush1, 10, 200); MyDrawing.DrawXY(g, 100, 200); g.DrawString("Mx/(N•m)", font2, brush1, 100, 200 - 100 - 30); double M1PlusM = 100; double M = m * 100 / (m1 + m); for (int i = 0; i < 300; i++) { mx[i] = m; } for (int i = 300; i <= 500; i++) { mx[i] = m + m1; } PointF[] pt = new PointF[5] { new PointF(100, (float)(200 - M)), new PointF(100 + 300, (float)(200 - M)), new PointF(100 + 300, (float)(200 - M1PlusM)), new PointF(100 + 500, (float)(200 - M1PlusM)), new PointF(100 + 500, 200) }; g.DrawLines(pen2, pt); for (int i = 100; i <= 100 + 300; i += 10) { g.DrawLine(pen2, (float)i, 200, (float)i, (float)(200 - M)); } for (int i = 100 + 300; i <= 100 + 500; i += 10) { g.DrawLine(pen2, (float)i, 200, (float)i, (float)(200 - M1PlusM)); } g.DrawString("" + Math.Round(m, 2), font1, brush1, 100 + 100, (float)(200 - M - 20)); g.DrawString("" + Math.Round(m + m1, 2), font1, brush1, 100 + 400, (float)(200 - M1PlusM - 20)); //剪力图z double[] fqzSection = new double[4]; double[] fqzSectionRatio = new double[4]; fqzSection[0] = -f *Math.Cos(degree); fqzSection[1] = fqzSection[0] + fay; fqzSection[2] = fqzSection[1] - (3 * f1 + g1); fqzSection[3] = fqzSection[2] + fby; float x2 = 100, y2 = 200 + 250; MyDrawing.DrawXY(g, x2, y2); g.DrawString("剪力图z", font2, brush1, 10, y2); g.DrawString("Fq/N", font2, brush1, x2 + 5, y2 - 120); max = 0; for (int i = 0; i < 4; i++) { if (Math.Abs(fqzSection[i]) > max) { max = Math.Abs(fqzSection[i]); } if (fqzSection[i] > 0) { stringUpOrDown[i] = -20; } else { stringUpOrDown[i] = 5; } } for (int i = 0; i < 4; i++) { fqzSectionRatio[i] = fqzSection[i] * 100 / max; //g.DrawString(""+Math.Round(fqzSectionRatio)) } PointF[] ptFqz = new PointF[9] { new PointF(x2, (float)(y2 - fqzSectionRatio[0])), new PointF(x2 + 100, (float)(y2 - fqzSectionRatio[0])), new PointF(x2 + 100, (float)(y2 - fqzSectionRatio[1])), new PointF(x2 + 300, (float)(y2 - fqzSectionRatio[1])), new PointF(x2 + 300, (float)(y2 - fqzSectionRatio[2])), new PointF(x2 + 400, (float)(y2 - fqzSectionRatio[2])), new PointF(x2 + 400, (float)(y2 - fqzSectionRatio[3])), new PointF(x2 + 500, (float)(y2 - fqzSectionRatio[3])), new PointF(x2 + 500, y2) }; g.DrawLines(pen2, ptFqz); MyDrawing.DrawShodow(g, new PointF(x2, y2), ptFqz[1]); MyDrawing.DrawShodow(g, ptFqz[2], new PointF(x2 + 300, y2)); MyDrawing.DrawShodow(g, new PointF(x2 + 300, y2), ptFqz[5]); MyDrawing.DrawShodow(g, ptFqz[6], ptFqz[8]); g.DrawString("" + Math.Round(Math.Abs(fqzSection[0]), 2), font1, brush1, x2 + 10, (float)(y2 - fqzSectionRatio[0] + stringUpOrDown[0])); g.DrawString("" + Math.Round(Math.Abs(fqzSection[1]), 2), font1, brush1, x2 + 200, (float)(y2 - fqzSectionRatio[1] + stringUpOrDown[1])); g.DrawString("" + Math.Round(Math.Abs(fqzSection[2]), 2), font1, brush1, x2 + 300, (float)(y2 - fqzSectionRatio[2] + stringUpOrDown[2])); g.DrawString("" + Math.Round(Math.Abs(fqzSection[3]), 2), font1, brush1, x2 + 400, (float)(y2 - fqzSectionRatio[3] + stringUpOrDown[3])); //弯矩图z for (int i = 0; i < 501; i++) { double x = a * i / 100.0; if (i >= 0 && i <= 100) { mz[i] = fqzSection[0] * x; } else if (i > 100 && i <= 300) { mz[i] = mz[100] + fqzSection[1] * (x - a); } else if (i > 300 && i <= 400) { mz[i] = mz[300] + fqzSection[2] * (x - 3 * a); } else { mz[i] = mz[400] + fqzSection[3] * (x - 4 * a); } } double[] mzRatio = new double[6]; max = 0; for (int i = 0; i < 6; i++) { mzRatio[i] = mz[i * 100]; if (Math.Abs(mzRatio[i]) > max) { max = Math.Abs(mzRatio[i]); } if (mzRatio[i] > 0) { stringUpOrDown[i] = -20; } else { stringUpOrDown[i] = 5; } } for (int i = 0; i < 6; i++) { mzRatio[i] = mzRatio[i] * 100 / max; } float x3 = x2, y3 = y2 + 250; MyDrawing.DrawXY(g, x3, y3); g.DrawString("弯矩图z", font2, brush1, 10, y3); g.DrawString("Mz/(N·m)", font2, brush1, x3 + 5, y3 - 120); PointF[] ptMz = new PointF[6]; for (int i = 0; i < 6; i++) { ptMz[i] = new PointF(x3 + i * 100, y3 - (float)(mzRatio[i])); } g.DrawLines(pen2, ptMz); MyDrawing.DrawShadowM(g, x3, y3, mz, max); MyDrawing.DrawStringM(g, x3, y3, mz, stringUpOrDown, max); for (int i = 0; i < 4; i++) { if (fqzSection[i] >= 0) { plusOrMinus[i] = "+"; } else { plusOrMinus[i] = ""; } } g.DrawString("Mz在各区间大小分别为:\n\n" + "0≤x≤a: Mz=" + Math.Round(fqzSection[0], 2) + "x\n" + "a<x≤3a: Mz=" + Math.Round(mz[100], 2) + plusOrMinus[1] + Math.Round(fqzSection[1], 2) + "(x-a)\n" + "3a<x≤4a: Mz=" + Math.Round(mz[300], 2) + plusOrMinus[2] + Math.Round(fqzSection[2], 2) + "(x-3a)\n" + "4a<x≤5a: Mz=" + Math.Round(mz[400], 2) + plusOrMinus[3] + Math.Round(fqzSection[3], 2) + "(x-4a)", font1, brush1, x3, y3 + 120); //剪力图y fbz = (-f * Math.Sin(degree) + 12 * f2) / 3; faz = -fbz + f * Math.Sin(degree) + 3 * f2; g.DrawString("Faz=" + Math.Round(faz, 2) + "N", font1, brush1, 400, 10); g.DrawString("Fbz=" + Math.Round(fbz, 2) + "N", font1, brush1, 400, 30); float x4 = x3, y4 = y3 + 400; MyDrawing.DrawXY(g, x4, y4); g.DrawString("剪力图y", font2, brush1, 10, y4); g.DrawString("Fq/N", font2, brush1, x4 + 5, y4 - 120); double[] fqySection = new double[3]; double[] fqySectionRatio = new double[3]; fqySection[0] = -f *Math.Sin(degree); fqySection[1] = fqySection[0] + faz; fqySection[2] = fqySection[1] + fbz; max = 0; for (int i = 0; i < 3; i++) { if (Math.Abs(fqySection[i]) > max) { max = Math.Abs(fqySection[i]); } if (fqySection[i] > 0) { stringUpOrDown[i] = -20; } else { stringUpOrDown[i] = 5; } } for (int i = 0; i < 3; i++) { fqySectionRatio[i] = fqySection[i] * 100 / max; } PointF[] ptFqy = new PointF[7] { new PointF(x4, (float)(y4 - fqySectionRatio[0])), new PointF(x4 + 100, (float)(y4 - fqySectionRatio[0])), new PointF(x4 + 100, (float)(y4 - fqySectionRatio[1])), new PointF(x4 + 400, (float)(y4 - fqySectionRatio[1])), new PointF(x4 + 400, (float)(y4 - fqySectionRatio[2])), new PointF(x4 + 500, (float)(y4 - fqySectionRatio[2])), new PointF(x4 + 500, y4) }; g.DrawLines(pen2, ptFqy); MyDrawing.DrawShodow(g, new PointF(x4, y4), ptFqy[1]); MyDrawing.DrawShodow(g, ptFqy[2], new PointF(x4 + 400, y4)); MyDrawing.DrawShodow(g, new PointF(x2 + 400, y4), ptFqy[5]); g.DrawString("" + Math.Round(Math.Abs(fqySection[0]), 2), font1, brush1, x4 + 10, (float)(y4 - fqySectionRatio[0] + stringUpOrDown[0])); g.DrawString("" + Math.Round(Math.Abs(fqySection[1]), 2), font1, brush1, x4 + 200, (float)(y4 - fqySectionRatio[1] + stringUpOrDown[1])); g.DrawString("" + Math.Round(Math.Abs(fqySection[2]), 2), font1, brush1, x4 + 400, (float)(y4 - fqySectionRatio[2] + stringUpOrDown[2])); //弯矩图y for (int i = 0; i < 501; i++) { double x = a * i / 100.0; if (i >= 0 && i <= 100) { my[i] = fqySection[0] * x; } else if (i > 100 && i <= 400) { my[i] = my[100] + fqySection[1] * (x - a); } else { my[i] = my[400] + fqySection[2] * (x - 4 * a); } } double[] myRatio = new double[6]; max = 0; for (int i = 0; i < 6; i++) { myRatio[i] = my[i * 100]; if (Math.Abs(myRatio[i]) > max) { max = Math.Abs(myRatio[i]); } if (myRatio[i] > 0) { stringUpOrDown[i] = -20; } else { stringUpOrDown[i] = 5; } } for (int i = 0; i < 6; i++) { myRatio[i] = myRatio[i] * 100 / max; } float x5 = x4, y5 = y4 + 250; MyDrawing.DrawXY(g, x5, y5); g.DrawString("弯矩图y", font2, brush1, 10, y5); g.DrawString("My/(N·m)", font2, brush1, x5 + 5, y5 - 120); PointF[] ptMy = new PointF[6]; for (int i = 0; i < 6; i++) { ptMy[i] = new PointF(x5 + i * 100, y5 - (float)(myRatio[i])); } g.DrawLines(pen2, ptMy); MyDrawing.DrawShadowM(g, x5, y5, my, max); MyDrawing.DrawStringM(g, x5, y5, my, stringUpOrDown, max); for (int i = 0; i < 3; i++) { if (fqySection[i] >= 0) { plusOrMinus[i] = "+"; } else { plusOrMinus[i] = ""; } } g.DrawString("My在各区间大小分别为:\n\n" + "0≤x≤a: My=" + Math.Round(fqySection[0], 2) + "x\n" + "a<x≤4a: My=" + Math.Round(my[100], 2) + plusOrMinus[1] + Math.Round(fqySection[1], 2) + "(x-a)\n" + "4a<x≤5a: My=" + Math.Round(my[400], 2) + plusOrMinus[3] + Math.Round(fqySection[2], 2) + "(x-4a)", font1, brush1, x5, y5 + 120); }