Skip to content

Instantly share code, notes, and snippets.

@NeoTheFox
Last active February 14, 2018 16:56

Revisions

  1. NeoTheFox revised this gist Feb 13, 2018. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion glasscalc.sh
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,6 @@ function printhelp
    echo "Example:"
    echo " glasscalc.sh 800x600"
    }
    power2() { echo "x=l($1)/l(2); scale=0; 2^((x+0.5)/1)" | bc -l; }

    if [ -z $1 ]
    then
  2. NeoTheFox revised this gist Feb 13, 2018. 1 changed file with 11 additions and 22 deletions.
    33 changes: 11 additions & 22 deletions glasscalc.sh
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,6 @@
    #This is a simple calc for looking glass
    #Licenced by WTFPL
    #by NeoTheFox 2018
    #Some functions are from http://www.pixelbeat.org/

    #USAGE:
    #glasscalc.sh WidthxHeight
    @@ -27,24 +26,14 @@ fi
    WIDTH=$(echo $1 | cut -d "x" -f1)
    HEIGHT=$(echo $1 | cut -d "x" -f2)

    echo "
    define int(x) {
    auto old_scale /* variables global by default */
    old_scale=scale /* scale is global */
    scale=0; ret=x/1
    scale=old_scale
    return ret
    }
    define ceil(x) {
    auto intx
    intx=int(x)
    if (intx<x) intx+=1
    return intx
    }
    m=$WIDTH*$HEIGHT*4*2
    m=m/1024/1024
    m=2^ceil(l(m)/l(2))
    m" | bc -l
    ((M=$WIDTH*HEIGHT*4*2))
    ((M=M/1024/1024))
    ((M+=1))
    ((M|=M>>1))
    ((M|=M>>2))
    ((M|=M>>4))
    ((M|=M>>8))
    ((M|=M>>16))
    ((M+=1))

    echo "$M"
  3. NeoTheFox created this gist Feb 13, 2018.
    50 changes: 50 additions & 0 deletions glasscalc.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    #!/bin/bash

    #This is a simple calc for looking glass
    #Licenced by WTFPL
    #by NeoTheFox 2018
    #Some functions are from http://www.pixelbeat.org/

    #USAGE:
    #glasscalc.sh WidthxHeight

    function printhelp
    {
    echo "Usage:"
    echo " glasscalc.sh widthxheight"
    echo "Example:"
    echo " glasscalc.sh 800x600"
    }
    power2() { echo "x=l($1)/l(2); scale=0; 2^((x+0.5)/1)" | bc -l; }

    if [ -z $1 ]
    then
    echo "No arguments provided"
    printhelp
    exit 0
    fi

    WIDTH=$(echo $1 | cut -d "x" -f1)
    HEIGHT=$(echo $1 | cut -d "x" -f2)

    echo "
    define int(x) {
    auto old_scale /* variables global by default */
    old_scale=scale /* scale is global */
    scale=0; ret=x/1
    scale=old_scale
    return ret
    }
    define ceil(x) {
    auto intx
    intx=int(x)
    if (intx<x) intx+=1
    return intx
    }
    m=$WIDTH*$HEIGHT*4*2
    m=m/1024/1024
    m=2^ceil(l(m)/l(2))
    m" | bc -l