Advertisement
Strzyk

kod

Jan 26th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2. #include <iostream>
  3. #include <time.h>
  4. #include <fstream>
  5. #define W 800
  6. #define H 600
  7. #define OFF 10
  8. #include <cmath>
  9. using namespace std;
  10.  
  11. int* generuj(int ile)
  12. {
  13. int* tmp;
  14. srand(time(NULL));
  15. int i;
  16.  
  17. if (ile < 1)
  18. return 0;
  19.  
  20. tmp = new int[ile];
  21.  
  22. for(i=0;i<ile;++i)
  23. tmp[i]=rand()%10;
  24. return tmp;
  25.  
  26. }
  27.  
  28. int liczR(char name[]){
  29. ifstream p;
  30. string tmp;
  31. int i=0;
  32. p.open(name);
  33. while(p.good())
  34. {
  35. getline(p,tmp);
  36. i++;
  37. }
  38. p.close();
  39. return i;
  40. }
  41.  
  42. int liczC(char name[]){
  43. ifstream p;
  44. char c;
  45. int i=0,tmp;
  46. p.open(name);
  47. while(p.good())
  48. {
  49. p >> tmp;
  50. p.get(c);
  51. i++;
  52. if(c=='\n')break;
  53. }
  54. p.close();
  55. return i;
  56. }
  57.  
  58. int** generuj(int R, int C){
  59. int **tmp;
  60.  
  61. tmp = new int *[R];
  62.  
  63. for (int i = 0; i < R; i++)
  64. tmp[i] = new int [C];
  65.  
  66. return tmp;
  67. }
  68. int** czytaj(char name[],int*R,int*C){
  69. int** tmp;
  70. ifstream p;
  71. *R=liczR(name);
  72. *C=liczC(name);
  73. tmp=generuj(*R,*C);
  74. p.open(name);
  75. for(int i=0;i<*R;i++){
  76. for(int j=0;j<*C;j++){
  77. p>>tmp[i][j];
  78. p.get();//przeskakuje o jeden zank
  79. }
  80. }
  81. p.close();
  82. return tmp;
  83. }
  84.  
  85.  
  86. int main()
  87.  
  88. {
  89. int *tab1;
  90. int j=0;
  91. int N=10;
  92. tab1 = generuj(N);
  93. for (j=0; j<N; j++)
  94. cout<< tab1[j] << " "<< endl;
  95. return 0;
  96.  
  97. int **tab, R,C;
  98. char fileO[]={"linia.csv"};
  99.  
  100.  
  101.  
  102. tab = czytaj(fileO,&R,&C);
  103. for(int i=0;i<R;i++){
  104. for(int j=0;j<C;j++){
  105. cout<<tab[i][j]<<";";
  106. }
  107. cout<<endl;
  108. }
  109.  
  110. int xx[]={OFF,OFF,W-OFF,W-OFF,OFF};
  111. int yy[]={OFF,H-OFF,H-OFF,OFF,OFF};
  112. int i;
  113. sf::VertexArray linie(sf::Lines);
  114. for(i=0;i<4;i++){
  115. linie.append(sf::Vector2f(xx[i],yy[i]));
  116. linie.append(sf::Vector2f(xx[i+1],yy[i+1]));
  117. }
  118.  
  119. ;
  120.  
  121. // Create the main window
  122. sf::RenderWindow window(sf::VideoMode(W,H), "SFML window");
  123.  
  124.  
  125.  
  126. // Start the game loop
  127. while (window.isOpen())
  128. {
  129. // Process events
  130. sf::Event event;
  131. while (window.pollEvent(event))
  132. {
  133. // Close window : exit
  134. if (event.type == sf::Event::Closed)
  135. window.close();
  136. }
  137.  
  138. // Clear screen
  139. window.clear();
  140.  
  141. window.draw(linie);
  142.  
  143.  
  144. // Update the window
  145. window.display();
  146. }
  147.  
  148. return EXIT_SUCCESS;;
  149.  
  150.  
  151.  
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement