I broke drawing the figure into two steps:
1) draw the top half, in a while loop, and 2) draw the bottom half, also in a while loop.
Then, inside those while loops, were the while loops for each of the color zones.
Code:
//cp = current position. cpx=current position x value, etc.
int cpx,cpy,red,cyan,magenta,yellow,midx,midy,r;
int ht=26, wt=27; //ht=height and wt=width of drawing
midx=wt/2; //midx=middle x
midy=ht/2; //midy=middle y midpoint is midx,midy
cpx=cpy=r=cyan=magenta=yellow=0;
red=wt-1;
printf("height: %d width: %d midx: %d midy: %d\n\n",ht, wt, midx, midy);
//upper half of figure
while(cpy<midy) {
cpx=0;
while(cpx<=cyan && cpy<midy) {
set color to CYAN
printf("%c",CH);
++cpx;
}
while(cpx>=cyan && cpx<red){
set color to MAGENTA);
printf("%c",CH);
cpx++;
}
while(cpx < wt) {
set color to RED
printf("%c",CH);
cpx++;
}
--red; //red gets larger when decremented
++cyan; //cyan gets larger " incremented
++cpy;
printf("\n");
}
//lower half of figure
yellow=0;
++cyan;
while(cpy<ht) {
cpx=0;
--cyan;
++red;
++yellow;
while(cpx<cyan) {
set color to BLUE;
printf("%c",CH);
++cpx;
}
while(cpx>=cyan && cpx<red){
set color to YELLOW);
printf("%c",CH);
cpx++;
}
while(cpx < wt) {
set color to RED;
printf("%c",CH);
cpx++;
}
++cpy;
_putch('\n');
}
printf("\n");
return 0;
}
Your test in each while (test) portion will use the slope and etc., that we discussed previously. Which were more fuzzy than precise, on my part.
I wasn't sure you were coming back, so I changed my program around a bit:
Code:
#include <stdio.h>
#include <conio.h>
#define BLUE 9
#define CYAN 3
#define RED 4
#define YELLOW 14
#define MAGENTA 5
#define WHITE 15
#define CH 254 //254-best, 219 for a full char
int main(void) {
int cpx,cpy,red,cyan,magenta,yellow,midx,midy,r;
//cp = current position. cpx=current position x value, etc.
int ht=26, wt=27; //ht=height and wt=width of drawing
midx=wt/2; //midx=middle x
midy=ht/2; //midy=middle y midpoint is midx,midy
cpx=cpy=r=cyan=magenta=yellow=0;
red=wt-1;
printf("height: %d width: %d midx: %d midy: %d\n\n",ht, wt, midx, midy);
//upper half of figure
while(cpy<midy) {
cpx=0;
_textcolor(WHITE);
printf("%2d. ",r++);
while(cpx<=cyan && cpy<midy) {
_textcolor(RED);
printf("%c",CH);
++cpx;
}
while(cpx>=cyan && cpx<red){
_textcolor(MAGENTA);
printf("%c",CH);
cpx++;
}
while(cpx < wt) {
_textcolor(BLUE);
printf("%c",CH);
cpx++;
}
--red;
++cyan;
++cpy;
_putch('\n');
}
//lower half of figure
yellow=0;
++cyan;
while(cpy<ht) {
cpx=0;
--cyan;
++red;
++yellow;
_textcolor(YELLOW);
printf("%2d. ",r++);
while(cpx<cyan) {
_textcolor(BLUE);
printf("%c",CH);
++cpx;
}
//if(cpx==midx && cpy==midy) { _textcolor(WHITE); printf("%c",CH);cpx++;} //a middle dot
while(cpx>=cyan && cpx<red){
_textcolor(YELLOW);
printf("%c",CH);
cpx++;
}
//_getch();
while(cpx < wt) {
_textcolor(RED);
printf("%c",CH);
cpx++;
}
++cpy;
_putch('\n');
}
_textcolor(YELLOW);
printf("\n");
return 0;
}
Which gave me this little beauty: