Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - etudiantengalere

Pages: [1]
1
General / Re: Changing the name variable in a loop for
« on: February 13, 2023, 10:24:48 am »
Thank you but unfortunately this doesn't work, I have an error "Failed to save image " " " and I don't know how to fix it.. I saw on internet that this can come from a special letter in the file acces but this is not my case

Here is my code :

...

while (window.isOpen()){
        sf::Event event;
        while (window.pollEvent(event))
            if (event.type == sf::Event::Closed) window.close();

       
        int i=0;
        for (auto& chart : charts){
            window.clear(sf::Color::White);
            sf::Texture text;
            window.draw(chart);
            text.update(window);
            sf::Image Screen;
            Screen = text.copyToImage();
            Screen.saveToFile("screen_" + to_string(i) + ".jpg");
            i++;
        }
        window.display();
    }
...

2
General / Re: Changing the name variable in a loop for
« on: February 12, 2023, 12:00:37 pm »
Thank you very much it works ! <3 And since you seem to know a lot about sfml would you happen to know how to save the window in a jpg file ?

3
General / Re: Changing the name variable in a loop for
« on: February 12, 2023, 12:10:36 am »
Thanks both of you for your fast responses ! It work but unfortunately there is a little probleme at the end of the plot, as you can see. Do you have any idea how to fix it ?

4
General / Re: Changing the name variable in a loop for
« on: February 11, 2023, 11:28:33 pm »
I would like to know if there's a way to avoid the 15 repetitions of sf::vertexarray

5
General / Changing the name variable in a loop for
« on: February 11, 2023, 11:26:13 pm »
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 ! ;D

#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;
}

Pages: [1]