chore: initialize repository and staged implementation plan

This commit is contained in:
Mikhail committed 2026-11-26 15:23:50 +03:00
commit cb0e9d156f
48 files changed
+7343

No files matched your search

Binary file not shown.

After

Width:  |  Height:  |  Size: 169 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 223 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 431 B

+57
View File
@@ -0,0 +1,57 @@
#!/usr/bin/env python3
"""
Утилита для конвертации цветного PNG в 1-битный спрайт 40x40.
Использование: python3 make_sprite.py <input.png> <output.png> [опции]
"""
import argparse
from PIL import Image, ImageOps
def main():
parser = argparse.ArgumentParser(description="Downscale PNG to 1-bit sprite (40x40).")
parser.add_argument("input", help="Путь к исходному файлу (PNG/JPG)")
parser.add_argument("output", help="Путь для сохранения спрайта (PNG)")
parser.add_argument("--size", type=int, default=40, help="Размер спрайта (по умолчанию 40)")
parser.add_argument("--invert", action="store_true", help="Инвертировать цвета (белый фон, черный объект)")
parser.add_argument("--dither", action="store_true", help="Включить дизеринг (сглаживание точками)")
parser.add_argument("--pad", action="store_true", help="Добавить поля (не обрезать), вместо обрезки по центру")
args = parser.parse_args()
try:
img = Image.open(args.input).convert("RGBA")
except Exception as e:
print(f"Ошибка открытия файла: {e}")
return
# Если есть прозрачность, накладываем на белый фон, чтобы она не стала черной
bg = Image.new("RGBA", img.size, (255, 255, 255, 255))
bg.paste(img, (0, 0), img)
img = bg.convert("L") # В оттенки серого
# Масштабирование
if args.pad:
# Вписываем в 40x40 с сохранением пропорций (добавляет поля)
img = ImageOps.contain(img, (args.size, args.size), method=Image.Resampling.LANCZOS)
canvas = Image.new("L", (args.size, args.size), 255) # Белый фон
offset = ((args.size - img.width) // 2, (args.size - img.height) // 2)
canvas.paste(img, offset)
img = canvas
else:
# Заполняет 40x40 с обрезкой лишнего по краям (центрирование)
img = ImageOps.fit(img, (args.size, args.size), method=Image.Resampling.LANCZOS)
# Инверсия
if args.invert:
img = ImageOps.invert(img)
# Перевод в 1-бит
if args.dither:
img_1bit = img.convert("1") # С дизерингом (Флойд-Стейнберг)
else:
img_1bit = img.convert("1", dither=Image.Dither.NONE) # Четкие пиксели
img_1bit.save(args.output)
print(f"Готово! Сохранено в {args.output} ({args.size}x{args.size}, 1-bit)")
if __name__ == "__main__":
main()
Binary file not shown.

After

Width:  |  Height:  |  Size: 309 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 378 B