Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. #include "graphics.hpp"
  2. #include <cstdlib>
  3. #include <vector>
  4. using namespace genv;
  5. //megynitott képernyõ mérete:
  6. const int X = 300, Y = 300;
  7.  
  8. struct kor{
  9. //Kor struct. Adatmezok:
  10. int o_x, o_y, radius; //Kor kozeppontja es sugara.
  11. int c_r, c_g, c_b; //Kor szine.
  12. // konstruktor:
  13. kor(){//default konstruktor. Mindig meg kell irni!!!
  14. o_x = X/2;
  15. o_y = Y/2;
  16. radius = rand()%10+10;
  17. c_r = rand()%255;
  18. c_g = rand()%255;
  19. c_b = rand()%255;
  20. }
  21. kor(int _o_x, int _o_y){
  22. //Beallitja a kor kozeppontjat a kapott koordinatakra es a tobbi parameteret random ertekekre.
  23. o_x = _o_x;
  24. o_y = _o_y;
  25. radius = rand()%10+10;
  26. c_r = rand()%255;
  27. c_g = rand()%255;
  28. c_b = rand()%255;
  29. }
  30. //konstruktorok inicializalo sorral:
  31. //: es a { kozti resznel mezonev(ertek) stilusban inicializalja a mezok ertekeit.
  32. //szep hasznos(es rovidebb is:P) es van amit csak ilyen stilusban lehet megoldani (tipikusan ilyen: konstans mezok inicializalasa)
  33. kor(int _o_x, int _o_y, int _r, int _g, int _b): o_x(_o_x), o_y(_o_y), c_r(_r), c_g(_g), c_b(_b){
  34. radius = rand()%10+10;
  35. }
  36. kor(int _o_x, int _o_y, int _rad, int _r, int _g, int _b):
  37. o_x(_o_x), o_y(_o_y), radius(_rad), c_r(_r), c_g(_g), c_b(_b){}
  38. //Tagfuggvenyek:
  39.  
  40. void kirajzol(){
  41. //kirajzolo metodus.
  42. gout << color(c_r,c_g,c_b);
  43. for(int i = -radius; i < radius; ++i){
  44. for(int j = -radius; j < radius; ++j){
  45. //Akkor rajzolunk ki amikor a kor sugaran belul vagyunk es a kepernyon van a keppont.
  46. if(i*i+j*j < radius*radius && i+o_x < X && i+o_x >= 0 && j+o_y < Y && j+o_y >=0){
  47. gout << move_to(i+o_x,j+o_y) << dot;
  48. }
  49. }
  50. }
  51. }
  52.  
  53. void mozog(){
  54. //mozgato fv.
  55. o_x += rand()%5-2;
  56. // ha kicsuszik a kepernyon akkor visszateszi a tuloldalt. ekvivalens: if(o_x >= X || o_x < 0) o_x =(X+o_x)%X;
  57. if(o_x > X) o_x -= X;
  58. else if(o_x < 0) o_x += X;
  59.  
  60. o_y += rand()%4-1;
  61. // ha kicsuszik a kepernyon akkor visszateszi a tuloldalt. ekvivalens: if(o_y >= Y || o_y < 0) o_y =(Y+o_y)%Y;
  62. if(o_y > Y) o_y -= Y;
  63. else if(o_y < 0) o_y += Y;
  64.  
  65. }
  66. };
  67.  
  68.  
  69. void torol(){
  70. gout << move_to(0,0) << color(0,0,0) << box(X,Y);
  71. }
  72.  
  73. int main()
  74. {
  75. // hopihek vektora es feltoltese:
  76. std::vector<kor> hopihek;
  77. for(unsigned i = 0; i < 100; ++i){
  78. hopihek.push_back(kor(rand()%X, rand()%Y, rand()%3+2, 255,255,255));
  79. }
  80.  
  81.  
  82. gout.open(X,Y);
  83. event ev;
  84. gin.timer(40);
  85. while(gin >> ev) {
  86. if(ev.type == ev_timer){
  87. torol(); //kepernyo alaphelyzetbe allitasa azaz elozo allapot torlese.
  88. //kovetkezo allapot kiszamitasa es beallitasa:
  89. for(unsigned i = 0; i < hopihek.size(); ++i){
  90. hopihek[i].mozog();
  91. hopihek[i].kirajzol();
  92. }
  93. //tenyleges megjelenites:
  94. gout << refresh;
  95. }
  96. }
  97. return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement