# Thread: How to Draw a square within a square

1. ## How to Draw a square within a square

i know how to draw a square hollow or filled

but i need to draw an alternating pattern

ex
iPatternHeight = 1
X

iPatternHeight = 3
OOO
OXO
OOO

iPatternHeight = 5
XXXXX
XOOOX
XOXOX
XOOOX
XXXXX

iPatternHeight = 7
OOOOOOO
OXXXXXO
OXOOOXO
OXOXOXO
OXOOOXO
OXXXXXO
OOOOOOO

anybody can help?

2. I would say quit focusing exactly on the squareness of the shape. I will use the size 7 square, since I think it will clearly illustrate my thinking -- but it applies equally to the size 5 and size 3 ones. The 1 input is a special case, regardless.

OOOOOOO

OXXXXXO

OXOOOXO

OXOXOXO

What do you notice about these lines? For each line, there is a specific number of X's and O's to draw. First it was all O's. Notice that as the X's are filled in, the line composed of the same characters on the inside is getting shorter by two. So one way to program it is to keep track of what row you are on, alternate characters to the start of the inner line, and then fill the inner line, and then alternate characters until you are done with the whole row. When you get down to the inner line length of 1, you know to alternate like OXOXOXO.

The pattern below is the same as that pattern, done in reverse.

OXOOOXO

OXXXXXO

OOOOOOO

Once you can do it for this length, extend the concept for longer lines.