diff options
Diffstat (limited to 'brutalmaze/misc.py')
-rw-r--r-- | brutalmaze/misc.py | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/brutalmaze/misc.py b/brutalmaze/misc.py index d26edf4..008d7cf 100644 --- a/brutalmaze/misc.py +++ b/brutalmaze/misc.py @@ -19,8 +19,10 @@ __doc__ = 'Brutal Maze module for miscellaneous functions' +from datetime import datetime from itertools import chain from math import degrees, cos, sin, pi +from os import path from random import shuffle, uniform import pygame @@ -40,9 +42,9 @@ def randsign(): def regpoly(n, R, r, x, y): - """Return the pointlist of the regular polygon with n sides, - circumradius of R, the center point I(x, y) and one point A make the - vector IA with angle r (in radians). + """Return pointlist of a regular n-gon with circumradius of R, + center point I(x, y) and corner A that angle of vector IA is r + (in radians). """ r %= pi * 2 angles = [r + pi*2*side/n for side in range(n)] @@ -50,7 +52,7 @@ def regpoly(n, R, r, x, y): def fill_aapolygon(surface, points, color): - """Draw a filled polygon with anti aliased edges onto a surface.""" + """Draw a filled polygon with anti-aliased edges onto a surface.""" aapolygon(surface, points, color) filled_polygon(surface, points, color) @@ -72,6 +74,15 @@ def cosin(x): return cos(x) + sin(x) +def join(iterable, sep=' ', end='\n'): + """Return a string which is the concatenation of string + representations of objects in the iterable, separated by sep. + + end is appended to the resulting string. + """ + return sep.join(map(str, iterable)) + end + + def around(x, y): """Return grids around the given one in random order.""" a = [(x + i, y + j) for i, j in ADJACENTS] @@ -111,3 +122,11 @@ def play(sound, volume=1.0, angle=None): volumes[i] = 1.0 sound.set_volume(1.0) channel.set_volume(*volumes) + + +def json_rec(directory): + """Return path to JSON file to be created inside the given directory + based on current time local to timezone in ISO 8601 format. + """ + return path.join( + directory, '{}.json'.format(datetime.now().isoformat()[:19])) |