Advertisement
Guest User

table generation

a guest
Jun 10th, 2015
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.45 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. #        DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
  5. #                    Version 2, December 2004
  6. #
  7. # Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
  8. #
  9. # Everyone is permitted to copy and distribute verbatim or modified
  10. # copies of this license document, and changing it is allowed as long
  11. # as the name is changed.
  12. #
  13. #            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
  14. #   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  15. #
  16. #  0. You just DO WHAT THE FUCK YOU WANT TO.
  17.  
  18. import os.path
  19.  
  20. #import basic pygame modules
  21. import pygame
  22. from pygame.locals import *
  23.  
  24. #see if we can load more than standard BMP
  25. if not pygame.image.get_extended():
  26.     raise SystemExit("Sorry, extended image module required")
  27.  
  28. levels = u"""\
  29.                \
  30.                \
  31. !"#$%&'()*+,-./\
  32. 0123456789:;<=>?\
  33. @ABCDEFGHIJKLMNO\
  34. PQRSTUVWXYZ[\]^_\
  35. `abcdefghijklmno\
  36. pqrstuvwxyz{|}~ \
  37.  ,ƒ„…†‡^‰Š‹Œ Ž \
  38. ‘’“”·–—˜™š›œ žŸ\
  39. ¡ȼ£¤¥¦§¨©ª«¬-®¯\
  40. °±²³´µ¶·¸¹º»¼½¾¿\
  41. ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏ\
  42. ÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞß\
  43. àáâãäåæçèéêëìíîï\
  44. ðñòóôõö÷øùúûüýþÿ\
  45. """
  46.  
  47. DATA_PATH = os.path.split(os.path.abspath(__file__))[0]
  48.  
  49. def get_text(surface):
  50.     """ We render the char, and then convert the image to table
  51.    """
  52.     font = pygame.font.Font("DejaVuSerif.ttf", 48)
  53.     for y in range(0, 16):
  54.         for x in range(0, 16):
  55.             pos = y * 16 + x
  56.             limit = pos % (len(levels))
  57.             image = font.render(levels[limit], True, Color("white"))
  58.             _, _, width, height = image.get_rect()
  59.             print levels[limit], width, height
  60.             surface.blit(image, (x*64 + 5,y*64 + 5))
  61.  
  62. def load_image(file):
  63.     """ Loads an image, prepares it for play.
  64.        **file** The file to load
  65.        **return** the surface converted.
  66.    """
  67.     file = os.path.join(DATA_PATH, 'data', file)
  68.     try:
  69.         surface = pygame.image.load(file)
  70.     except pygame.error:
  71.         raise SystemExit('Could not load image "%s" %s'%(file, pygame.get_error()))
  72.     return surface.convert_alpha()
  73.  
  74. def main(winstyle = 0):
  75.     pygame.init()
  76.  
  77.     surface = pygame.Surface((1024, 1024))
  78.  
  79.     #screen.blit(load_image("logo.png"), (0, 0))
  80.  
  81.     get_text(surface)
  82.     pygame.image.save(surface,'oolite-font.png')
  83.  
  84.     pygame.quit()
  85.  
  86. if __name__ == '__main__':
  87.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement