Skip to content

Latest commit

 

History

40 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sprite-generator

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.

matrix examples:

- spaceships

                    [[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:

- aliens

                [[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:

todo

development steps

  • Setup project and dev environment
  • Create single image generator
  • Create canvas generator
  • Generate color images

additional steps

  • Add tests to the project
  • Add docstring

running the project and tests

run project

prepare destination folder

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.

advice:

If you generate image or atlas of images close the destination folder to render images properly.

generate figures indexes

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.

generate sprite (single image)

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

generate canvas (atlas of images)

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

run tests

pytest  -v -cov

license

This project is licensed under the [MIT] License - see License.md

About

Script to generate small pixel images of robots or spaceships

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages