Challenge:
Given an integer \$n\$, guaranteed to be \$\geq2\$ and a power of 2, we are going to draw multiply boards either side-by-side or below one another, where the first has dimensions of \$n\$ by \$n\$; the second \$\frac{n}{2}\$ by \$\frac{n}{2}\$; the third \$\frac{n}{4}\$ by \$\frac{n}{4}\$; etc.; until the final \$1\$ by \$1\$ pixel.
The first \$n\$ by \$n\$ board will have its pixels uniformly randomly generated with black (rgb(0,0,0)
/#000000
) and white (rgb(255,255,255)
/#FFFFFF
) pixels. The next \$\frac{n}{2}\$ by \$\frac{n}{2}\$ compressed image will have each 2x2 block of pixels reduced to the color with the most pixels in that block (thus if a 2x2 block has four or three pixels of the same color, it becomes that color; and if both colors have two pixels each, we again choose one uniformly randomly).
It must be clear how the boards of each iteration are separated.†
Challenge rules:
- Output is flexible, but must be a graphical-output. So it can be drawn and shown in a frame/canvas; output to an image-file on disk; drawn in a graph; generated as black/white Minecraft Wool blocks; generated as colored MS Excel cells; etc.
- †As mentioned, it should be clear how the boards of each iteration are separated. This can for example be done by using a non-white and non-black color: setting a background of your canvas with a single pixel delimiter between boards or surrounding each board with a border. Alternatively you can output each board separately, in its own image-file or own canvas tab/window perhaps.
- The iterations can be drawn both horizontally or vertically, and alignment is irrelevant (e.g. vertical output with right aligned blocks is fine).
- The size of the individual blocks doesn't necessarily have to be a single pixel, as long as they are all the same size and squares.
Example:
Input: \$8\$
Potential output - horizontal; bottom-aligned; red background as separator:
Same example output, but vertical, right-aligned, with a blue border as separator instead:
General rules:
- This is code-golf, so the shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language. - Standard rules apply for your answer with default input rules and graphical output rules.
- Default Loopholes are forbidden.
- If possible, please add a link with a test for your code, and if not, please include an example screenshot of the output.
- Also, adding an explanation for your answer is highly recommended.
[ascii-art]
challenges that can be done with[graphical-output]
, and vice-versa, but I personally see them as two different things. \$\endgroup\$