Exemplo n.º 1
0
        public void repulsionPower(Particle [] array)
        {
           
                foreach (Particle i in array)
                {
                    if (!this.Equals(i))
                    {
                        var d = Math.Sqrt((this.xCoord - i.xCoord) * (this.xCoord - i.xCoord) +
                            (this.yCoord - i.yCoord) * (this.yCoord - i.yCoord));
                      
                        if (d <= 10)
                        {
                           
                            xSpeed += (xCoord - i.xCoord) / 8;
                            ySpeed += (yCoord - i.yCoord) / 8;
                            i.xSpeed -= (xCoord - i.xCoord) / 8;
                            i.ySpeed -= (yCoord - i.yCoord) / 8;
                        if (xSpeed > maxSpeed)
                            xSpeed = maxSpeed;
                        if (xSpeed < -maxSpeed)
                            xSpeed = -maxSpeed;
                        if (ySpeed > maxSpeed)
                            ySpeed = maxSpeed;
                        if (ySpeed < -maxSpeed)
                            ySpeed = -maxSpeed;


                        }
                    }
                }
            
        }
Exemplo n.º 2
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            pictureBox1.Refresh();
            Particle[] pr = new Particle[2];
            pr[0] = p1;
            pr[1] = p2;
            p1.Move(pictureBox1.Size);
            p2.Move(pictureBox1.Size);
            p1.repulsionPower(pr);

            drawPoint(Convert.ToInt32(p1.X), Convert.ToInt32(p1.Y), pictureBox1);
            drawPoint(Convert.ToInt32(p2.X), Convert.ToInt32(p2.Y), pictureBox1);

        }
Exemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            Random rnd = new Random();
            try {
                if (Convert.ToInt32(textBox1.Text) == 0)
                    throw new ArgumentException();
                p = new Particle[Convert.ToInt32(textBox1.Text)-1];
            }
            catch
            {
                MessageBox.Show("Перевірте введені данні", "Помилка", MessageBoxButtons.OK, MessageBoxIcon.Error);
               
                textBox1.ResetText();
                
                return;
            }
            for (int i = 0; i < p.Length; i++)
                p[i] = new Particle();
            pc = new ParticleWithCoord();


            int midle_speed = Convert.ToInt32(Math.Sqrt(3 * 0.013 * trackBar1.Value));

            for (int j = 0; j < p.Length; j++)
            {
                p[j].SetMaxSpeed = midle_speed+1;
                p[j].X = rnd.Next(pictureBox1.Width);
                p[j].Y = rnd.Next(pictureBox1.Height);
                p[j].X_Speed = rnd.Next(-midle_speed, midle_speed);
                p[j].Y_Speed = rnd.Next(-midle_speed, midle_speed);

                drawPoint(Convert.ToInt32(p[j].X), Convert.ToInt32(p[j].Y), this.pictureBox1);
               
            }
            pc.SetMaxSpeed = midle_speed + 1;
            pc.X = rnd.Next(700);
            pc.Y = rnd.Next(350);
            pc.X_Speed = rnd.Next(-midle_speed, midle_speed);
            pc.Y_Speed = rnd.Next(-midle_speed, midle_speed);

            drawPoint(Convert.ToInt32(pc.X), Convert.ToInt32(pc.Y), this.pictureBox1);
            button2.Enabled = true;

            // 
        }