c prog, functions and backround gradient

Discussion in 'Programmer's Corner' started by smarch, Apr 29, 2010.

Thread Status:
Not open for further replies.
  1. smarch

    Thread Starter Active Member

    Mar 14, 2009
    52
    0
    so anyways i've created a code to create an image, so far a black rectangle appears. This is my code below:

    #include <stdio.h>

    #define XSIZE 256
    #define YSIZE 128
    #define RED 0
    #define GREEN 1
    #define BLUE 2

    int image[YSIZE][XSIZE][3];

    main()
    {
    int x, y;
    for(x=0; x<XSIZE; x++)
    for(y=0; y<YSIZE; y++)
    {
    image[x][y][RED]=250;
    image[x][y][GREEN]=100;
    image[x][y][BLUE]=200;



    {
    FILE *pfile = NULL;
    int x,y; //loop counter
    pfile = fopen("myfile.ppm", "w");
    fprintf(pfile, "P3\n# %s\n%d %d\n255\n", "Myfile.ppm", XSIZE, YSIZE);
    for(y = 0; y < YSIZE; y++)
    for(x = 0; x < XSIZE; x++)
    fprintf(pfile,"%d %d %d\n",image[y][x][0],image[y][x][1],image[y][x][2]);
    fclose(pfile);
    system("myfile.ppm");
    }

    }

    }

    I am asked to use a function as well as a loop, but i'm unsure of how to apply it in my code.
    I am also asked to generate a smooth transistion between two colours, but i'm just getting the black box.
    Can anyone shed some light on what I'm doing wrong and what I need to do?

    thanks.
     
  2. Bosparra

    Member

    Feb 17, 2010
    79
    3
    I suggest that before you start adding functions, check your logic first. You are calling the system() API once for every pixel, which I suspect is not the intended behaviour?

    What OS are you running on?
     
  3. bertus

    Administrator

    Apr 5, 2008
    15,647
    2,346
Loading...
Thread Status:
Not open for further replies.