Schotter, the output of LOLWUT of Redis 5, is a computer graphic art piece * generated by Georg Nees in the 60s. It explores the relationship between * caos and order. * * The function creates the canvas itself, depending on the columns available * in the output display and the number of squares per row and per column * requested by the caller. */
| 69 | * in the output display and the number of squares per row and per column |
| 70 | * requested by the caller. */ |
| 71 | lwCanvas *lwDrawSchotter(int console_cols, int squares_per_row, int squares_per_col) { |
| 72 | /* Calculate the canvas size. */ |
| 73 | int canvas_width = console_cols*2; |
| 74 | int padding = canvas_width > 4 ? 2 : 0; |
| 75 | float square_side = (float)(canvas_width-padding*2) / squares_per_row; |
| 76 | int canvas_height = square_side * squares_per_col + padding*2; |
| 77 | lwCanvas *canvas = lwCreateCanvas(canvas_width, canvas_height, 0); |
| 78 | |
| 79 | for (int y = 0; y < squares_per_col; y++) { |
| 80 | for (int x = 0; x < squares_per_row; x++) { |
| 81 | int sx = x * square_side + square_side/2 + padding; |
| 82 | int sy = y * square_side + square_side/2 + padding; |
| 83 | /* Rotate and translate randomly as we go down to lower |
| 84 | * rows. */ |
| 85 | float angle = 0; |
| 86 | if (y > 1) { |
| 87 | float r1 = (float)rand() / (float) RAND_MAX / squares_per_col * y; |
| 88 | float r2 = (float)rand() / (float) RAND_MAX / squares_per_col * y; |
| 89 | float r3 = (float)rand() / (float) RAND_MAX / squares_per_col * y; |
| 90 | if (rand() % 2) r1 = -r1; |
| 91 | if (rand() % 2) r2 = -r2; |
| 92 | if (rand() % 2) r3 = -r3; |
| 93 | angle = r1; |
| 94 | sx += r2*square_side/3; |
| 95 | sy += r3*square_side/3; |
| 96 | } |
| 97 | lwDrawSquare(canvas,sx,sy,square_side,angle,1); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | return canvas; |
| 102 | } |
| 103 | |
| 104 | /* Converts the canvas to an SDS string representing the UTF8 characters to |
| 105 | * print to the terminal in order to obtain a graphical representaiton of the |
no test coverage detected