Generate a skyline inspired by the parallax backgrounds of 8 bit games. */
| 121 | |
| 122 | /* Generate a skyline inspired by the parallax backgrounds of 8 bit games. */ |
| 123 | void generateSkyline(lwCanvas *canvas) { |
| 124 | struct skyscraper si; |
| 125 | |
| 126 | /* First draw the background skyscraper without windows, using the |
| 127 | * two different grays. We use two passes to make sure that the lighter |
| 128 | * ones are always in the background. */ |
| 129 | for (int color = 2; color >= 1; color--) { |
| 130 | si.color = color; |
| 131 | for (int offset = -10; offset < canvas->width;) { |
| 132 | offset += rand() % 8; |
| 133 | si.xoff = offset; |
| 134 | si.width = 10 + rand()%9; |
| 135 | if (color == 2) |
| 136 | si.height = canvas->height/2 + rand()%canvas->height/2; |
| 137 | else |
| 138 | si.height = canvas->height/2 + rand()%canvas->height/3; |
| 139 | si.windows = 0; |
| 140 | generateSkyscraper(canvas, &si); |
| 141 | if (color == 2) |
| 142 | offset += si.width/2; |
| 143 | else |
| 144 | offset += si.width+1; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | /* Now draw the foreground skyscraper with the windows. */ |
| 149 | si.color = 0; |
| 150 | for (int offset = -10; offset < canvas->width;) { |
| 151 | offset += rand() % 8; |
| 152 | si.xoff = offset; |
| 153 | si.width = 5 + rand()%14; |
| 154 | if (si.width % 4) si.width += (si.width % 3); |
| 155 | si.height = canvas->height/3 + rand()%canvas->height/2; |
| 156 | si.windows = 1; |
| 157 | generateSkyscraper(canvas, &si); |
| 158 | offset += si.width+5; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | /* The LOLWUT 6 command: |
| 163 | * |
no test coverage detected