Пример #1
0
        public void deletePointFromArPoints(int delInd)
        {
            if (arPoints == null || moveDir == null)
            {
                cout("Error");
                return;
            }

            //delete point from arPoints
            PointF[] newArPoints = new PointF[arPoints.Length - 1];

            for (int i = 0; i < delInd; i++)
            {
                newArPoints[i] = arPoints[i];
            }
            for (int i = delInd; i < newArPoints.Length; i++)
            {
                newArPoints[i] = arPoints[i + 1];
            }

            arPoints = newArPoints;
            if (arPoints.Length == 0)
            {
                arPoints = null;
            }

            //delete point from moveDir
            Direct[] newMoveDir = new Direct[moveDir.Length - 1];

            for (int i = 0; i < delInd; i++)
            {
                newMoveDir[i] = moveDir[i];
            }
            for (int i = delInd; i < newMoveDir.Length; i++)
            {
                newMoveDir[i] = moveDir[i + 1];
            }

            moveDir = newMoveDir;
            if (moveDir.Length == 0)
            {
                moveDir = null;
                if (modeMovePoints)
                {
                    modeMovePoints     = false;
                    btnMovePoints.Text = "Move points: OFF";
                    cout("Move points: OFF");
                    moveTimer.Stop();
                }
            }
        }
Пример #2
0
        public void setRandomSpeedToAll()
        {
            if (moveDir != null)
            {
                Random rand      = new Random();
                int    InitX     = rand.Next(INIT_STEP_X_MIN, INIT_STEP_X_MAX + 1);
                int    InitY     = rand.Next(INIT_STEP_Y_MIN, INIT_STEP_Y_MAX + 1);
                float  InitSpeed = (float)(rand.Next((int)(INIT_SPEED_MIN * 2 + 1), (int)(INIT_SPEED_MAX * 2 + 1))) / 2;

                for (int i = 0; i < moveDir.Length; i++)
                {
                    moveDir[i] = new Direct(InitSpeed, InitX, InitY);
                }
            }
        }
Пример #3
0
        public void setRealRandomSpeedToAll()
        {
            if (moveDir != null)
            {
                Random rand = new Random();

                for (int i = 0; i < moveDir.Length; i++)
                {
                    float InitSpeed = 0;
                    int   InitX     = 0;
                    int   InitY     = 0;
                    getRealRandomSpeed(rand, ref InitSpeed, ref InitX, ref InitY);

                    moveDir[i] = new Direct(InitSpeed, InitX, InitY);
                }
            }
        }
Пример #4
0
        public void setManyPoints()
        {
            arPoints = null;
            moveDir  = null;

            setPointsCount(-pointsCount);

            // calculate actual borders
            int leftBorder   = leftMargin;
            int rightBorder  = form.Width - rightMargin - pointWidth / 2;
            int topBorder    = topMargin;
            int bottomBorder = form.Height - bottomMargin - pointWidth / 2;

            //calculate rows and columns
            int Delta = 10;

            if (pointWidth >= 6)
            {
                Delta = pointWidth * 2;
            }


            int cols = (rightBorder - leftBorder) / Delta;
            int rows = (bottomBorder - topBorder) / Delta;

            cout((cols * rows).ToString() + " points added");
            setPointsCount(cols * rows);

            arPoints = new PointF[cols * rows];
            moveDir  = new Direct[cols * rows];

            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    arPoints[i * cols + j] = new PointF(leftBorder + Delta * (j + 1),
                                                        topBorder + Delta * (i + 1));

                    moveDir[i * cols + j] = new Direct(moveInitSpeed, moveInitStepX, moveInitStepY);
                }
            }

            Refresh();
        }
Пример #5
0
        private void Form1_MouseClick(object sender, MouseEventArgs e)
        {
            if (modeAddPoints && e.Button == MouseButtons.Left)
            {
                PointF p1 = e.Location;

                float realX = p1.X;
                float realY = p1.Y;

                //checking for out of margin zone
                if (realX < leftMargin + pointWidth / 2)
                {
                    realX = leftMargin + pointWidth / 2;
                }
                else if (realX > form.Width - rightMargin - pointWidth / 2)
                {
                    realX = form.Width - rightMargin - pointWidth / 2;
                }

                if (realY < topMargin + pointWidth / 2)
                {
                    realY = topMargin + pointWidth / 2;
                }
                else if (realY > form.Height - bottomMargin - pointWidth / 2)
                {
                    realY = form.Height - bottomMargin - pointWidth / 2;
                }

                PointF realP1 = new PointF(realX, realY);
                cout(realP1.ToString() + " added");

                setPointsCount(1);

                if (arPoints == null)
                {
                    arPoints = new PointF[] { realP1 };

                    // create helper array for directions of points
                    if (modeMoveInitPointsRandom)
                    {
                        float InitSpeed = 0;
                        int   InitX     = 0;
                        int   InitY     = 0;
                        getRealRandomSpeed(new Random(), ref InitSpeed, ref InitX, ref InitY);

                        moveDir = new Direct[] { new Direct(InitSpeed, InitX, InitY) };
                    }
                    else
                    {
                        moveDir = new Direct[] { new Direct(moveInitSpeed, moveInitStepX, moveInitStepY) };
                    }

                    moveDir = new Direct[] { new Direct(moveInitSpeed, moveInitStepX, moveInitStepY) };
                }
                else
                {
                    PointF[] newArPoints = new PointF[arPoints.Length + 1];
                    newArPoints[arPoints.Length] = realP1;

                    for (int i = 0; i < arPoints.Length; i++)
                    {
                        newArPoints[i] = arPoints[i];
                    }
                    arPoints = newArPoints;

                    // update helper array for directions of points
                    Direct[] newMoveDir = new Direct[moveDir.Length + 1];

                    if (modeMoveInitPointsRandom)
                    {
                        float InitSpeed = 0;
                        int   InitX     = 0;
                        int   InitY     = 0;
                        getRealRandomSpeed(new Random(), ref InitSpeed, ref InitX, ref InitY);

                        newMoveDir[moveDir.Length] = new Direct(InitSpeed, InitX, InitY);
                    }
                    else
                    {
                        newMoveDir[moveDir.Length] = new Direct(moveInitSpeed, moveInitStepX, moveInitStepY);
                    }

                    // copying old values
                    for (int i = 0; i < moveDir.Length; i++)
                    {
                        newMoveDir[i] = moveDir[i];
                    }
                    moveDir = newMoveDir;
                }


                Refresh();
            }

            if (e.Button == MouseButtons.Right)
            {
                // ON/OFF modeAddPoints / dragPoints
                if (modeAddPoints == false)
                {
                    modeAddPoints  = true;
                    btnPoints.Text = "Add points: ON";
                    cout("Add points: ON");
                    cout("Drag points: OFF");
                }
                else
                {
                    modeAddPoints  = false;
                    btnPoints.Text = "Add points: OFF";
                    cout("Add points: OFF");
                    cout("Drag points: ON");
                }
            }

            if (e.Button == MouseButtons.Middle && arPoints != null)
            {
                PointF delPoint = e.Location;

                for (int i = 0; i < arPoints.Length; i++)
                {
                    if (IsOnPoint(delPoint, arPoints[i]))
                    {
                        PointF deletedPoint = new PointF(arPoints[i].X, arPoints[i].Y);

                        cout(deletedPoint.ToString() + " deleted");
                        deletePointFromArPoints(i);
                        setPointsCount(-1);

                        Refresh();

                        break;
                    }
                }
            }
        }