Last active
January 30, 2018 16:55
-
-
Save morgulbrut/e8d31c7bcd7acaa6376601e4bd89defb 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
#!/usr/bin/env python | |
from random import shuffle | |
def generate(x_size, y_size): | |
'''generates pattern in the form: | |
[0,1,2] | |
[1,2,0] | |
[2,0,1] | |
''' | |
l = [] | |
for i in range(x_size): | |
temp = [] | |
for j in range(y_size): | |
temp.append((i + j) % x_size) | |
l.append(temp) | |
return l | |
def generate_from_list(l, y_size, n=1): | |
''' Generates a pattern from a given list, | |
the optional parameter n defines how much | |
the list gets rotated per line''' | |
ret = [] | |
ret.append(l) | |
for i in range(y_size): | |
ret.append(rotate(l, (n * (i + 1)) % len(l))) | |
return ret | |
def rotate(l, n): | |
return l[n:] + l[:n] | |
def print_out(l, frmt='{} '): | |
''' Prints out a pattern, the opional frmt argument | |
is used to format the elements of the pattern''' | |
for elem in l: | |
elem_str = '' | |
for ch in elem: | |
elem_str += frmt.format(ch) | |
print(elem_str) | |
pattern = generate(20, 20) | |
print_out(pattern, frmt='{:02} ') | |
shuffle(pattern) | |
print_out(pattern) | |
for i in range(len(pattern)): | |
shuffle(pattern[i]) | |
print_out(pattern) | |
pat = [' ', 'X', ' ', 'X', ' ', 'X', ' ', 'X'] | |
pattern = generate_from_list(pat, 8, n=2) | |
print_out(pattern) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment