Skip to content

Instantly share code, notes, and snippets.

@stefanv
Created November 17, 2011 00:25
Show Gist options
  • Select an option

  • Save stefanv/1371985 to your computer and use it in GitHub Desktop.

Select an option

Save stefanv/1371985 to your computer and use it in GitHub Desktop.

Revisions

  1. stefanv revised this gist Nov 17, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion sparks.py
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    #!/usr/bin/python
    # coding=utf-8

    # Python version of Zach Holman's "spark:
    # Python version of Zach Holman's "spark"
    # https://github.com/holman/spark
    # by Stefan van der Walt <[email protected]>

  2. stefanv created this gist Nov 17, 2011.
    37 changes: 37 additions & 0 deletions sparks.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    #!/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('▁▂▃▄▅▆▇█', 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()