Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Math-scripts
Python examples for beginners

Scripts for solve / investigate mathematical exercises
by python3 scripts.

Inspired by Dima |Matan| Mikhailov

https://www.youtube.com/channel/UCocsNgfW9tGLP8zktA6CtRg
36 changes: 30 additions & 6 deletions moving_Sierpinski_triangle.py
Original file line number Diff line number Diff line change
@@ -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])
Expand All @@ -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
Expand Down