Skip to content

Commit e61a38f

Browse files
committed
📓 add readme s
1 parent cd458e6 commit e61a38f

File tree

13 files changed

+114
-9
lines changed

13 files changed

+114
-9
lines changed

.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ node_modules
22
npm-debug.log*
33
yarn-error.log*
44
dist
5-
build
6-
out.gif
5+
build

README.md

+32-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,39 @@
33
![type definitions](https://img.shields.io/npm/types/typescript?style=flat-square)
44
![code style](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)
55

6+
Generates a snake game from a github user contributions grid
7+
68
![](https://raw.githubusercontent.com/Platane/snk/output/github-contribution-grid-snake.gif)
79

8-
Generates a snake game from a github user contributions grid and output a screen capture as gif
10+
Pull a github user's contribution grid.
11+
Make it a snake Game, generate a snake path where the cells get eaten in an orderly fashion.
12+
13+
Generate a [gif](https://github.com/Platane/snk/raw/output/github-contribution-grid-snake.gif) or [svg](https://github.com/Platane/snk/raw/output/github-contribution-grid-snake.svg) image.
14+
15+
Available as github action. Automatically generate a new image at the end of the day. Which make for great [github profile readme](https://docs.github.com/en/free-pro-team@latest/github/setting-up-and-managing-your-github-profile/managing-your-profile-readme)
16+
17+
## Usage
18+
19+
**github action**
20+
21+
```yaml
22+
- uses: Platane/snk@master
23+
with:
24+
github_user_name: platane
25+
gif_out_path: dist/github-contribution-grid-snake.gif
26+
svg_out_path: dist/github-contribution-grid-snake.svg
27+
```
28+
29+
> [example with cron job](https://github.com/Platane/Platane/blob/master/.github/workflows/main.yml#L13-L18)
30+
31+
**interactive demo**
32+
33+
[platane.github.io/snk](https://platane.github.io/snk)
34+
35+
**local**
936
10-
- [demo](https://platane.github.io/snk)
37+
```
38+
npm install
1139

12-
- [github action](https://github.com/marketplace/actions/generate-snake-game-from-github-contribution-grid)
40+
npm run dev:demo
41+
```

action.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
name: "generate-snake-game-from-github-contribution-grid"
2-
description: "Generates a snake game from a github user contributions grid and output a screen capture as gif"
2+
description: "Generates a snake game from a github user contributions grid. Output the animation as gif or svg"
33
author: "platane"
44

55
outputs:
66
gif_out_path:
7-
description: "path of the generated gif"
7+
description: "path of the generated gif. If left empty, will not generate a gif file"
88
svg_out_path:
9-
description: "path of the generated svg"
9+
description: "path of the generated svg. If left empty, will not generate a svg file"
1010

1111
runs:
1212
using: "docker"

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "snk",
3-
"description": "Generates a snake game from a github user contributions grid and output a screen capture as gif",
3+
"description": "Generates a snake game from a github user contributions grid",
44
"version": "1.0.0",
55
"private": true,
66
"repository": "github:platane/snk",

packages/action/README.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# @snk/action
2+
3+
Contains the github action code.
4+
5+
## Implementation
6+
7+
### Docker
8+
9+
Because the gif generation requires some native libs, we cannot use a node.js action.
10+
11+
Use a docker action instead, the image is created from the [Dockerfile](./Dockerfile).
12+
13+
It's published to [dockerhub](https://hub.docker.com/repository/docker/platane/snk) which makes for faster build ( compare to building the image when the action runs )
14+
15+
Notice that the [action.yml](../../action.yml) point to the latest version of the image. Which makes releasing sematic versioning of the action pointless. Which is probably fine for a wacky project like this one.

packages/compute/README.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# @snk/compute
2+
3+
Contains the algorithm to compute the best route given a grid and a starting position for the snake.
4+
5+
## Implementation
6+
7+
- for each color in the grid
8+
9+
- 1\ **clear residual color** phase
10+
11+
- find all the cells of a previous color that are "tunnel-able" ( ie: the snake can find a path from the outside of the grid to the cell, and can go back to the outside without colliding ). The snake is allowed to pass thought current and previous color. Higher colors are walls
12+
13+
- sort the "tunnel-able" cell, there is penalty for passing through current color, as previous color should be eliminated as soon as possible.
14+
15+
- for cells with the same score, take the closest one ( determined with a quick mathematic distance, which is not accurate but fast at least )
16+
17+
- navigate to the cell, and through the tunnel.
18+
19+
- re-compute the list of tunnel-able cells ( as eating cells might have freed better tunnel ) as well as the score
20+
21+
- iterate
22+
23+
- 2\ **clear clean color** phase
24+
25+
- find all the cells of the current color that are "tunnel-able"
26+
27+
- no need to consider scoring here. In order to improve efficiency, get the closest cell by doing a tree search ( instead of a simple mathematic distance like in the previous phase )
28+
29+
- navigate to the cell, and through the tunnel.
30+
31+
- iterate
32+
33+
- go back to the starting point

packages/demo/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# @snk/demo
2+
3+
Contains various demo to test and validate some pieces of the algorithm.

packages/draw/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# @snk/draw
2+
3+
Draw grids and snakes on a canvas.

packages/gif-creator/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# @snk/gif-creator
2+
3+
Generate a gif file from the grid and snake path.
4+
5+
Relies on graphics magic and gifsicle binaries.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# @snk/github-user-contribution-service
2+
3+
Expose github-user-contribution as an endpoint, using vercel.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# @snk/github-user-contribution
2+
3+
Get the github user contribution grid
4+
5+
## Implementation
6+
7+
Based on the html page. Which is very unstable. Might switch to using github api but afaik it's a bit complex.

packages/svg-creator/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# @snk/svg-creator
2+
3+
Generate a svg file from the grid and snake path.
4+
5+
Uses css style tag to animate the snake and the grid cells. For that reason it only work in browser. Animations are likely to be ignored be native image reader.

packages/types/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# @snk/types
2+
3+
set of basic types and helpers

0 commit comments

Comments
 (0)