Write the smallest program you can to create affine fractals. You may use any method you feel like that generates the same results as the rules below. You don't have to use any ideas from the suggested methods!
Your program will take two inputs, the first to define the pattern in the format 074
made of three digits from 0 to 7. The second input will define the size, 3
will be 8x8, 4
will be 16x16 and so on (2^n). Your program must output the correct result for all sizes from 0 (1x1) to at least 5 (32x32). If it produces any output for higher numbers it must be correct, i.e. it must produce the correct output up to a certain size but produce no output above that size if it would be wrong. You may assume a maximum size of 15 (32768x32768) as that is already an insane size for ASCII art (1GB)!
An 8x8 pattern will look something like below (rule 160
). The left-most digit will be for block A
, the middle digit (no rude thoughts please!) for block B
and the right-most digit for block C
. To construct the fractal, shrink it by a half in both dimensions, and apply the rotation/mirroring rule for the block. To shrink the pattern divide it evenly into 2x2 areas. There will either be 3 visible characters or none in each area. If there are visible characters place a character in the appropriate place in the smaller block, otherwise place a space. Rules 0
-3
are not mirrored, rules 4
-7
are mirrored. Rules 0
and 4
are not rotated, 1
and 5
are rotated 90 degrees clockwise, 2
and 6
are rotated 180 degrees, 3
and 7
are rotated 270 degrees clockwise. Stitch the three blocks together in the order shown, A
in the top-left corner, B
bottom-left and C
bottom-right.
AAA
AA A
AA
A
BBB CC
B BBC
BBCCC
B CCC
Shrunk, rotated and mirrored by rule number:
0 1 2 3 4 5 6 7
---- ---- ---- ---- ---- ---- ---- ----
AA BAA CCB C C BCC AAB AA
A BB A CBB CC CC BBC A BB A
BBC CC A A BB BB A A CC CBB
BCC C AA AAB BAA AA C CCB
Rules:
- Not mirrored, Rotated 90 degrees clockwise
- Not mirrored, Rotated 180 degrees clockwise
- Not mirrored, Rotated 270 degrees clockwise
- Mirrored but not rotated
- Mirrored then Rotated 90 degrees clockwise
- Mirrored then Rotated 180 degrees clockwise
- Mirrored then Rotated 270 degrees clockwise
- Rule 0: Not mirrored, Not rotated
The mirroring is always done first and is done diagonally through the blank corner e.g. rule 0 vs rule 4:
0 4
---- ----
AA / C /
A / CC/
BBC BB A
/BCC /BAA
Only rules 1
, 6
and 0
are used in the above pattern, in that order. After the transformations have been applied and the blocks stitched together it will look like the below except I have spaced each block from each other by one space. Your code will not have this extra space in it. If you compare it to the "parent" image you will see that it has visible characters in the same positions.
BAA
BB A
CC
C
AAB AA
A BB A
CC BBC
C BCC
Another way to generate the image without shrinking is as follows: Start with one character:
X
Apply the transformations for each of the three blocks (none since it's only one character) and stitch the blocks together:
X
XX
Apply the transformations for each of the three blocks again:
1
--
XX
X
6 0
-- --
XX X
X XX
Stitch them together:
XX
X
XXX
XXX
Apply the transformations for each of the three blocks again:
1
----
XXX
XX X
XX
X
6 0
---- ----
XXX XX
X XX X
XX XXX
X XXX
Stitch them together:
XXX
XX X
XX
X
XXX XX
X XXX
XXXXX
X XXX
You may use any printable character or characters (0x21 - 0x7E) for the visible part of the pattern but only the space character (0x20) for the blanks. Trailing spaces are allowed but there must be no blanks outside the entire square (i.e. for an 8x8 square there can be no characters past column 8).
There are 512 different rules, but some of them produce the same pattern. As a side note, any pattern containing only 0
and 4
will produce the Sierpinski triangle (8 different rules).
You may optionally post your favourite pattern and the rule that generates it. If you do, make sure the size is at least 3 (8x8) to distinguish it from similar rules.