Hello, I'm tryng to draw multiple graph with SFML on a single window and for that I need to change the name of a vertexarray variable inside my loop for, unfortunately I don't know how to do it, anyone can help me ?
Thanks !
#include <SFML/Graphics.hpp>
#include <iostream>
#include <sstream>
#include <cmath>
#include<fstream>
using namespace std;
double dt=1;//sec
double dx=0.1;//m
int tmax = 30 ;
int xmax = 40 ;
int main()
{
fstream fich; //file with stuff to plot
fich.open("results.txt", ios::in);
const unsigned int s = 800;
const unsigned int N = 1500;
sf::RenderWindow window(sf::VideoMode(N, s),"Graph", sf::Style::Default);
window.setVerticalSyncEnabled(true);
window.setFramerateLimit(60);
sf::VertexArray chart1(sf::LinesStrip, N);
for (unsigned int i=0; i<400; i++){
double x1, U1, x2, U2, Utot, t;
fich>>x1>> U1>> x2>> U2>> Utot>> t;
double abscisse = x1*N/xmax;
double ordonne = s-Utot*s/2;
chart1.append(sf::Vertex(sf::Vector2f(abscisse, ordonne), sf::Color::Black));
}
sf::VertexArray chart2(sf::LinesStrip, N);
for (unsigned int i=0; i<400; i++){
double x1, U1, x2, U2, Utot, t;
fich>>x1>> U1>> x2>> U2>> Utot>> t;
double abscisse = x1*N/xmax;
double ordonne = s-Utot*s/2;
chart2.append(sf::Vertex(sf::Vector2f(abscisse, ordonne), sf::Color::Black));
}
sf::VertexArray chart3(sf::LinesStrip, N);
for (unsigned int i=0; i<400; i++){
double x1, U1, x2, U2, Utot, t;
fich>>x1>> U1>> x2>> U2>> Utot>> t;
double abscisse = x1*N/xmax;
double ordonne = s-Utot*s/2;
chart3.append(sf::Vertex(sf::Vector2f(abscisse, ordonne), sf::Color::Black));
}
sf::VertexArray chart4(sf::LinesStrip, N);
for (unsigned int i=0; i<400; i++){
double x1, U1, x2, U2, Utot, t;
fich>>x1>> U1>> x2>> U2>> Utot>> t;
double abscisse = x1*N/xmax;
double ordonne = s-Utot*s/2;
chart4.append(sf::Vertex(sf::Vector2f(abscisse, ordonne), sf::Color::Black));
}
sf::VertexArray chart5(sf::LinesStrip, N);
for (unsigned int i=0; i<400; i++){
double x1, U1, x2, U2, Utot, t;
fich>>x1>> U1>> x2>> U2>> Utot>> t;
double abscisse = x1*N/xmax;
double ordonne = s-Utot*s/2;
chart5.append(sf::Vertex(sf::Vector2f(abscisse, ordonne), sf::Color::Black));
}
sf::VertexArray chart6(sf::LinesStrip, N);
for (unsigned int i=0; i<400; i++){
double x1, U1, x2, U2, Utot, t;
fich>>x1>> U1>> x2>> U2>> Utot>> t;
double abscisse = x1*N/xmax;
double ordonne = s-Utot*s/2;
chart6.append(sf::Vertex(sf::Vector2f(abscisse, ordonne), sf::Color::Black));
}
sf::VertexArray chart7(sf::LinesStrip, N);
for (unsigned int i=0; i<400; i++){
double x1, U1, x2, U2, Utot, t;
fich>>x1>> U1>> x2>> U2>> Utot>> t;
double abscisse = x1*N/xmax;
double ordonne = s-Utot*s/2;
chart7.append(sf::Vertex(sf::Vector2f(abscisse, ordonne), sf::Color::Black));
}
sf::VertexArray chart8(sf::LinesStrip, N);
for (unsigned int i=0; i<400; i++){
double x1, U1, x2, U2, Utot, t;
fich>>x1>> U1>> x2>> U2>> Utot>> t;
double abscisse = x1*N/xmax;
double ordonne = s-Utot*s/2;
chart8.append(sf::Vertex(sf::Vector2f(abscisse, ordonne), sf::Color::Black));
}
sf::VertexArray chart9(sf::LinesStrip, N);
for (unsigned int i=0; i<400; i++){
double x1, U1, x2, U2, Utot, t;
fich>>x1>> U1>> x2>> U2>> Utot>> t;
double abscisse = x1*N/xmax;
double ordonne = s-Utot*s/2;
chart9.append(sf::Vertex(sf::Vector2f(abscisse, ordonne), sf::Color::Black));
}
sf::VertexArray chart10(sf::LinesStrip, N);
for (unsigned int i=0; i<400; i++){
double x1, U1, x2, U2, Utot, t;
fich>>x1>> U1>> x2>> U2>> Utot>> t;
double abscisse = x1*N/xmax;
double ordonne = s-Utot*s/2;
chart10.append(sf::Vertex(sf::Vector2f(abscisse, ordonne), sf::Color::Black));
}
sf::VertexArray chart11(sf::LinesStrip, N);
for (unsigned int i=0; i<400; i++){
double x1, U1, x2, U2, Utot, t;
fich>>x1>> U1>> x2>> U2>> Utot>> t;
double abscisse = x1*N/xmax;
double ordonne = s-Utot*s/2;
chart11.append(sf::Vertex(sf::Vector2f(abscisse, ordonne), sf::Color::Black));
}
sf::VertexArray chart12(sf::LinesStrip, N);
for (unsigned int i=0; i<400; i++){
double x1, U1, x2, U2, Utot, t;
fich>>x1>> U1>> x2>> U2>> Utot>> t;
double abscisse = x1*N/xmax;
double ordonne = s-Utot*s/2;
chart12.append(sf::Vertex(sf::Vector2f(abscisse, ordonne), sf::Color::Black));
}
sf::VertexArray chart13(sf::LinesStrip, N);
for (unsigned int i=0; i<400; i++){
double x1, U1, x2, U2, Utot, t;
fich>>x1>> U1>> x2>> U2>> Utot>> t;
double abscisse = x1*N/xmax;
double ordonne = s-Utot*s/2;
chart13.append(sf::Vertex(sf::Vector2f(abscisse, ordonne), sf::Color::Black));
}
sf::VertexArray chart14(sf::LinesStrip, N);
for (unsigned int i=0; i<400; i++){
double x1, U1, x2, U2, Utot, t;
fich>>x1>> U1>> x2>> U2>> Utot>> t;
double abscisse = x1*N/xmax;
double ordonne = s-Utot*s/2;
chart14.append(sf::Vertex(sf::Vector2f(abscisse, ordonne), sf::Color::Black));
}
sf::VertexArray chart15(sf::LinesStrip, N);
for (unsigned int i=0; i<400; i++){
double x1, U1, x2, U2, Utot, t;
fich>>x1>> U1>> x2>> U2>> Utot>> t;
double abscisse = x1*N/xmax;
double ordonne = s-Utot*s/2;
chart15.append(sf::Vertex(sf::Vector2f(abscisse, ordonne), sf::Color::Black));
}
fich.close();
while (window.isOpen()){
sf::Event event;
while (window.pollEvent(event))
if (event.type == sf::Event::Closed) window.close();
window.clear(sf::Color::White);
window.draw(chart1);
window.draw(chart2);
window.draw(chart3);
window.draw(chart4);
window.draw(chart5);
window.draw(chart6);
window.draw(chart7);
window.draw(chart8);
window.draw(chart9);
window.draw(chart10);
window.draw(chart11);
window.draw(chart12);
window.draw(chart13);
window.draw(chart14);
window.draw(chart15);
window.display();
}
return 0;
}