Exemplo n.º 1
0
        double timeStep; //timestep for solution incrementation

        #endregion Fields

        #region Constructors

        public MainWindow()
        {
            InitializeComponent();
            rand = new Random();

            timer = new DispatcherTimer();
            timer.Tick += new EventHandler(timer_Tick);
            timer.Interval = TimeSpan.FromMilliseconds(100);

            tbXseed.Text = string.Format("{0}", rand.Next(371, 379));
            tbYseed.Text = string.Format("{0}", rand.Next(380, 388));
            tbNumParticles.Text = "20";

            //draw the initalisation particle
            Particle p = new Particle(Convert.ToInt32(tbXseed.Text), Convert.ToInt32(tbYseed.Text), 0, 0, Particle.ParticleType.fixedParticle);
            seedParticle = CreateRectangle(red);
            PaintCanvas.Children.Add(seedParticle);
            Canvas.SetTop(seedParticle, p.position.Y - 2);
            Canvas.SetLeft(seedParticle, p.position.X - 2);
        }
Exemplo n.º 2
0
        private void btCreate_Click(object sender, RoutedEventArgs e)
        {
            int particleDistance = 5; //initial distance between particles
            particleList = new List<Particle>();
            particleGridWidth = Convert.ToInt32(tbNumParticles.Text);
            int firstParticleX = (((int)PaintCanvas.ActualWidth - (particleDistance * particleGridWidth)) / 2);
            int firstParticleY = (((int)PaintCanvas.ActualHeight - (particleDistance * (particleGridWidth + 20))) / 2);

            //set the seed particle
            seed = new Particle(Convert.ToInt32(tbXseed.Text), Convert.ToInt32(tbYseed.Text), 0, 0, Particle.ParticleType.fixedParticle);
            particleList.Add(seed);

            //fill the list of particles with non-fixed particles
            for (i = firstParticleX; i < (firstParticleX + particleGridWidth * particleDistance); i += particleDistance)
                for (j = firstParticleY; j < (firstParticleY + (particleDistance * (particleGridWidth + 20))); j += particleDistance)
                {
                    if (i > (Convert.ToInt32(tbXseed.Text) - 5) && i < (Convert.ToInt32(tbXseed.Text) + 5) && j > (Convert.ToInt32(tbYseed.Text) - 5) && j < (Convert.ToInt32(tbYseed.Text) + 5))
                        continue;
                    Particle p = new Particle((i + rand.Next(-2, 3)), (j + rand.Next(-2, 3)), 0, 0, Particle.ParticleType.freeParticle);
                    particleList.Add(p);
                }

            //render the initial scene
            foreach (var particle in particleList)
            {
                Rectangle rect;
                if (particle.pType == Particle.ParticleType.freeParticle)
                    rect = CreateRectangle(blue);
                else rect = CreateRectangle(red);
                PaintCanvas.Children.Add(rect);
                Canvas.SetTop(rect, particle.position.Y - 2);
                Canvas.SetLeft(rect, particle.position.X - 2);
            }

            //set initial conditions for brownian motion calculations
            mass = 2.325E-27;
            Temp = 300;
            relaxTime = 1;
            timeStep = (double)(1.0 / 30.0);

            //start timer
            timer.Start();
        }