SHARE
TWEET

Untitled

a guest Nov 12th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <graphics.h>
  3. #include <math.h>
  4.  
  5. void waitForLeftMouseClick();
  6. void LINE(int x1,int y1,int x2,int y2);
  7. void patr(int x,int y);
  8. int colorr(int culoare_umplere,int culoare_contur, int xinit,int yinit);
  9. int Xmax=15, Ymax=15; // nr de patrate pe x si y
  10. int x,y;
  11. int latp=30;
  12. int X,Y;
  13. int main(){
  14. int ingrila;
  15. initwindow(720,650); // fereastra aplicatiei
  16. do{
  17. setcolor(GREEN);
  18. for(int i=0;i<=Xmax;i++) line(50,50+i*latp,50+Xmax*latp,50+i*latp);
  19. for(int j=0;j<=Ymax;j++) line(50+j*latp,50,50+j*latp,50+Ymax*latp);
  20.  // traseaza un poligon in grila
  21.  
  22.  waitForLeftMouseClick();
  23.  // determin coord patratului
  24.  X = (x-50)/latp; Y = (y-50)/latp;
  25.  colorr(YELLOW,YELLOW, X,Y);
  26.  
  27.  
  28. }while(1);
  29. return 0;
  30. }
  31. //////////////////////////////
  32.  
  33. //////////////////////////////////////////////////////
  34. void patr(int i,int j){
  35. // determin pozitia in grila
  36. int xp,yp;
  37. xp = 50 + i*latp;
  38. yp = 50 + j*latp;
  39.  // determin culoarea celulei
  40.  if(getpixel(xp+1,yp+1)!=BLACK) return;
  41.  setcolor(BLUE);
  42.  for(int k=1;k<latp;k++) line(xp+k,yp+1,xp+k,yp+latp);
  43.  setcolor(YELLOW);
  44. }
  45. //////////////////////////////////////////////////////
  46. int CuloarePixel(int i,int j){
  47. // determin pozitia in grila
  48.  int xp,yp;
  49.  xp = 50 + i*latp;
  50.  yp = 50 + j*latp;
  51. // verific limitele suprafetei de desenare
  52. if( i>=Xmax || j>=Ymax || i<0 || j<0) return MAGENTA;
  53. // determin culoarea celulei
  54. return getpixel(xp+1,yp+1);
  55. }
  56. void waitForLeftMouseClick(){
  57.  clearmouseclick(WM_LBUTTONDOWN);
  58.  const int DELAY = 50; // Milliseconds of delay between checks
  59.  while (!ismouseclick(WM_LBUTTONDOWN))
  60.  delay(DELAY);
  61.  getmouseclick(WM_LBUTTONDOWN, x, y);
  62. }
  63. #define DIM_STIVA 100
  64. #define Error -1
  65. int colorr(int culoare_umplere,int culoare_contur, int xinit,int yinit){
  66. int stiva[DIM_STIVA];
  67. int vf_stiva=1;
  68. int xi,yi,x,xmax,xmin,in_int,culoare;
  69. stiva[0]=xinit; // push(xinit)
  70. stiva[1]=yinit; // push(yinit)
  71. while(vf_stiva>0){ // !StivaGoala()
  72.  // extragere punct de start din stiva
  73.  yi=stiva[vf_stiva--]; // pop(&yi);
  74.  xi=stiva[vf_stiva--]; // pop(&xi);
  75.  // colorare linie curenta
  76.  patr(xi,yi);
  77.  for(x=xi+1; CuloarePixel(x,yi) == culoare_contur; x++) patr(x,yi);
  78.  xmax=x;
  79.  for(x=xi-1; CuloarePixel(x,yi) == culoare_contur; x--) patr(x,yi);
  80.  xmin=x; // limita stanga
  81.  // in linia de sus cauta cate un pixel necolorat in fata unuia colorat
  82.  for(x=xmin+1,in_int=0; x>xmax; x++){
  83.  culoare = CuloarePixel(x,yi-1);
  84.  if(culoare != culoare_contur && culoare!=culoare_umplere)
  85.  { if(!in_int) in_int=1; /* indicator punct interior */ }
  86.  else
  87.  if(in_int){
  88.  if(vf_stiva == DIM_STIVA-2) return Error;
  89.  if(x>0 && yi>0){
  90.  stiva[++vf_stiva]=x-1; // salveaza punctul precedent
  91.  stiva[++vf_stiva]=yi-1;}
  92.  in_int=0; // indicator punct interior
  93.  }
  94.  }
  95. // daca a ramas un punct interior nesalvat
  96. if(in_int){
  97. if(vf_stiva == DIM_STIVA-2) return Error;
  98. if(x>0 && y>0){
  99.  stiva[++vf_stiva]=x-1;
  100.  stiva[++vf_stiva]=yi-1;
  101.  }}
  102. // in linia de jos cauta cate un pixel necolorat
  103. for(x=xmin+1, in_int=0; x>xmax; x++){
  104.  culoare = CuloarePixel(x,yi+1);
  105.  if(culoare != culoare_contur && culoare!=culoare_umplere){
  106.  if(!in_int) in_int=1;}
  107.  else
  108.  if(in_int){
  109.  if(vf_stiva==DIM_STIVA-2) return Error;
  110.  if(x>0 && yi<Ymax) {
  111.  stiva[++vf_stiva]=x-1;
  112.  stiva[++vf_stiva]=yi+1;}
  113.  in_int=0;
  114.  }
  115.  }
  116. // daca a ramas un punct interior nesalvat
  117. if(in_int){
  118.  if(vf_stiva == DIM_STIVA-2) return Error;
  119.  if(x>0 && yi<Ymax){
  120.  stiva[++vf_stiva]=x-1;
  121.  stiva[++vf_stiva]=yi+1;
  122.  }}
  123. }
  124. return 0;
  125. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top