Code:
#include <stdio.h>
void make_header (int width, int height);
void print_Row (int yValue, int width, int height);
void make_pixel (unsigned char r, unsigned char g, unsigned char b);
void make_header (int width, int height)
{
fprintf(stdout,"P6\n");
fprintf(stdout,"%d %d 255\n",width, height);
}
void print_Row (int yValue, int width, int height){
int x;
float slope1 = height / width, slope2 = -1*slope1;
for(yValue = 0; yValue < height; yValue++){
for(x = 0; x < width; x++){
if(yValue < slope1 * x && yValue < slope2 * x){
make_pixel(255, 0, 0);}//Makes red
else if(yValue<slope1 * x && yValue >= slope2 * x){
make_pixel(0, 255, 0);}//Makes green
else if(yValue>= slope1 * x && yValue>=slope2 * x){
make_pixel(0, 0, 255);}//Makes blue
else(yValue >= slope1 * x && yValue < slope2 * x);{
make_pixel(255, 255, 0);}//Makes yellow
}
}
}
void make_pixel (unsigned char r, unsigned char g, unsigned char b)
{
fprintf(stdout,"%c%c%c", r,g,b);
}
int main()
{
float slope1, slope2, wmid, hmid, yValue ;
int width, height;
fprintf(stderr, "\nEnter a value for width: ");
fscanf(stdin, "%d", &width);
fprintf(stderr, "\nEnter a value for height: ");
fscanf(stdin, "%d", &height);
make_header (width, height);
slope1 = height / width;
slope2 = -1*slope1;
print_Row (yValue, width, height);
return(0);
}
Basically what I need it to do is to divide a rectangle of dimensions entered by the user into 4 quadrants (divided diagonally from the corners). I'm trying to do this by dividing the rectangle by two slope functions and then trying to see if a certain point is above both, above one but below another, or below both and it determines which color to print.