Picket Fence

Hello
i am required to draw picket fence. At the moment i think i am way off. Each rectangle must not be drawn individually. They must go through a loop. I thought of an IF statement to draw the rectangles as long as the up left coord is <= 43. else it will draw the last bar to hold the pickets.
heres the code tell me what can be adjusted or that i am way off course.

#include "DarkGDK.h"

void DarkGDK ()
{
int boxHeight;
int boxWidth;
int upperLeftX;
int upperLeftY;
int lowerLeftX;
int lowerRightX;
int lowerRightY;

upperLeftX = 20;
upperLeftY = 200;
boxHeight = 280;
boxWidth = 20;
lowerRightX= 0;
lowerRightY = 0;

if(upperLeftX <= 639)
{
lowerRightX = upperLeftX + boxWidth;
lowerRightY = upperLeftY + boxHeight;

dbBox(upperLeftX, upperLeftY, lowerRightX, lowerRightY);

upperLeftX= upperLeftX +20;
dbWait(2000);
}
else
{
int boxULX;
int boxULY;
int boxLLX;
int boxLLY;
int boxLRX;
int boxLRY;

dbBox(0, 220, 436, 220);
}

dbWaitKey();
return;
}
Last edited on
the else statement i have yet to complete dont mind it at the moment
Think i got it

#include "DarkGDK.h"

void DarkGDK ()
{
int boxHeight;
int boxWidth;
int upperLeftX;
int upperLeftY;
int lowerLeftX;
int lowerLeftY;
int lowerRightX;
int lowerRightY;

upperLeftX = 20;
upperLeftY = 200;
boxHeight = 280;
boxWidth = 20;
lowerRightX= 0;
lowerRightY = 0;

while(upperLeftX <= 639)
{
lowerRightX = upperLeftX + boxWidth;
lowerRightY = upperLeftY + boxHeight;

dbBox(upperLeftX, upperLeftY, lowerRightX, lowerRightY);

upperLeftX= upperLeftX+39;
//upperLeftY= upperLeftY+20;
}

lowerRightX=640;
lowerRightY=240;
boxHeight=10;
boxWidth=636;
upperLeftX = lowerRightX - boxWidth;
upperLeftY = lowerRightY - boxHeight;
dbBox(upperLeftX, upperLeftY, lowerRightX, lowerRightY);

dbWaitKey();
return;
}
I'd say let "DarkGDK()" except some arguments for the start points of "upperLeftX" and "upperLeftY". Make "lowerRightX" and "lowerRightY" offsets of the previous two and you're all set. This way you can reuse this function in a number of cases.
Topic archived. No new replies allowed.