Last active
August 29, 2015 14:21
-
-
Save curzona/98ce0c1bb75694ddf18f to your computer and use it in GitHub Desktop.
Render waveform as ascii text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| python ascii_waveform.py | |
| sda ──┐ ┌───────┐ | |
| └──┘ └─────────── | |
| scl ───┐ ┌─┐ ┌─┐ ┌─┐ ┌─┐ ┌── | |
| └──┘ └─┘ └─┘ └─┘ └─┘ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
