Beispiel #1
0
        //
        //  Basic method to initialize the walkers to the source region defined
        //  by whatever ruleset is specified.
        //
        private void InitializeWalker(Walker new_walker)
        {
            int rndx = 100;
              int rndy = 100;

              switch(step_method)
              {
            default:
              { } break;
            // Random box is a box from the upper left corner (inset by 10x10) to
            // the lower left corner defined by the parameters in the UI. walkers
            // will randomly initialize anywhere in this region
            case StepMode.RANDOM_BOX:
              {
            rndx = rnd.Next(10, generate_x);
            rndy = rnd.Next(10, generate_y);
              } break;
            // Random horizontal line, walkers will initialize on a line at
            // generate_y, along the simulation region with a buffer of 50 pixels
            // on each side
            case StepMode.RANDOM_X_LINE:
              {
            rndx = rnd.Next(50, panel_width - 50);
            rndy = generate_y;
              } break;
            // Similar to RANDOM_X_LINE except a vertical line.
            case StepMode.RANDOM_Y_LINE:
              {
            rndx = generate_x;
            rndy = rnd.Next(50, panel_height - 50);
              } break;
            // ADVANCE_Y, starts a horizontal block of walkers, but moves up as
            // the simulation progresses. Initially I tried a horizontal line,
            // but it was slower and had issues, the box seems to work a lot better.
            case StepMode.ADVANCE_Y:
              {
            rndx = rnd.Next(50, panel_width - 50);
            rndy = rnd.Next(generate_y - 20, generate_y);
              } break;
            // ADVANCE_X is similar to ADVANCE_Y. It's tricky to get the parameters
            // right for this not to turn into a filled up source region. Remember to
            // keep the deposition rate low enough, and the number of particles right.
            case StepMode.ADVANCE_X:
              {
            rndx = rnd.Next(generate_x - 20, generate_x);
            rndy = rnd.Next(50, panel_height - 50);
              } break;
              }

              // Initialize the walker.
              new_walker.x = rndx;
              new_walker.y = rndy;
              new_walker.state = ParticleState.ALIVE;
        }
Beispiel #2
0
        //
        // Reset simply adjusts all the parameters, it will be called passing
        // the current UI values to the class.
        //
        public void Reset(uint num_particles, double set_up_prob, double set_down_prob, double set_left_prob,
                      double set_right_prob, int set_y_line, int set_x_line, int set_deposition_rate)
        {
            // Up/Down and Left/Right have independant probability spaces.
              //    Any undefined region of probability will cause the particle
              //    to not move along that axis (which gives us 8 possible
              //    nearest-neighbor sites.)
              up_probability = set_up_prob;
              down_probability = 1.0f - set_down_prob;
              left_probability = set_left_prob;
              right_probability =  1.0f - set_right_prob;

              // Pass parameters to the class
              walkers.Clear();
              number_of_walkers = num_particles;

              generate_x = set_x_line;
              generate_y = set_y_line;

              last_deposit_x = set_x_line;
              last_deposit_y = set_y_line;
              deposit_y = 500;
              deposit_x = 900;

              // Initialize the walkers
              for(int i = 0; i < number_of_walkers; i++)
              {
            Walker nwalk = new Walker(0,0);
            InitializeWalker(nwalk);
            walkers.Add(nwalk);
              }

              // Setup the initial cluster state
              //    Note, the cluster could also be setup as a
              //    list, which may lead to performance/memory
              //    improvements. However, coding time was
              //    a significt consideration, and it seemed
              //    easier/faster to impliment it this way.
              for (int i = 0; i < panel_height; i++)
              {
            for (int j = 0; j < panel_width; j++)
            {
              if (i == (panel_height - 50))
              {
            pixels[j, i] = true;
              }
              else
              {
            pixels[j, i] = false;
              }
            }
              }

              deposit_rate = set_deposition_rate;
              deposit_count = 0;

              current_step = 0;
        }