Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void btn_Recryst_Next_Click(object sender, EventArgs e)
- {
- //OBLICZAMY RO DLA DANEGO KROKU CZASOWEGO I RO SREDNIE
- ro_current = recryst_A / recryst_B + (1 - recryst_A / recryst_B) * Math.Exp(-recryst_B * recryst_t);
- ro_average = ro_current / (_size * _size);
- //LOSUJEMY 100 PUNKTOW I DODAJEMY IM RO ZALEZNE OD POZYCJI (GRANICA ZIARNA)
- for (int c = 0; c < recryst_package; c++)
- {
- uint x = Convert.ToUInt32(_rand.Next(0, _size - 1));
- uint y = Convert.ToUInt32(_rand.Next(0, _size - 1));
- if (!recryst[x, y])
- {
- if (bordering[x, y])
- ro[x, y] += Convert.ToDouble((_rand.Next(120, 180) / 100)) * ro_average;
- else
- ro[x, y] += Convert.ToDouble((_rand.Next(0, 30) / 100)) * ro_average;
- }
- }
- //PETLA AUTOMATOW KOMORKOWYCH
- for (int i = 0; i < _size; i++)
- for(int j = 0; j < _size; j++)
- {
- if(!recryst[i, j])
- {
- //JEZELI RO DANEJ KOMORKI WIEKSZE OD KRYTYCZNEGO I JEST NA GRANICY ZIAREN
- if (ro[i, j] > ro_critical && bordering[i, j])
- addNewUniqueRecrystGrain(i, j); //grain recrystallizes at the end of this step
- //SPRAWDZ GRANICE DOOKOLA DANEJ KOMORKI - JEZELI JAKAS W SASIEDZTWIE ZREKRYSTALIZOWALA, OBECNA TEZ TO ROBI
- for (int m = i - Convert.ToInt32(neigh_radius); m < i + Convert.ToInt32(neigh_radius) + 1; m++)
- for (int n = j - Convert.ToInt32(neigh_radius); n < j + Convert.ToInt32(neigh_radius) + 1; n++)
- {
- if (cb_Periodic.Checked)
- {
- if (neigh_PsRadius.Checked)
- {
- if (recryst[mod(m, _size), mod(n, _size)])
- tempcolors.Add(color[mod(m, _size), mod(n, _size)]);
- }
- else
- {
- if (curr_table[table_iter])
- if (recryst[mod(m, _size), mod(n, _size)])
- tempcolors.Add(color[mod(m, _size), mod(n, _size)]);
- }
- }
- else
- {
- if (neigh_PsRadius.Checked)
- {
- if (m >= 0 && m < _size && n >= 0 && n < _size)
- if (recryst[m, n])
- tempcolors.Add(color[m, n]);
- }
- else
- {
- if (m >= 0 && m < _size && n >= 0 && n < _size)
- if (curr_table[table_iter])
- if (recryst[m, n])
- tempcolors.Add(color[m, n]);
- }
- }
- table_iter++;
- }
- table_iter = 0;
- if (tempcolors.Count > 0)
- {
- Color mode = tempcolors.GroupBy(v => v).OrderByDescending(g => g.Count()).First().Key;
- nextrecryst[i, j] = true;
- nextcolor[i, j] = mode;
- tempcolors.Clear();
- }
- }
- }
- //PRZYPISZ WSZYSTKIE WARTOSCI
- for (int i = 0; i < _size; i++)
- for (int j = 0; j < _size; j++)
- {
- recryst[i, j] = nextrecryst[i, j];
- color[i, j] = nextcolor[i, j];
- bmp.SetPixel(i, j, color[i, j]);
- }
- //ZWIEKSZ KROK CZASOWY
- recryst_t += 0.001;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement