Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "graphics.hpp"
- #include <vector>
- #include <fstream>
- #include <iostream>
- #include <cstdlib>
- #include <math.h>
- using namespace std;
- using namespace genv;
- typedef vector<vector<int> > mat_t;
- int XX, YY;
- const int r=50;
- const int minmely=-10;
- const int maxmag=20;
- struct koord
- {
- int x,y;
- koord():x(0),y(0) {}
- koord(int _x, int _y):x(_x),y(_y) {}
- };
- void beolvas(mat_t &v, string file="terkep.txt")
- {
- ifstream fin(file);
- if(!fin.good())
- {
- cerr<<"Hoppa! Nincs meg a fajl, battya! :( \n";
- exit(1);
- }
- fin>>XX>>YY;
- v.resize(XX);
- for(size_t i=0; i<XX; ++i)
- {
- v[i].resize(YY);
- for(size_t j=0; j<YY; ++j)
- {
- fin>>v[i][j];
- }
- }
- }
- void kirajzol(const mat_t &v, canvas& c)
- {
- for(size_t i=0; i<v.size(); ++i)
- {
- for(size_t j=0; j<v[i].size(); ++j)
- {
- int g,b;
- int norm_h=127+v[i][j];
- g=norm_h;
- if(v[i][j]<0)
- {
- b=255+v[i][j];
- }
- else
- {
- b=0;
- }
- c<<move_to(i,j)<<color(0,g,b)<<dot;
- }
- }
- c<<refresh;
- }
- void tr(canvas& out, canvas& hatter)
- {
- out<<stamp(hatter,0,0);
- }
- void csomaglerakas(int x, int y, mat_t &terkep, mat_t &bejart)
- {
- if(x<0 || x>=XX || y<0 || y>YY || terkep[x][y]>=minmely || bejart[x][y]==1)
- {
- return;
- }
- bejart[x][y]=1;
- for(int i=-r; i<=r; i++)
- {
- for(int j=-r; j<=r; j++)
- {
- 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)
- {
- gout<<move_to(x+i,y+j)<<color(255,0,0)<<dot<<refresh;
- }
- }
- }
- }
- void szigetbejaras(int x, int y, mat_t &terkep)
- {
- mat_t bejart(XX,vector<int>(YY,0));
- csomaglerakas(x,y,terkep,bejart);
- }
- int main()
- {
- mat_t terkep;
- beolvas(terkep);
- gout.open(XX,YY);
- canvas hatter(XX,YY);
- kirajzol(terkep,hatter);
- tr(gout,hatter);
- gout<<refresh;
- event ev;
- while(genv::gin>>ev && ev.keycode!=key_escape)
- {
- if(ev.type==ev_mouse && ev.button==btn_left)
- {
- tr(gout,hatter);
- szigetbejaras(ev.pos_x, ev.pos_y, terkep);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement