Wednesday, 1 April 2009

Chunk46 - Line Patterns

After much deliberation we come up with a motley collection of patterns which we will be re-factoring out to functions in the next section.
Our first pattern required 4 line statements to draw it and we placed these in our for loop. Looking at our collection of patterns we realise that some need a different amount of statements in order to be drawn and their symmetrical properties vary. We intend to make a randomised pattern generator, along the lines of Chunk16 but we have some decisions to make along the way, which will affect how the finished patterns will be generated.
One of our patterns requires only one statement and is totally symmetrical. Any function this pattern is used in will be vety simple as there are no choices to make. If you havent guessed this unique pattern is number 4.
Pattern 4 is symmetrical, horizontally, vertically and also diagonally. We have to decide, which symmetrical properties our sketch will be using. We could decide to make the symmetrical properties of our pattern vary and this would make it more complex to manage. Lets use the KISS principle to begin with...(Keep It Simple Stupid).
Pattern 4 required only one statement and two of our patterns are only a little more complex having only 2 possible statements in their code. In our example pattern numbers 5, 6 and 11 have only 2 possible statements.
Lets look at their symmetry:
Pattern 5:

This pattern has 3 possible display options, we can display both images together which forms a grid and is totally symmetrical or we can use one of the images alone, to produce horizontally or vertically, symmetrical stripes.
Pattern 6:

Again we can choose vertical, horizontal or total symmetry.
Pattern 11:

Pattern 11 covers the whole display area with one statement, which has diagonal and either horizonal or vertical symmetry depending on which one of the two statements in the set is used. Using both statements acheives total symmetry.

Each pattern in our next group requires 4 statements to be drawn and has other display options. Lets look at them one by one:
Pattern 2:

Our options are beginning to get more complicated here. We can display each single pattern on its own but this would be assymetrical and would not fill the display screen. The diagonally opposite patterns would be symmetrical on the diagonal axes and would give us another two choices or we could use all the statements, to produce a totally symmetrical pattern which could cover most of all previous patterns in one "coat".
Pattern 3:

This pattern is similar to pattern 2, in that we have 3 symmetrically possible choices but it would probably allow any underlying patterns to show through.
Pattern 8:

Pattern 8 covers the screen in one statement but it is not very symmetrical, having a semi symmetry on one diagonal axis. Using two statements with diagonal symmetry might be a better option or using all four statements in the set gives us a totally symmetrical pattern.
Pattern 9:

I call this pattern the butterfly and although it is an attractive pattern its symmetry could be hard to explain and implement. Depending on the statements chosen it can have total, horizontal, vertical or diagonal symmetry. As in pattern 8 it covers the screen in one statement and each statement has horizontal or vertical symmetry on its own.
Pattern 10:

This is another simple pattern which presents no problems.

Our final two patterns have 8 statements in each set, which further complicates things by allowing more options for symmetrical displays:
Pattern 12:

If we pick out some combinations of statements from the set of Pattern 12, we could find the above patterns but we have probably missed some. We will not discuss the symmetry of pattern 12 here but we will have to study it again when we move it to a function.
Pattern 7:
Like the preceding pattern there are 8 statements in this set. Although we are not going to study Set Theory in this chapter, it may help give us some insight to help us manage the options available. A set has a number of subsets equal to 2 to the power of the number of its elements. In the case of pattern 7 this is simply 2^8. This gives us 2x2x2x2x2x2x2x2 or 256 possible combinations, including the empty set, which we don't want, as it would just result in an empty screen. We could list this set formally as:








Sometimes we end up wishing we hadnt started something and this is one of these times! A couple of hours later and still over 50 combinations short!

Anyway to continue.....
Pattern 7:
We will stop there with pattern 7 but as can be seen, there are many decisions to be made over which combination of pattern 7 statements we will allow, maybe it would be easier to choose the ones we wont allow! Our next task is to place each pattern in its own function and control its drawing from a for loop within the draw method.

No comments:

Post a Comment