Skip to content

Instantly share code, notes, and snippets.

@sridharavinash
Last active June 13, 2019 18:45
Show Gist options
  • Save sridharavinash/929fe2e98d7bd013b5b69d672ea52be0 to your computer and use it in GitHub Desktop.
Save sridharavinash/929fe2e98d7bd013b5b69d672ea52be0 to your computer and use it in GitHub Desktop.
An experiment on using the hexbot from noopschallenge, https://noopschallenge.com/challenges/hexbot
#!/bin/bash
#
# usage: ./hexbot.sh 10 rainbow
# will print the string `rainbow` on the commandline in the colors
# that the hexbot responds with.
#
# Not specifying a string will print the nyancat
# fromhex A52A2A
# fromhex "#A52A2A"
# BLUE_VIOLET=$(fromhex "#8A2BE2")
# http://unix.stackexchange.com/a/269085/67282
function fromhex() {
hex=$1
if [[ $hex == "#"* ]]; then
hex=$(echo $1 | awk '{print substr($0,4)}')
fi
r=$(printf '0x%0.2s' "$hex")
g=$(printf '0x%0.2s' ${hex#??})
b=$(printf '0x%0.2s' ${hex#????})
echo -e `printf "%03d" "$(((r<75?0:(r-35)/40)*6*6+(g<75?0:(g-35)/40)*6+(b<75?0:(b-35)/40)+16))"`
}
nyan=':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::############## :::::::::::::::::::
############################ ############################## :::::::::::::::::
######################### ######???????????????????????###### :::::::::::::::
========================= ####??????????()????()?????????#### :::::::::::::::
========================= ##????()?????????????? ()?????## :::: :::::::
------------============= ##?????????????????? ;;;; ?????## :: ;;;; :::::
------------------------- ##??????????()?????? ;;;;;;?????## ;;;;;; :::::
------------------------- ##?????????????????? ;;;;;; ;;;;;;;; :::::
++++++++++++------------- ##?????????????????? ;;;;;;;;;;;;;;;;;;;;;;; :::::
+++++++++++++++++++++++++ ##????????????()?? ;;;;;;;;;;;;;;;;;;;;;;;;;;; :::
+++++++++++++++++ ;;;; ##??()???????????? ;;;;;;@@ ;;;;;;;;@@ ;;;;; :::
~~~~~~~~~~~~~++++;;;;;;;; ##???????????????? ;;;;;; ;;; ;;; ;;;;; :::
~~~~~~~~~~~~~~~ ;; ~~~~ ####??????()?????? ;;[];;;;;;;;;;;;;;;;;;;;;[] :::
$$$$$$$$$$$$$~~~~ ~~~~~~ ######????????????? ;;;;;; ;;;; :::::
$$$$$$$$$$$$$$$$$$$$$$$$$ ################### ;;;;;;;;;;;;;;;;;;;; :::::::
$$$$$$$$$$$$$$$$$$$$$$$ ;;;; :::::::::::
:::::::::::::$$$$$$$$$$ ;;;; :: ;; :::::::::::: ;; :: ;;;; ::::::::::::
::::::::::::::::::::::: :::::: ::::::::::::: :::: ::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::NN::::NN::YY::::YY:::AAAAAA:::NN::::NN:::!!::::::::::::::::::::
::::::::::::::::NNNN::NN::YY::::YY::AA::::AA::NNNN::NN:::!!::::::::::::::::::::
::::::::::::::::NNNN::NN::YY::::YY::AA::::AA::NNNN::NN:::!!::::::::::::::::::::
::::::::::::::::NN::NNNN::::YYYY::::AAAAAAAA::NN::NNNN:::!!::::::::::::::::::::
::::::::::::::::NN::NNNN:::::YY:::::AA::::AA::NN::NNNN:::::::::::::::::::::::::
::::::::::::::::NN::::NN:::::YY:::::AA::::AA::NN::::NN:::!!::::::::::::::::::::'
render=${2:-$nyan}
colors=$(curl -s https://api.noopschallenge.com/hexbot\?count\=$1 | jq -r .colors[].value)
for color in $colors; do
clr=$(fromhex $color)
tput setaf $clr
tput sc
echo "$render"
tput sgr0
tput rc
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment