sleep()函数不能与gnu libplot一起使用

时间:2014-03-06 22:36:06

标签: c struct plot sleep

我正在编写一个程序来读取文件以获取有关太阳和行星的大小,质量,位置等。我可以在Xwindow中将行星绘制为圆圈,但我无法使睡眠功能起作用。我只是想让行星出现五秒然后消失以显示黑色,但当我试着打电话给睡眠并运行程序时,我从未在窗口看到行星。它只是以黑屏开始。我只是错误地使用睡眠或者我需要添加什么?或者我完全忽略了这一点?

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <plot.h>

struct body {
    char color[10];
    char size[4];
    char mass[10];
    char xpos[10];
    char ypos[10];
};

int main()
{    
    /* just drawing the first five for now */
    struct body sun;
    struct body mercury;
    struct body venus;
    struct body earth;
    struct body mars;

    /* not gonna show code for reading file and assigning values to the struct
     * for the space
    */

    plPlotter *plotter;
    plPlotterParams *plotterParams;

    plotterParams = pl_newplparams();
    pl_setplparam(plotterParams, "BITMAPSIZE", "750x750");
    pl_setplparam(plotterParams, "USE_DOUBLE_BUFFERING", "no");
    pl_setplparam(plotterParams, "BG_COLOR", "black");

    if ((plotter = pl_newpl_r("X", stdin, stdout, stderr, plotterParams)) == NULL) {
        fprint(stderr, "Couldn't create Plotter\n");
        exit(1);
    } else if(pl_openpl_r(plotter) < 0) {
         fprintf(stderr, "Couldn't open Xwindows Plotter\n");
         exit(1);
    }

    pl_fspace_r(plotter, -2500, -2500, 2500, 2500);

    pl_pentype_r(plotter, 1);
    pl_filltype_r(plotter, 1);

    pl_pencolorname_r(plotter, "black");

    /* draw the sun */
    pl_fillcolorname_r(plotter, sun.color);
    pl_fcircle_r(plotter, atof(sun.xpos), atof(sun.ypos), atof(sun.size));

    /* I do this same thing 4 more times but with 
     * mercury, venus, earth, and mars
    */

    sleep(5); /* try to wait 5 seconds then sleep */

    /* close and cleanup */
    if (pl_close_pl_r(plotter) < 0) {
        fprintf(stderr, "Couldnt delete plotter\n");
    }
    else if (pl_deletepl_r(plotter) < 0) {
        fprintf(stderr, "Couldnt delete plotter\n");
    }

    return 0; 
}

0 个答案:

没有答案