Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
c1088915
Commit
c1088915
authored
Oct 07, 2019
by
antirez
Browse files
LOLWUT: version 6 initial output. May change a bit.
parent
f019f28e
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/lolwut.c
View file @
c1088915
...
@@ -90,12 +90,12 @@ void lolwutCommand(client *c) {
...
@@ -90,12 +90,12 @@ void lolwutCommand(client *c) {
* canvas implementation that can be reused. */
* canvas implementation that can be reused. */
/* Allocate and return a new canvas of the specified size. */
/* 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
));
lwCanvas
*
canvas
=
zmalloc
(
sizeof
(
*
canvas
));
canvas
->
width
=
width
;
canvas
->
width
=
width
;
canvas
->
height
=
height
;
canvas
->
height
=
height
;
canvas
->
pixels
=
zmalloc
(
width
*
height
);
canvas
->
pixels
=
zmalloc
(
width
*
height
);
memset
(
canvas
->
pixels
,
0
,
width
*
height
);
memset
(
canvas
->
pixels
,
bgcolor
,
width
*
height
);
return
canvas
;
return
canvas
;
}
}
...
...
src/lolwut.h
View file @
c1088915
...
@@ -41,7 +41,7 @@ typedef struct lwCanvas {
...
@@ -41,7 +41,7 @@ typedef struct lwCanvas {
}
lwCanvas
;
}
lwCanvas
;
/* Drawing functions implemented inside lolwut.c. */
/* 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
lwFreeCanvas
(
lwCanvas
*
canvas
);
void
lwDrawPixel
(
lwCanvas
*
canvas
,
int
x
,
int
y
,
int
color
);
void
lwDrawPixel
(
lwCanvas
*
canvas
,
int
x
,
int
y
,
int
color
);
int
lwGetPixel
(
lwCanvas
*
canvas
,
int
x
,
int
y
);
int
lwGetPixel
(
lwCanvas
*
canvas
,
int
x
,
int
y
);
...
...
src/lolwut5.c
View file @
c1088915
...
@@ -74,7 +74,7 @@ lwCanvas *lwDrawSchotter(int console_cols, int squares_per_row, int squares_per_
...
@@ -74,7 +74,7 @@ lwCanvas *lwDrawSchotter(int console_cols, int squares_per_row, int squares_per_
int
padding
=
canvas_width
>
4
?
2
:
0
;
int
padding
=
canvas_width
>
4
?
2
:
0
;
float
square_side
=
(
float
)(
canvas_width
-
padding
*
2
)
/
squares_per_row
;
float
square_side
=
(
float
)(
canvas_width
-
padding
*
2
)
/
squares_per_row
;
int
canvas_height
=
square_side
*
squares_per_col
+
padding
*
2
;
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
y
=
0
;
y
<
squares_per_col
;
y
++
)
{
for
(
int
x
=
0
;
x
<
squares_per_row
;
x
++
)
{
for
(
int
x
=
0
;
x
<
squares_per_row
;
x
++
)
{
...
...
src/lolwut6.c
View file @
c1088915
...
@@ -114,14 +114,34 @@ void generateSkyscraper(lwCanvas *canvas, struct skyscraper *si) {
...
@@ -114,14 +114,34 @@ void generateSkyscraper(lwCanvas *canvas, struct skyscraper *si) {
/* Generate a skyline inspired by the parallax backgrounds of 8 bit games. */
/* Generate a skyline inspired by the parallax backgrounds of 8 bit games. */
void
generateSkyline
(
lwCanvas
*
canvas
)
{
void
generateSkyline
(
lwCanvas
*
canvas
)
{
struct
skyscraper
si
=
{
struct
skyscraper
si
;
.
xoff
=
4
,
.
width
=
13
,
/* First draw the background skyscraper without windows, using the
.
height
=
15
,
* two different grays. */
.
windows
=
1
,
si
.
color
=
1
;
.
color
=
1
for
(
int
offset
=
-
10
;
offset
<
canvas
->
width
;)
{
};
offset
+=
rand
()
%
8
;
generateSkyscraper
(
canvas
,
&
si
);
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:
/* The LOLWUT 6 command:
...
@@ -152,7 +172,7 @@ void lolwut6Command(client *c) {
...
@@ -152,7 +172,7 @@ void lolwut6Command(client *c) {
if
(
rows
>
1000
)
rows
=
1000
;
if
(
rows
>
1000
)
rows
=
1000
;
/* Generate the city skyline and reply. */
/* Generate the city skyline and reply. */
lwCanvas
*
canvas
=
lwCreateCanvas
(
cols
,
rows
);
lwCanvas
*
canvas
=
lwCreateCanvas
(
cols
,
rows
,
3
);
generateSkyline
(
canvas
);
generateSkyline
(
canvas
);
sds
rendered
=
renderCanvas
(
canvas
);
sds
rendered
=
renderCanvas
(
canvas
);
rendered
=
sdscat
(
rendered
,
rendered
=
sdscat
(
rendered
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment