Skip to content

Instantly share code, notes, and snippets.

@curzona
Last active August 29, 2015 14:21
Show Gist options
  • Select an option

  • Save curzona/98ce0c1bb75694ddf18f to your computer and use it in GitHub Desktop.

Select an option

Save curzona/98ce0c1bb75694ddf18f to your computer and use it in GitHub Desktop.
Render waveform as ascii text
# coding=utf-8
def render(data, label=''):
line1 = []
line2 = []
for i, pt in enumerate(data):
if i<len(data)-1:
if pt == data[i+1]:
line1.append((" ", "─")[pt])
line2.append(("─", " ")[pt])
else:
line1.append(("┌", "┐")[pt])
line2.append(("┘", "└")[pt])
else:
line1.append((" ", "─")[pt])
line2.append(("─", " ")[pt])
print label, ''.join(line1)
print ' '*len(label),''.join(line2)
render([1,1,1,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0], 'sda')
render([1,1,1,1,0,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1], 'scl')
python ascii_waveform.py
sda ──┐ ┌───────┐
└──┘ └───────────
scl ───┐ ┌─┐ ┌─┐ ┌─┐ ┌─┐ ┌──
└──┘ └─┘ └─┘ └─┘ └─┘
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment