Zoo tutorials: [ SQL | Linux | XML ]
ProgZoo: [ Java | C# | VB | C++ | Perl ]
Log in

A Gentle Introduction to
Java Programming

Tutorial: Bricks - repeating

 

We can specify the number of bricks to be drawn.

CommandMeaning
b(3)Draw three long bricks
h(3)Draw three half bricks
m(3)Leave three half brick spaces
r(3)Start a new row three times

1. Making an E


Big

Finish of the "E".

A pattern of bricks

2. Rectangle


Big

Change so that the are 3 rows of 4 half-bricks.

A pattern of bricks

3. Triangle


Big

There should be one half-brick, then two, then three, four and five.

A pattern of bricks

4. Triangle II


Big

The triangle starts with a row of zero half-bricks. The initial row of 6 is simply so that we can see where the triangle starts.

In each row we must

  • draw some bricks h(...)
  • miss some spaces m(...)
  • draw one brick h()
In row 0 we need 1 brick then we miss 4 then draw 1.
In row 1 we need 2 brick then we miss 3 then draw 1.
We must calculate the number of bricks to draw and the number to miss.

row      h(...)     m(...)
 0         1          4
 1         2          3
 2         3          2
 3         4          1
 4         5          0

Draw the framed triangle as shown.

A pattern of bricks

5. Triangle III


Big

We must calculate the number of spaces to miss then the number of bricks to draw.

row      m(...)     b(...)
 0         4          1
 1         3          3
 2         2          5
 3         1          7
 4         0          9

In row 0: miss 4, draw 1.
In row 1: miss 3, draw 3.
In row 2: miss 2, draw 5.
...

A pattern of bricks