Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1. #include <fstream>
  2. #include <SFML/Graphics.hpp>
  3. #include <ctime>
  4. using namespace std;
  5. sf::RenderWindow window(sf::VideoMode(500, 400), "COT++", sf::Style::Titlebar);
  6. sf::VertexArray points(sf::Points, 3000);
  7. sf::Event event;
  8. fstream f;
  9. unsigned int Pointers[10000000], pointer = 0, funcSelector = 0, lengthBuffer;
  10. char filePath[30] = "c:/users/79994/desktop/a.exe";
  11. bool mouseLeft, touchDown, fileCreated = 0;
  12. void readFile() {
  13. f.seekg (0, f.end);
  14. lengthBuffer = f.tellg();
  15. f.seekg (0, f.beg);
  16. char *fileBuffer = new char[lengthBuffer];
  17. f.open(filePath, ios::in | ios::app | ios::binary);
  18. f.read(fileBuffer, lengthBuffer);
  19. f.close();
  20. return fileBuffer[];
  21. }
  22. void writeFile(){
  23. if (fileBuffer[0] > 0 & fileCreated == 0) {
  24. filePath[23] += 1;
  25. f.open(filePath, ios::out | ios::app | ios::binary);
  26. f.write(fileBuffer, lengthBuffer);
  27. filePath[23] -= 1;
  28. fileCreated = 1;
  29. }
  30. f.close();
  31. }
  32.  
  33. void removeFile() {
  34. filePath[23] += 1;
  35. remove(filePath);
  36. filePath[23] -= 1;
  37. fileCreated = 0;
  38. }
  39. /*void drawArray() {
  40. pointer = 0;
  41. if (sizeof(fileBuffer) > 0) {
  42. while (pointer < sizeof(fileBuffer)) {
  43. //Draw Array...
  44. pointer += 1;
  45. }
  46. }
  47. }*/
  48. void Search() {
  49. char buffer[sizeof(fileBuffer)];
  50. memcpy(buffer, fileBuffer, sizeof(fileBuffer));//copying array to array
  51. unsigned int NewPointer = 0, requiredNumber;
  52. //define requiredNumber
  53. while (pointer < sizeof(fileBuffer)) {
  54. Pointers[NewPointer] = Pointers[pointer];
  55. buffer[NewPointer] = buffer[pointer];
  56. if (fileBuffer[pointer] == requiredNumber) {
  57. NewPointer += 1;
  58. }
  59. pointer += 1;
  60. }
  61. }
  62. void touch(){
  63. touchDown = sf::Touch::isDown(0);
  64. sf::Vector2i touch = sf::Touch::getPosition(0, window);
  65. if(touch.x < 100 & touch.y < 100){
  66. funcSelector = 1;
  67. }
  68. }
  69. void mouse() {
  70. mouseLeft = sf::Mouse::isButtonPressed(sf::Mouse::Left);
  71. sf::Vector2i mouse = sf::Mouse::getPosition(window);
  72. if (mouseLeft & mouse.y < 100) {
  73. funcSelector = 1 + mouse.x/100;
  74. }
  75. }
  76. int main()
  77. {
  78. float start, x = 0.f, y = 1.f, pos = 0.f;
  79. unsigned int n = 0;
  80. start = clock();
  81. while(x < 500.f){
  82. points[n].position = sf::Vector2f(x + pos, y + pos);
  83. points[n].color = sf::Color::Green;
  84. x += 1.f;
  85. n += 1;
  86. if(x == 500.f & y < 100.f){
  87. x = 0.f;
  88. y += 100.f;
  89. }
  90. }
  91. x = 100.f, y = 1.f;
  92. while(x < 600.f){
  93. points[n].position = sf::Vector2f(x + pos, y + pos);
  94. points[n].color = sf::Color::Green;
  95. y += 1.f;
  96. n += 1;
  97. if(y > 101.f){
  98. x += 100.f;
  99. y = 1.f;
  100. }
  101. }
  102. while (window.isOpen())
  103. {
  104. mouse();
  105. if ((clock() - start) > 10) {
  106. while (window.pollEvent(event)) {
  107. }
  108. switch(funcSelector){
  109. case 5: window.close();
  110. break;
  111. case 1: readFile();
  112. break;
  113. case 2: writeFile();
  114. break;
  115. case 3: removeFile();
  116. break;
  117. case 4: Search();
  118. break;
  119. }
  120. start = clock();
  121. window.clear();
  122. window.draw(points);
  123. window.display();
  124. }
  125. }
  126. return 0;
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement