コード例 #1
0
ファイル: Form1.cs プロジェクト: a-samoylov/Doodle
        private void pictureBoxMain_MouseClick(object sender, MouseEventArgs e)
        {
            //остановка кругов
            foreach (Circlecs circl in circlesList)
            {
                if (circl.MouseEnter(e.X, e.Y) == true)
                {
                    if (circl.Move == true)
                    {
                        circl.Move = false;
                    }
                    else
                    {
                        circl.Move = true;
                    }
                    return;
                }
            }

            if (e.X < 150 || e.X > pictureBoxMain.Size.Width - 150 || e.Y < 150 || e.Y > pictureBoxMain.Size.Height - 150)
            {
                return;                                                                                                             //для создания кругов в центре экрана
            }
            Random   rand   = new Random();
            int      radius = rand.Next(50, 100);
            Circlecs c      = new Circlecs(rand.Next(3, 8), rand.Next(0, 361), e.X - radius, e.Y - radius, radius,
                                           Color.FromArgb(120, rand.Next(1, 255), rand.Next(5, 255), rand.Next(1, 255)), pictureBoxMain.Size);

            //foreach (Circlecs circl in circlesList)//дополнительная проверка на пересечение с другими кругами
            //    if (c.SmashCirles(circl) == true) return;
            circlesList.Add(c);
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: a-samoylov/Doodle
        private void ChangeTrajectory(Circlecs circl1, Circlecs circl2)
        {
            //circl2.Dx = circl1.Dx;
            //circl2.Dy = circl1.Dy;
            //double d = Math.Sqrt(Math.Pow(circl1.X + circl2.X, 2) + Math.Pow(circl1.Y + circl2.Y, 2));//растояние между центрами кругов
            //double sinL = Math.Abs(circl1.Y - circl2.Y) / d,
            //       cosL = Math.Abs(circl1.X - circl2.X) / d;

            //double Vn1 = circl1.Dx * cosL + circl1.Dy * sinL,
            //       Vt1 = circl1.Dy * cosL - circl1.Dx * sinL;

            //double Vn2 = circl2.Dx * cosL + circl2.Dy * sinL,
            //       Vt2 = circl2.Dy * cosL - circl2.Dx * sinL;

            //Swap(ref Vn1, ref Vn2);

            //circl1.Dx = (int)Math.Round(Vn1 * cosL - Vt1 * sinL);
            //circl1.Dy = (int)Math.Round(Vn1 * sinL + Vt1 * cosL);

            //circl2.Dx = (int)Math.Round(Vn2 * cosL - Vt2 * sinL);
            //circl2.Dy = (int)Math.Round(Vn2 * sinL + Vt2 * cosL);
        }
コード例 #3
0
 public double SmashDistansCirles(Circlecs cirlc)//растояние между шарами
 {
     return(Math.Abs(Math.Sqrt(Math.Pow(x + radius - cirlc.x - cirlc.Radius, 2) + Math.Pow(y + radius - cirlc.y - cirlc.Radius, 2)) - (radius + cirlc.Radius)));
 }
コード例 #4
0
 public Boolean SmashCirles(Circlecs cirlc)//столкновение шаров
 {
     return(Math.Sqrt(Math.Pow(x + radius - cirlc.x - cirlc.Radius, 2) + Math.Pow(y + radius - cirlc.y - cirlc.Radius, 2)) <= radius + cirlc.Radius + (Math.Sqrt(Dx * Dx + Dy * Dy) + Math.Sqrt(cirlc.Dx * cirlc.Dx + cirlc.Dy * cirlc.Dy)) * 0.1);
 }