为什么像素条在ppm图像对角线而不是水平或垂直?

时间:2014-10-07 01:53:01

标签: c ppm

我必须创建ppm文件中显示的国家/地区标志。我有以下程序工作,除非我显示标志条纹是对角线而不是法国国旗的垂直或其他两个水平。我知道它与i < width函数中的make_flag_row有关,但我真的不知道是什么会使条纹水平或垂直。

int main(void) {
    int width;
    int country_code;

    fscanf(stdin, "%d %d", &country_code, &width);
    fprintf(stderr, "Making country %d width %d \n", country_code, width);

    make_ppm_image(country_code, width);

    return(0);
}

void make_pixel(int r,int g,int b) {
    fprintf(stdout, "%c%c%c", r, g, b);
}

void make_ppm_header(int width, int height) {
    fprintf(stdout, "P6\n");
    fprintf(stdout, "%d %d %d\n", width, height, 255);
}

void make_ppm_image(int country_code, int width) {
    if(country_code==0) {
        make_france_flag(width);
    }
    else if(country_code==1) {
        make_germany_flag(width);
    }
    else {
        make_lithuania_flag(width);
    }
}   

void make_france_flag(int width) {
    int i;
    int height;
    height = width * 2/3;
    make_ppm_header(width, height);
    for(i = 0; i < height; i++)
        make_france_flag_row(width);
}

void make_germany_flag(int width) {
    int i;
    int height;
    height = width * 3/5;
    make_ppm_header(width, height);   
    for(i = 0; i < height; i++)
        make_germany_flag_row(width);
}

void make_lithuania_flag(int width) {
    int i;
    int height;
    height = width * 3/5;
    make_ppm_header(width, height);
    for(i = 0; i < height; i++)
        make_lithuania_flag_row(width);
}

void make_france_flag_row(int width) {
    int i;
    for (i = 0; i < width / 3; i++)
        make_pixel(0, 85, 164);
    for (i = 0; i < width / 3; i++)
        make_pixel(255, 255, 255);
    for (i = 0; i < width / 3; i++)
        make_pixel(250, 60, 50);
}

void make_germany_flag_row(int width) {
    int i;
    for (i = 0; i <= width / 3; i++)
        make_pixel(0, 0, 0);
    for (i = 0; i <= width / 3; i++)
        make_pixel(255, 0, 0);
    for (i = 0; i <= width / 3; i++)
        make_pixel(255, 204, 0);
}

void make_lithuania_flag_row(int width) {
    int i;
    for (i = 0; i < width / 3; i++)
        make_pixel(253, 185, 19);
    for (i = 0; i < width / 3; i++)   
        make_pixel(0, 106 , 68 );
    for (i = 0; i < width / 3; i++) 
        make_pixel(193, 39, 45);
}

0 个答案:

没有答案