Skip to content

Instantly share code, notes, and snippets.

@amarion35
Forked from amarioncosmo/wave.py
Created October 11, 2018 17:32
Show Gist options
  • Save amarion35/02877b7a28464a0f977174a6511f844e to your computer and use it in GitHub Desktop.
Save amarion35/02877b7a28464a0f977174a6511f844e to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
import numpy as np
import sys
import time
import math
import os
def plot(array, width, height):
size = len(array)
y = [array[int(round(k*size/width)):int(round((k+1)*size/width))] for k in range(width)]
y = [np.mean(k) for k in y]
y = height*(y-np.min(y))/(np.max(y)-np.min(y))
res = np.array(list([list('#'*int(round(y[k]))+' '*int(round(height-y[k]))) for k in range(len(y))]))
res = np.rot90(res, k=1, axes=(0,1))
for r in res:
print('\033[94m' + ''.join(r)+'\033[0m')
def f(x):
return [math.sin(x+k/200) for k in range(-500,500)]
def wave(n=100):
for k in range(n):
print(chr(27))
print('\033c')
print('\x1bc')
rows, columns = os.popen('stty size', 'r').read().split()
plot(f(k), int(columns)+3, int(rows)-1)
time.sleep(0.1)
sys.stdout.flush()
if __name__=='__main__':
wave()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment