Script to generate procedurally pixel images that are similar to the old days of video game sprites.
Generator idea is based on pixel-sprite-generator and Sprite-Generator.
The sprites are generated based on 2-dimensional matrix of numbers related to colors.
The colors are randomized, the matrix can be mirrored if needed, and the final result is rendered into single image or canvas element (atlas).
Algorithm of converting matrix values into colors:
---------------------------------------------------------------------
| value | description |
|----------|--------------------------------------------------------|
| 0 | white omitted from assigning to color (background) |
|----------|--------------------------------------------------------|
| 1 | black (shape) |
|----------|--------------------------------------------------------|
| -1 and 2 | random colors (body) |
---------------------------------------------------------------------
Tool includes some predefined matrix patterns in figures.py, but it's possible to add new custom ones through this file.
[[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 1, 1],
[0, 0, 0, 0, 1, -1, -1, -1],
[0, 0, 0, 1, -1, -1, -1, -1],
[0, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1],
[0, 1, 1, 2, 1, 2, 1, 2],
[0, 0, 1, 1, 1, 1, 1, 1],
[0, 0, 0, 0, 0, 0, 0, 0]]
Single image:
Atlas:
[[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 1, 1],
[0, 0, 0, 0, 1, 1, 1, 1],
[0, 0, 0, 1, 1, 1, 1, 1],
[0, 0, 0, 1, 1, 2, 2, 2],
[0, 0, 0, 1, 1, 2, 2, 2],
[0, 0, 1, 1, 1, 1, 1, 1],
[0, 0, 1, 1, 1, 1, 1, -1],
[0, 1, 1, 1, 1, -1, -1, -1],
[0, 1, 1, 1, 1, -1, -1, 1],
[0, 1, 1, 1, 0, 1, 1, 0],
[0, 1, 1, 1, 0, 1, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0]]
Single image:
Atlas:
- Setup project and dev environment
- Create single image generator
- Create canvas generator
- Generate color images
- Add tests to the project
- Add docstring
After you run any of generating commands you will have two prompts:
Name of the image and Path to folder.
In Path to folder copy and paste path of your destination.
The path will be saved in the automatically created json file called:
folder_path.json.
Every time after the generated image will be saved in that destination folder and there will be only prompt about the name of the image.
If you want to change destination folder just delete folder_path.json and Path to folder will reappear.
If you generate image or atlas of images close the destination folder to render images properly.
Getting dictionary with indexes of all available items in the figures.py file.
python3 figures_dict.py
The index is needed for generate commands described in next points below.
Use command:
python3 generate_sprite.py index is_color is_mirror size
where:
index -> index of the figure to be rendered
is_color -> black & white if 0 and color image if 1
is_mirror -> mirrored if 1 otherwise 0
size -> size of image in pixels
Use command:
python3 generate_canvas.py index is_color is_mirror size sprites_amount
where:
index -> index of the figure to be rendered
is_color -> black & white if 0 and color image if 1
is_mirror -> mirrored if 1 otherwise 0
size -> size of single image in pixels
sprites_amount -> total amount of sprites on the canvas
pytest -v -cov
This project is licensed under the [MIT] License - see License.md