MetaField.cpp 772 B

1234567891011121314151617181920212223242526272829303132333435
  1. //
  2. // Created by jovian on 09/10/17.
  3. //
  4. #include "MetaField.h"
  5. MetaField::MetaField() {
  6. clean();
  7. }
  8. void MetaField::clean() {
  9. for (int i(0); i < WIN_H; i++)
  10. for (int j(0); j < WIN_W; j++) {
  11. m_field[i][j] = 0.0;
  12. }
  13. }
  14. void MetaField::binary(bool mat[WIN_H][WIN_W], float ceil) {
  15. for (int i(0); i < WIN_H; i++)
  16. for (int j(0); j < WIN_W; j++) {
  17. mat[i][j] = (m_field[i][j] > ceil);
  18. }
  19. }
  20. void MetaField::disturb(int y, int x, float weight) {
  21. // Escape
  22. if (x < 0 || x >= WIN_W || y < 0 || y >= WIN_H)
  23. return;
  24. // todo Disturb
  25. for (int i(0); i < WIN_H; i++)
  26. for (int j(0); j < WIN_W; j++) {
  27. m_field[i][j] += weight / ((y - i)*(y - i) + (x - j)*(x - j));
  28. }
  29. }