c - sleep() 函数未按预期工作

标签 c plot sleep

我之前也遇到过类似的问题,但现在发生的情况是我尝试使用 GNU libplot 绘制五个圆圈,等待几秒钟,然后让窗口变黑。发生的情况是屏幕开始变黑,等待指定的时间,然后进行绘制。如何使用 sleep 来获得所需的输出?我将省略为时间结构赋值的代码

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

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

int main() {

    struct body sun;
    struct body mercury;
    struct body venus;
    struct body earth;
    struct body mars;

    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.size), 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; 
}

最佳答案

你在哪里:

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

您将“BG_COLOR”设置为黑色。

我对这套特定的工具不太了解,但看起来您从一开始就将背景设置为黑色。

在您的情况下,您想要做的是将其最初设置为白色(或其他),然后在完成后将其更改为黑色。希望这能让您走上正轨。

关于c - sleep() 函数未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22239998/

相关文章:

c++ - 当主应用程序处于 while 循环时,boost 线程未运行

php - 使用 cURL 登录,然后使用 cURL 发出另一个请求

java - 在 JPanel 中使用 sleep

c - 为什么我在比较线性搜索和二分搜索时每次都得到零?

c - 将值从文本文件传递到数组

c - 从 xml 响应中提取 url

python - 旋转时的文本不在 matplotlib 中正确(对齐)的位置

c - 使用 fgetc() 从文件读取时出现奇怪的最终值

python - 即使编辑后端并使用 pylab.show() 后,matplotlib 图也不会出现

r - 如何在 R 中创建优势比和 95% CI 图