Advertisement
towniyan

Untitled

May 12th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. #include <string>
  4. #include <SFML/Graphics.hpp>
  5. #include "csv.h"
  6.  
  7. using namespace std;
  8.  
  9. // index in array = y * width + x
  10.  
  11. int main () {
  12.     ifstream file("data/A_Z Handwritten Data.csv");
  13.  
  14.     sf::ContextSettings settings;
  15.     settings.antialiasingLevel = 8;
  16.     sf::RenderWindow window(sf::VideoMode(4 * 300, 3 * 300), "", sf::Style::Default, settings);
  17.     window.setFramerateLimit(60);
  18.  
  19.     string line;
  20.     getline(file, line);
  21.     Csv csv(line);
  22.  
  23.     // rectangles
  24.     sf::RectangleShape rectangles[28 * 28];
  25.     int pixel;
  26.     for (int i = 0; i < 28; i++) {
  27.         for (int j = 0; j < 28; j++) {
  28.             pixel = stoi(csv.getNextToken());
  29.  
  30.             rectangles[i * 28 + j] = sf::RectangleShape(sf::Vector2f(16, 16));
  31.             rectangles[i * 28 + j].setPosition(sf::Vector2f(j * 16, i * 16));
  32.             rectangles[i * 28 + j].setFillColor(sf::Color(255 - pixel, 255 - pixel, 255 - pixel));
  33.         }
  34.     }
  35.  
  36.     while (window.isOpen()) {
  37.         sf::Event event;
  38.         while (window.pollEvent(event)) {
  39.             // "close requested" event: we close the window
  40.             if (event.type == sf::Event::Closed)
  41.                 window.close();
  42.         }
  43.  
  44.         // clear the window with white color
  45.         window.clear(sf::Color::White);
  46.  
  47.         for (int i = 0; i < 28; i++) {
  48.             for (int j = 0; j < 28; j++) {
  49.                 window.draw(rectangles[i * 28 + j]);
  50.             }
  51.         }
  52.  
  53.         // end the current frame
  54.         window.display();
  55.     }
  56.  
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement