Read up on how to use logical operators &&
and ||
.
There is no need to add separate checks for 'left red, middle white, right red', you can assume you are drawing in red and only check for the middle part.
Since you want to draw in White when [x > 0.3 && x <= 0.4] or [y > 0.3 && y <= 0.4], you can concatenate this into a single if
check. The same goes for the black border -- it only needs a single check.
if (x < width * .1 || y < height * .1 || x > width * .9 || y > height * .9)
..black..
else
if ((x > width *.3 && x <= width * .4) || (y > height *.3 && y <= height * .4))
..white..
else
..red..
Also: Your Pixel routine already prints the RGB value, so there is no need to try that again when you call it. What happens now is that
printf("%i", Pixel(255,51,51));
first prints the R,G,B values and then attempts to print the 'result' of calling the Pixel
function. This fails because Pixel
does not return a value. Your compiler should have warned you about that, so please check your compile settings. (But note that adding a return x
statement in that function does not help a bit, because it calculates nothing you are interested in.)
Finally, I'd strongly recommed using y
instead of i
to iterate a clearly-Y value. I noticed I used that 'instinctively' in my explanation.
After fixing a few smaller issues (for instance, Pixel
outputs three digits separated by a space, but if you call it a second time, the first new digit will stick to the previous one) I got this:
in PPM format, which I could open correctly in Photoshop (and then convert to PNG because SO does not like PPM images).