Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. #include "graphics.hpp"
  2. #include <vector>
  3. #include <fstream>
  4. #include <iostream>
  5. #include <cstdlib>
  6. #include <math.h>
  7.  
  8. using namespace std;
  9. using namespace genv;
  10.  
  11. typedef vector<vector<int> > mat_t;
  12.  
  13. int XX, YY;
  14. const int r=50;
  15. const int minmely=-10;
  16. const int maxmag=20;
  17.  
  18. struct koord
  19. {
  20. int x,y;
  21. koord():x(0),y(0) {}
  22. koord(int _x, int _y):x(_x),y(_y) {}
  23. };
  24.  
  25. void beolvas(mat_t &v, string file="terkep.txt")
  26. {
  27. ifstream fin(file);
  28. if(!fin.good())
  29. {
  30. cerr<<"Hoppa! Nincs meg a fajl, battya! :( \n";
  31. exit(1);
  32. }
  33. fin>>XX>>YY;
  34. v.resize(XX);
  35. for(size_t i=0; i<XX; ++i)
  36. {
  37. v[i].resize(YY);
  38. for(size_t j=0; j<YY; ++j)
  39. {
  40. fin>>v[i][j];
  41. }
  42. }
  43. }
  44.  
  45. void kirajzol(const mat_t &v, canvas& c)
  46. {
  47. for(size_t i=0; i<v.size(); ++i)
  48. {
  49. for(size_t j=0; j<v[i].size(); ++j)
  50. {
  51. int g,b;
  52. int norm_h=127+v[i][j];
  53. g=norm_h;
  54. if(v[i][j]<0)
  55. {
  56. b=255+v[i][j];
  57. }
  58. else
  59. {
  60. b=0;
  61. }
  62. c<<move_to(i,j)<<color(0,g,b)<<dot;
  63. }
  64. }
  65.  
  66. c<<refresh;
  67. }
  68.  
  69. void tr(canvas& out, canvas& hatter)
  70. {
  71. out<<stamp(hatter,0,0);
  72. }
  73.  
  74. void csomaglerakas(int x, int y, mat_t &terkep, mat_t &bejart)
  75. {
  76. if(x<0 || x>=XX || y<0 || y>YY || terkep[x][y]>=minmely || bejart[x][y]==1)
  77. {
  78. return;
  79. }
  80.  
  81. bejart[x][y]=1;
  82.  
  83. for(int i=-r; i<=r; i++)
  84. {
  85. for(int j=-r; j<=r; j++)
  86. {
  87. if(x+i<0 || x+i>=XX || y+j<0 || y+j>YY || terkep[x+i][y+j]<=maxmag && terkep[x+i][y+j]>0 && i*i+j*j<=r*r)
  88. {
  89. gout<<move_to(x+i,y+j)<<color(255,0,0)<<dot<<refresh;
  90. }
  91. }
  92. }
  93. }
  94.  
  95. void szigetbejaras(int x, int y, mat_t &terkep)
  96. {
  97. mat_t bejart(XX,vector<int>(YY,0));
  98. csomaglerakas(x,y,terkep,bejart);
  99. }
  100.  
  101. int main()
  102. {
  103. mat_t terkep;
  104. beolvas(terkep);
  105.  
  106. gout.open(XX,YY);
  107. canvas hatter(XX,YY);
  108. kirajzol(terkep,hatter);
  109. tr(gout,hatter);
  110. gout<<refresh;
  111.  
  112. event ev;
  113.  
  114. while(genv::gin>>ev && ev.keycode!=key_escape)
  115. {
  116. if(ev.type==ev_mouse && ev.button==btn_left)
  117. {
  118. tr(gout,hatter);
  119. szigetbejaras(ev.pos_x, ev.pos_y, terkep);
  120. }
  121. }
  122.  
  123. return 0;
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement