Skip to content

Instantly share code, notes, and snippets.

@Hoolean
Created August 9, 2018 13:50
Show Gist options
  • Save Hoolean/3c09c598f4384904deccc60e7af0ed14 to your computer and use it in GitHub Desktop.
Save Hoolean/3c09c598f4384904deccc60e7af0ed14 to your computer and use it in GitHub Desktop.
import pygame
import glob
import math
tiles = [pygame.image.load(tile) for tile in glob.glob('*.png')]
tile_length = max([max([tile.get_width(), tile.get_height()]) for tile in tiles])
side = math.ceil(math.sqrt(len(tiles)))
stitched = pygame.surface([side * tile_length, side * tile_length], pygame.SRCALPHA, 32)
for index, tile in tiles:
x = index % side
y = int(index / side)
stitched.blit(tile, (x * tile_length, y * tile_length))
pygame.image.save(stitched, 'stitched.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment