コード例 #1
0
        private void animation_btn_Click(object sender, EventArgs e)
        {
            List <BezierCurve> buildList     = anchorFigure.bezierCurves;
            List <BezierCurve> dist          = new List <BezierCurve>();
            List <BezierCurve> anotherFigure = AnimationCurves();

            for (int i = 0; i < anchorFigure.bezierCurves.Count; i++)
            {
                MyPoint newS = new MyPoint(anchorFigure.bezierCurves[i].StartPoint.X - anotherFigure[i].StartPoint.X, anchorFigure.bezierCurves[i].StartPoint.Y - anotherFigure[i].StartPoint.Y);
                MyPoint newM = new MyPoint(anchorFigure.bezierCurves[i].MiddlePoint.X - anotherFigure[i].MiddlePoint.X, anchorFigure.bezierCurves[i].MiddlePoint.Y - anotherFigure[i].MiddlePoint.Y);
                MyPoint newE = new MyPoint(anchorFigure.bezierCurves[i].EndPoint.X - anotherFigure[i].EndPoint.X, anchorFigure.bezierCurves[i].EndPoint.Y - anotherFigure[i].EndPoint.Y);

                dist.Add(new BezierCurve(newS, newM, newE));
            }
            int itr = 30;

            for (int i = 0; i < itr; i++)
            {
                for (int j = 0; j < buildList.Count; j++)
                {
                    MyPoint newS = new MyPoint(buildList[j].StartPoint.X - dist[j].StartPoint.X / itr, buildList[j].StartPoint.Y - dist[j].StartPoint.Y / itr);
                    MyPoint newM = new MyPoint(buildList[j].MiddlePoint.X - dist[j].MiddlePoint.X / itr, buildList[j].MiddlePoint.Y - dist[j].MiddlePoint.Y / itr);
                    MyPoint newE = new MyPoint(buildList[j].EndPoint.X - dist[j].EndPoint.X / itr, buildList[j].EndPoint.Y - dist[j].EndPoint.Y / itr);

                    buildList[j] = new BezierCurve(newS, newM, newE);
                    buildList[j].Validate();
                }
                AnchorFigure af = new AnchorFigure(buildList);
                DrawAnchor(af);
                pictureBox1.Update();
            }
        }
コード例 #2
0
        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            width_label.Text  = $"Width: {e.X}";
            height_label.Text = $"Height: {e.Y}";
            if (!DGVEmpty && !IsMouseDown)
            {
                minIndex = NearestPoint(anchorFigure.bezierCurves, new PointF(e.X, e.Y));
                Bitmap   bmp      = new Bitmap(figBmp);
                Graphics graphics = Graphics.FromImage(bmp);
                graphics.DrawRectangle(new Pen(Color.Red, 1), n.X - 3, n.Y - 3, 6, 6);
                pictureBox1.Image = bmp;
            }
            if (!IsMouseDown)
            {
                return;
            }
            float xMove = e.X - prevMousePos.X;
            float yMove = e.Y - prevMousePos.Y;
            List <BezierCurve> bezCur = anchorFigure.bezierCurves;

            switch (minIndex[1])
            {
            case 1:
                bezCur[minIndex[0]].StartPoint.X += xMove;
                bezCur[minIndex[0]].StartPoint.Y += yMove;
                break;

            case 2:
                bezCur[minIndex[0]].MiddlePoint.X += xMove;
                bezCur[minIndex[0]].MiddlePoint.Y += yMove;
                break;

            case 3:
                bezCur[minIndex[0]].EndPoint.X += xMove;
                bezCur[minIndex[0]].EndPoint.Y += yMove;
                break;
            }
            prevMousePos = new PointF(e.X, e.Y);
            bezCur[minIndex[0]].Validate();
            anchorFigure = new AnchorFigure(bezCur);
            DrawAnchor(anchorFigure);
            pictureBox1.Update();
            //bezierCurvesInfo_dgv.Update();
        }
コード例 #3
0
        private void DrawAnchor(AnchorFigure aF)
        {
            Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            //Graphics graphics = pictureBox1.CreateGraphics();
            Graphics graphics = Graphics.FromImage(bmp);

            graphics.Clear(Color.White);
            //graphics.DrawImage(Properties.Resources.u, new Point(0, 0));

            for (int i = 0; i < aF.AnchorToBuild.Count; i++)
            {
                if (!aF.AnchorToBuild[i].NewStart)
                {
                    graphics.DrawLine(new Pen(Color.Red, 2), aF.AnchorToBuild[i - 1].GetPoint(), aF.AnchorToBuild[i].GetPoint());
                }
                //Thread.Sleep(2);
            }
            bezierCurvesInfo_dgv.Rows.Clear();

            int curveNumber = 0;

            foreach (BezierCurve bc in aF.bezierCurves)
            {
                curveNumber++;
                DataGridViewRow newRow = new DataGridViewRow();
                bezierCurvesInfo_dgv.Rows.Add(curveNumber, bc.StartPoint.X, bc.StartPoint.Y, bc.MiddlePoint.X, bc.MiddlePoint.Y, bc.EndPoint.X, bc.EndPoint.Y);
                DGVEmpty = false;
                if (drawPoints_chb.Checked)
                {
                    graphics.DrawLine(new Pen(Color.Gray, 1), bc.StartPoint.GetPoint(), bc.MiddlePoint.GetPoint());
                    graphics.DrawLine(new Pen(Color.Gray, 1), bc.MiddlePoint.GetPoint(), bc.EndPoint.GetPoint());
                    graphics.DrawRectangle(new Pen(Color.Gray, 1), bc.StartPoint.X - 2, bc.StartPoint.Y - 2, 4, 4);
                    graphics.DrawRectangle(new Pen(Color.Gray, 1), bc.MiddlePoint.X - 2, bc.MiddlePoint.Y - 2, 4, 4);
                    //graphics.DrawString(curveNumber.ToString(), new Font("Calibri", 12), Brushes.Gray, bc.MiddlePoint.X + 4, bc.MiddlePoint.Y + 4);

                    graphics.DrawRectangle(new Pen(Color.Gray, 1), bc.EndPoint.X - 2, bc.EndPoint.Y - 2, 4, 4);
                }
            }
            pictureBox1.Image = bmp;
            figBmp            = bmp;
        }
コード例 #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            List <BezierCurve> bezierCurvesToBuild = new List <BezierCurve>();

            if (!DGVEmpty)
            {
                for (int i = 0; i < bezierCurvesInfo_dgv.Rows.Count - 1; i++)
                {
                    MyPoint sp = new MyPoint
                    {
                        X = (float)Convert.ToDouble(bezierCurvesInfo_dgv.Rows[i].Cells[1].Value),
                        Y = (float)Convert.ToDouble(bezierCurvesInfo_dgv.Rows[i].Cells[2].Value)
                    };

                    MyPoint mp = new MyPoint
                    {
                        X = (float)Convert.ToDouble(bezierCurvesInfo_dgv.Rows[i].Cells[3].Value),
                        Y = (float)Convert.ToDouble(bezierCurvesInfo_dgv.Rows[i].Cells[4].Value)
                    };

                    MyPoint ep = new MyPoint
                    {
                        X = (float)Convert.ToDouble(bezierCurvesInfo_dgv.Rows[i].Cells[5].Value),
                        Y = (float)Convert.ToDouble(bezierCurvesInfo_dgv.Rows[i].Cells[6].Value)
                    };
                    BezierCurve bc = new BezierCurve(sp, mp, ep);
                    bezierCurvesToBuild.Add(bc);
                }
                anchorFigure = new AnchorFigure(bezierCurvesToBuild);
            }
            else
            {
                anchorFigure = new AnchorFigure();
            }


            DrawAnchor(anchorFigure);


            //pictureBox1.Image = bmp;
        }