From 1dc0f629cf831cc6034900aacc9843bd9934052e Mon Sep 17 00:00:00 2001 From: manetta Date: Mon, 25 Mar 2019 23:46:03 +0100 Subject: [PATCH] small pattern test with J --- pattern.py | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 pattern.py diff --git a/pattern.py b/pattern.py new file mode 100644 index 0000000..c511cc3 --- /dev/null +++ b/pattern.py @@ -0,0 +1,77 @@ +from math import sqrt, log, log10 + +# Using a function to describe a circle +# Thanks J + +def circulair_pattern(): + line_width = 110 + line_height = 70 + + out = '' + count = 0 + + for x in range(100): + for y in range(100): + if count == 10: + count = 0 + z = sqrt((x ** 2) + (y ** 2)) + z = int(z / 50) + print(z) + out += str(count) + (' ' * z) + count += 1 + + page = '' + linenumber = 0 + for i, c in enumerate(out): + if i % line_width == 0: + range_start = linenumber * line_width + range_end = range_start + line_width + page += out[range_start:range_end] + '\n' + linenumber += 1 + + lines = page.split('\n') + page = '\n'.join(lines[:69]) + '\n' + + f = open('pattern.txt', 'w+') + f.write(page) + f.close() + return page + +circulair_pattern() + + +def new(): + line_width = 110 + line_height = 70 + + out = '' + count = 0 + + for x in range(100): + if count == 10: + count = 0 + z = int(log10(4 * (x + 1))) + print(z) + out += str(count) + (' ' * z) + count += 1 + + out = out.replace(' ', ' ') + + page = '' + linenumber = 0 + for i, c in enumerate(out): + if i % line_width == 0: + range_start = linenumber * line_width + range_end = range_start + line_width + page += out[range_start:range_end] + '\n' + linenumber += 1 + + lines = page.split('\n') + page = '\n'.join(lines[:69]) + '\n' + + f = open('pattern.txt', 'w+') + f.write(page) + f.close() + return page + +# new() \ No newline at end of file