Advertisement
Guest User

Untitled

a guest
May 29th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.44 KB | None | 0 0
  1. private void btn_Recryst_Next_Click(object sender, EventArgs e)
  2.         {
  3.             //OBLICZAMY RO DLA DANEGO KROKU CZASOWEGO I RO SREDNIE
  4.             ro_current = recryst_A / recryst_B + (1 - recryst_A / recryst_B) * Math.Exp(-recryst_B * recryst_t);
  5.             ro_average = ro_current / (_size * _size);
  6.             //LOSUJEMY 100 PUNKTOW I DODAJEMY IM RO ZALEZNE OD POZYCJI (GRANICA ZIARNA)
  7.             for (int c = 0; c < recryst_package; c++)
  8.             {
  9.                 uint x = Convert.ToUInt32(_rand.Next(0, _size - 1));
  10.                 uint y = Convert.ToUInt32(_rand.Next(0, _size - 1));
  11.                 if (!recryst[x, y])
  12.                 {
  13.                     if (bordering[x, y])
  14.                         ro[x, y] += Convert.ToDouble((_rand.Next(120, 180) / 100)) * ro_average;
  15.                     else
  16.                         ro[x, y] += Convert.ToDouble((_rand.Next(0, 30) / 100)) * ro_average;
  17.                 }
  18.             }
  19.             //PETLA AUTOMATOW KOMORKOWYCH
  20.             for (int i = 0; i < _size; i++)
  21.                 for(int j = 0; j < _size; j++)
  22.                 {
  23.                     if(!recryst[i, j])
  24.                     {
  25.                         //JEZELI RO DANEJ KOMORKI WIEKSZE OD KRYTYCZNEGO I JEST NA GRANICY ZIAREN
  26.                         if (ro[i, j] > ro_critical && bordering[i, j])
  27.                             addNewUniqueRecrystGrain(i, j); //grain recrystallizes at the end of this step
  28.                         //SPRAWDZ GRANICE DOOKOLA DANEJ KOMORKI - JEZELI JAKAS W SASIEDZTWIE ZREKRYSTALIZOWALA, OBECNA TEZ TO ROBI
  29.                         for (int m = i - Convert.ToInt32(neigh_radius); m < i + Convert.ToInt32(neigh_radius) + 1; m++)
  30.                             for (int n = j - Convert.ToInt32(neigh_radius); n < j + Convert.ToInt32(neigh_radius) + 1; n++)
  31.                             {
  32.                                 if (cb_Periodic.Checked)
  33.                                 {
  34.                                     if (neigh_PsRadius.Checked)
  35.                                     {
  36.                                         if (recryst[mod(m, _size), mod(n, _size)])
  37.                                             tempcolors.Add(color[mod(m, _size), mod(n, _size)]);
  38.                                     }
  39.                                     else
  40.                                     {
  41.                                         if (curr_table[table_iter])
  42.                                             if (recryst[mod(m, _size), mod(n, _size)])
  43.                                                 tempcolors.Add(color[mod(m, _size), mod(n, _size)]);
  44.                                     }
  45.                                 }
  46.                                 else
  47.                                 {
  48.                                     if (neigh_PsRadius.Checked)
  49.                                     {
  50.                                         if (m >= 0 && m < _size && n >= 0 && n < _size)
  51.                                             if (recryst[m, n])
  52.                                                 tempcolors.Add(color[m, n]);
  53.                                     }
  54.                                     else
  55.                                     {
  56.                                         if (m >= 0 && m < _size && n >= 0 && n < _size)
  57.                                             if (curr_table[table_iter])
  58.                                                 if (recryst[m, n])
  59.                                                     tempcolors.Add(color[m, n]);
  60.                                     }
  61.                                 }
  62.                                 table_iter++;
  63.                             }    
  64.                             table_iter = 0;
  65.                             if (tempcolors.Count > 0)
  66.                             {
  67.                                 Color mode = tempcolors.GroupBy(v => v).OrderByDescending(g => g.Count()).First().Key;
  68.                                 nextrecryst[i, j] = true;
  69.                                 nextcolor[i, j] = mode;
  70.                                 tempcolors.Clear();
  71.                             }
  72.                     }
  73.                 }
  74.             //PRZYPISZ WSZYSTKIE WARTOSCI
  75.             for (int i = 0; i < _size; i++)
  76.                 for (int j = 0; j < _size; j++)
  77.                 {
  78.                     recryst[i, j] = nextrecryst[i, j];
  79.                     color[i, j] = nextcolor[i, j];
  80.                     bmp.SetPixel(i, j, color[i, j]);
  81.                 }
  82.             //ZWIEKSZ KROK CZASOWY
  83.             recryst_t += 0.001;
  84.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement