Skip to content

Instantly share code, notes, and snippets.

@remram44
Forked from stefanv/sparks.py
Last active December 18, 2015 14:49
Show Gist options
  • Save remram44/5799618 to your computer and use it in GitHub Desktop.
Save remram44/5799618 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# coding=utf-8
# Python version of Zach Holman's "spark"
# https://github.com/holman/spark
# by Stefan van der Walt <[email protected]>
"""
USAGE:
sparks.py [comma,separated,value,list] or [vals separated by spaces]
EXAMPLES:
spark 1,5,22,13,53
▁▁▃▂▇
spark 0 30 55 80 33 150
▁▂▃▅▂▇
spark 0.1 0.2 0.9 -0.5
▄▅█▁
"""
import sys
import numpy as np
if len(sys.argv) < 2:
print __doc__
sys.exit(-1)
sparks = np.fromstring(
'\xE2\x96\x81'
'\xE2\x96\x82'
'\xE2\x96\x83'
'\xE2\x96\x84'
'\xE2\x96\x85'
'\xE2\x96\x86'
'\xE2\x96\x87'
'\xE2\x96\x88',
dtype='S3')
values = np.array([float(v) for v in ' '.join(sys.argv[1:]).replace(',', ' ').split()])
if np.unique(values).size != 1:
values -= values.min()
m = values.max() or 1
values /= m
print sparks[np.round(values * (sparks.size - 1)).astype(int)].tostring()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment