C++ setfillstyle problem? Help I am newbie....

What is the different between these two codes? Why a) shows color and b) doesn't shows color?

a) // Directives:
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <graphics.h>
using namespace std;

// Named constants:
const int S = 500; // Width and height of the graphics window.
const int FPS = 30;

// Prototypes:
void draw_robot(int x, int y, int d);


// Function definitions:
//----------------------------------------------------------
int main( )
{
// declare variables
int offset = 0; // x-offset

// 0. Initialize the graphics window:
initwindow(S, S, "Moving robot!", 0, 0, true);

//while(S / 2 + offset - 50 < S)
// S / 2 - initial x coordinate of the robot
// d = 50 - value defining size of the robot
while(offset < S - S / 2 + 50)
{
// 1. Clear our drawing canvas
clearviewport();

// 2. Draw two tilted snowmen:
draw_robot(S / 2 + offset, 250, 50);

// 3. Swap buffers & delay
swapbuffers();
delay(1000/FPS);

// 4. calculations
// can be here or at the beginning of this loop
offset = offset + 1;
}
return EXIT_SUCCESS;
}
//----------------------------------------------------------

//----------------------------------------------------------
void draw_robot(int x, int y, int d)
{
setfillstyle(WIDE_DOT_FILL, GREEN); // sets fill style & color
bar(x-d, y-d, x+d, y+d); // draws robot body
circle(x, y-2*d, d); // draws robot head
line(x - d, y + 3 * d, x, y + d); // left leg
line(x + d, y + 3 * d, x, y + d); // right leg
}
//----------------------------------------------------------


b)#include <iostream>
#include <cstdlib>
#include <graphics.h>
#include <cmath>

int const s=500;

using namespace std;

void robo(int x, int y, int d);



int main()
{

initwindow(s, s, "robo", 0, 0, true);
clearviewport();
robo(s/2,s/2,50);
swapbuffers();
delay(1000000);


}
void robo(int x, int y, int d)
{



setfillstyle(WIDE_DOT_FILL, GREEN);

bar(x-d,y-d,x+d,x-d);
line(x-d,y+3*d,x,y+d);
line(x+d,y+3*d,x,y+d);
}

indent your code and and use the code tag for codes [<>] on the right to help read it easier
Topic archived. No new replies allowed.