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.
#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.