summaryrefslogtreecommitdiff
path: root/src/lolwut6.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2019-10-07 18:24:34 +0200
committerantirez <antirez@gmail.com>2019-10-07 18:24:34 +0200
commitc10889150ef10a30edb2ba0503b06154222458df (patch)
tree8e2b9a40d5d7472ba5189afd5dd53ca6d53fd0ee /src/lolwut6.c
parentf019f28e7b9f05205c02261bb3af8261869d600a (diff)
downloadredis-c10889150ef10a30edb2ba0503b06154222458df.tar.gz
LOLWUT: version 6 initial output. May change a bit.
Diffstat (limited to 'src/lolwut6.c')
-rw-r--r--src/lolwut6.c38
1 files changed, 29 insertions, 9 deletions
diff --git a/src/lolwut6.c b/src/lolwut6.c
index 8cc8d6e04..44c933629 100644
--- a/src/lolwut6.c
+++ b/src/lolwut6.c
@@ -114,14 +114,34 @@ void generateSkyscraper(lwCanvas *canvas, struct skyscraper *si) {
/* Generate a skyline inspired by the parallax backgrounds of 8 bit games. */
void generateSkyline(lwCanvas *canvas) {
- struct skyscraper si = {
- .xoff = 4,
- .width = 13,
- .height = 15,
- .windows = 1,
- .color = 1
- };
- generateSkyscraper(canvas, &si);
+ struct skyscraper si;
+
+ /* First draw the background skyscraper without windows, using the
+ * two different grays. */
+ si.color = 1;
+ for (int offset = -10; offset < canvas->width;) {
+ offset += rand() % 8;
+ si.xoff = offset;
+ si.width = 10 + rand()%9;
+ si.height = canvas->height/2 + rand()%canvas->height/2;
+ si.windows = 0;
+ si.color = si.color == 1 ? 2 : 1;
+ generateSkyscraper(canvas, &si);
+ offset += si.width/2;
+ }
+
+ /* Now draw the foreground skyscraper with the windows. */
+ si.color = 0;
+ for (int offset = -10; offset < canvas->width;) {
+ offset += rand() % 8;
+ si.xoff = offset;
+ si.width = 5 + rand()%14;
+ if (si.width % 4) si.width += (si.width % 3);
+ si.height = canvas->height/2 + rand()%canvas->height/2;
+ si.windows = 1;
+ generateSkyscraper(canvas, &si);
+ offset += si.width+1;
+ }
}
/* The LOLWUT 6 command:
@@ -152,7 +172,7 @@ void lolwut6Command(client *c) {
if (rows > 1000) rows = 1000;
/* Generate the city skyline and reply. */
- lwCanvas *canvas = lwCreateCanvas(cols,rows);
+ lwCanvas *canvas = lwCreateCanvas(cols,rows,3);
generateSkyline(canvas);
sds rendered = renderCanvas(canvas);
rendered = sdscat(rendered,