mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-22 16:18:28 -05:00
LOLWUT: version 6 initial output. May change a bit.
This commit is contained in:
parent
f019f28e7b
commit
c10889150e
@ -90,12 +90,12 @@ void lolwutCommand(client *c) {
|
||||
* canvas implementation that can be reused. */
|
||||
|
||||
/* Allocate and return a new canvas of the specified size. */
|
||||
lwCanvas *lwCreateCanvas(int width, int height) {
|
||||
lwCanvas *lwCreateCanvas(int width, int height, int bgcolor) {
|
||||
lwCanvas *canvas = zmalloc(sizeof(*canvas));
|
||||
canvas->width = width;
|
||||
canvas->height = height;
|
||||
canvas->pixels = zmalloc(width*height);
|
||||
memset(canvas->pixels,0,width*height);
|
||||
memset(canvas->pixels,bgcolor,width*height);
|
||||
return canvas;
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ typedef struct lwCanvas {
|
||||
} lwCanvas;
|
||||
|
||||
/* Drawing functions implemented inside lolwut.c. */
|
||||
lwCanvas *lwCreateCanvas(int width, int height);
|
||||
lwCanvas *lwCreateCanvas(int width, int height, int bgcolor);
|
||||
void lwFreeCanvas(lwCanvas *canvas);
|
||||
void lwDrawPixel(lwCanvas *canvas, int x, int y, int color);
|
||||
int lwGetPixel(lwCanvas *canvas, int x, int y);
|
||||
|
@ -74,7 +74,7 @@ lwCanvas *lwDrawSchotter(int console_cols, int squares_per_row, int squares_per_
|
||||
int padding = canvas_width > 4 ? 2 : 0;
|
||||
float square_side = (float)(canvas_width-padding*2) / squares_per_row;
|
||||
int canvas_height = square_side * squares_per_col + padding*2;
|
||||
lwCanvas *canvas = lwCreateCanvas(canvas_width, canvas_height);
|
||||
lwCanvas *canvas = lwCreateCanvas(canvas_width, canvas_height, 0);
|
||||
|
||||
for (int y = 0; y < squares_per_col; y++) {
|
||||
for (int x = 0; x < squares_per_row; x++) {
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user