C++ 尝试使用CImg库(C+;+;)制作实时数据记录器

C++ 尝试使用CImg库(C+;+;)制作实时数据记录器,c++,cimg,C++,Cimg,我是CImg的新手。我不确定图书馆里是否已经有一台实时数据绘图仪,但我想我还是自己做一台吧。如果库中已经存在我要查找的内容,请指向函数。否则,这里是我超低效的代码,我希望你能帮助我~ #include <iostream> #include "CImg.h" #include <ctime> #include <cmath> using namespace cimg_library; int main() { CImg<unsigned ch

我是CImg的新手。我不确定图书馆里是否已经有一台实时数据绘图仪,但我想我还是自己做一台吧。如果库中已经存在我要查找的内容,请指向函数。否则,这里是我超低效的代码,我希望你能帮助我~

#include <iostream>
#include "CImg.h"
#include <ctime>
#include <cmath>

using namespace cimg_library;

int main()
{
    CImg<unsigned char> plot(400, 320, 1, 3, 0);
    CImgDisplay graph(plot, "f(x)");

    clock();
    const unsigned char red[] =  {255, 0, 0};

    float* G = new float[plot.width()];      //define an array holding the values that are to be displayed on the graph

    while (1){
        G[0] = ((plot.height()/4) * sin(clock() / 1000.0)) + plot.height()/2;         // new f(t) value
        for (int i = 1; i <= plot.width() - 1; i++){
            G[plot.width() - i] = G[plot.width() - i - 1];  //basically shift all the array values to current address+1
            plot.draw_point(plot.width() - 3*i, G[i-1], red, 1).display(graph);
            }
        plot.fill(0);
    }

    return 0;
}
#包括
#包括“CImg.h”
#包括
#包括
使用名称空间cimg_库;
int main()
{
CImg绘图(400、320、1、3、0);
CImgDisplay图形(绘图,“f(x)”);
时钟();
常量无符号字符红色[]={255,0,0};
float*G=new float[plot.width()];//定义一个数组,其中包含要在图形上显示的值
而(1){
G[0]=((plot.height()/4)*sin(clock()/1000.0))+plot.height()/2;//新的f(t)值

对于(int i=1;i,库中已经有了适合您的内容,方法是
CImg::draw_graph()
,如下(brielfy)所述:

库中提供的使用此方法的示例很少,请参见文件
examples/tutorial.cpp
examples/plotter1d.cpp