Last active
February 13, 2016 12:19
-
-
Save yangshun/b061c0f00f6ec2f3c7fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Directory structure: | |
## dir | |
## |-- gen_runes.py | |
## |-- graphics.py | |
## |-- PyGif.py | |
## +-- runes.py | |
## Put submissions in the same directory as this file. | |
## Make sure there are no other .py files besides | |
## the submissions and the whitelisted files | |
## Usage: | |
## $ python3 gen_runes.py | |
## Rendered images will be saved in the `rendered` directory: | |
## Final directory structure: | |
## dir | |
## |-- gen_runes.py | |
## |-- graphics.py | |
## |-- PyGif.py | |
## |-- runes.py | |
## |-- submission-1.py | |
## |-- submission-2.py | |
## +-- rendered | |
## |-- submission-1.py.png | |
## +-- submission-2.py.png | |
import os, time, traceback | |
whitelisted_filenames = ['gen_runes.py', 'graphics.py', 'PyGif.py', 'runes.py'] | |
filenames = [filename for filename in os.listdir('./') if (filename.endswith('.py') and filename not in whitelisted_filenames)] | |
try: | |
os.mkdir('rendered') | |
except FileExistsError: | |
pass | |
for filename in filenames: | |
try: | |
start = time.time() | |
module = filename[0:filename.rfind('.py')] | |
rune = __import__(module) | |
os.chdir('./rendered') | |
try: | |
rune.save_hollusion(filename) | |
except: # runes.py throws an invalid exception type >_< | |
rune.save_image(filename[0:filename.rfind('.py')]) | |
rune.clear_all() | |
rune.graphics.show_viewport(rune.vp) | |
print(filename, '(' + str(round(time.time() - start, 2)) + 's)') | |
del rune | |
os.chdir('../') | |
except: | |
traceback.print_exc() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment