From b526c284e102e0788ccbfb16dcc0b7343bb5e8ad Mon Sep 17 00:00:00 2001 From: Amin Date: Mon, 27 Sep 2021 12:15:21 +0000 Subject: [PATCH 1/3] fix terminal autodatect Serpinsky triangle move animation use autodetected width/height of terminal; https://codengineering.ru/q/how-to-get-linux-console-window-width-in-python-23258 --- moving_Sierpinski_triangle.py | 36 +++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/moving_Sierpinski_triangle.py b/moving_Sierpinski_triangle.py index c084fcd..06a3cb2 100644 --- a/moving_Sierpinski_triangle.py +++ b/moving_Sierpinski_triangle.py @@ -1,7 +1,27 @@ +#!/usr/bin/python3 + +filling_char = 'A'; # Symbol for draw Serpinskiy triangle +fps_forward = 30; # frame-per-second / animation speed +fps_backward = 30; # frame-per-second / animation speed + import time +import os + +# detect terminal sizes +try: + # Since python 3.3 this method accessible + ts = os.get_terminal_size() # get terminal size (in char-places) + height = ts.lines - 1 # height of serp-3angle = ht-1 + width = int(ts.columns / 3) # width of movement base = 1/3 of tw + # 1/3 is safe value; true mathematics can try calculate more beautiful +except: + width = 26; # ~ 80/3 + height = 24; # std DOS/CMD h/w values - safe mode or old python + +# create Serpinsky triangle a = [[1]] -for i in range(73): +for i in range(height): b = [1] for j in range(len(a[-1]) - 1): b.append(a[-1][j] + a[-1][j + 1]) @@ -12,17 +32,21 @@ if a[i][j] % 2 == 0: a[i][j] = ' ' else: - a[i][j] = 'A' + a[i][j] = filling_char d = ' '.join(a[i]) + + +# draw triangle with loop animation while 1: - for j in range(165): - time.sleep(.02) + for j in range(width): # forward (left-to-right move) + time.sleep(1/fps_forward) for i in range(len(a)): f = ' '.join(a[i]) e = (len(d) - len(f)) // 2 print(j * ' ' + e * ' ' + f + e * ' ') - for j in range(165, 0, -1): - time.sleep(.02) + + for j in range(width, 0, -1): # backward (right-to-left move) + time.sleep(1/fps_backward) for i in range(len(a)): f = ' '.join(a[i]) e = (len(d) - len(f)) // 2 From 71ee453e77e05f293bf6cdf4a8a8e07e6ba73a44 Mon Sep 17 00:00:00 2001 From: Amin Date: Sun, 21 Aug 2022 13:53:08 +0000 Subject: [PATCH 2/3] Create README.md --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..22070a8 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# Math-scripts +Python examples for beginners + +Scripts for solve / investigate mathemacal exercises +by python3 scripts. + +Inspired by Dima |Matan| Mikhailov + +https://www.youtube.com/channel/UCocsNgfW9tGLP8zktA6CtRg From 4c173889cadfcb217f18b84fa68961211df29151 Mon Sep 17 00:00:00 2001 From: Amin Date: Sun, 21 Aug 2022 13:53:31 +0000 Subject: [PATCH 3/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 22070a8..b4c3c93 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Math-scripts Python examples for beginners -Scripts for solve / investigate mathemacal exercises +Scripts for solve / investigate mathematical exercises by python3 scripts. Inspired by Dima |Matan| Mikhailov