Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- #include <string>
- #include <SFML/Graphics.hpp>
- #include "csv.h"
- using namespace std;
- // index in array = y * width + x
- int main () {
- ifstream file("data/A_Z Handwritten Data.csv");
- sf::ContextSettings settings;
- settings.antialiasingLevel = 8;
- sf::RenderWindow window(sf::VideoMode(4 * 300, 3 * 300), "", sf::Style::Default, settings);
- window.setFramerateLimit(60);
- string line;
- getline(file, line);
- Csv csv(line);
- // rectangles
- sf::RectangleShape rectangles[28 * 28];
- int pixel;
- for (int i = 0; i < 28; i++) {
- for (int j = 0; j < 28; j++) {
- pixel = stoi(csv.getNextToken());
- rectangles[i * 28 + j] = sf::RectangleShape(sf::Vector2f(16, 16));
- rectangles[i * 28 + j].setPosition(sf::Vector2f(j * 16, i * 16));
- rectangles[i * 28 + j].setFillColor(sf::Color(255 - pixel, 255 - pixel, 255 - pixel));
- }
- }
- while (window.isOpen()) {
- sf::Event event;
- while (window.pollEvent(event)) {
- // "close requested" event: we close the window
- if (event.type == sf::Event::Closed)
- window.close();
- }
- // clear the window with white color
- window.clear(sf::Color::White);
- for (int i = 0; i < 28; i++) {
- for (int j = 0; j < 28; j++) {
- window.draw(rectangles[i * 28 + j]);
- }
- }
- // end the current frame
- window.display();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement