From 183ca247326cd19c9e3b1aee743b5a19d82502d6 Mon Sep 17 00:00:00 2001 From: Daniel Ruiz de Alegría Date: Fri, 1 Mar 2019 17:26:32 +0100 Subject: Update Flat-Remix palette --- tools/colorFixer.sh | 151 --- tools/colorfixer.sh | 151 +++ tools/flat-remix-palette.svg | 2815 +----------------------------------------- tools/paletteColors | 126 +- 4 files changed, 259 insertions(+), 2984 deletions(-) delete mode 100755 tools/colorFixer.sh create mode 100755 tools/colorfixer.sh diff --git a/tools/colorFixer.sh b/tools/colorFixer.sh deleted file mode 100755 index 79bb35a10..000000000 --- a/tools/colorFixer.sh +++ /dev/null @@ -1,151 +0,0 @@ -#!/bin/bash - -USAGE="$(basename "$0") [OPTION]... [FILE] - Replace all colors found in input file with the closest from - specified palette. Supports HEX RGB and RGBA colors. - - Options: - -p FILE, --palette FILE \t read palette colors from FILE - -x, --hex \t use hex colors as replacement - -v, --verbose \t print color modifications - -c, --color \t colorize the output - -h, --help \t show this help text" - - - -FILES=() -PALETTE_FILE='' -while [[ $# -gt 0 ]] -do - key="$1" - - case $key in - -p|--palette) - PALETTE_FILE="$2" - shift # past argument - shift # past value - ;; - -x|--hex) - HEX=1 - shift # past argument - ;; - -v|--verbose) - VERBOSE=1 - shift # past argument - ;; - -c|--color) - COLOR=1 - shift # past argument - ;; - -h|--help) - echo -e "$USAGE" - exit 0 - ;; - *) # files - FILES+=("$1") - shift # past argument - ;; - esac -done - -if [[ ${FILES[@]} == '' || $PALETTE_FILE == '' ]] -then - echo -e "$USAGE" - exit 0 -fi - - - -function parse_color { - color="$1" - if [[ ${color:0:1} = "#" ]] - then - if [[ $(wc -c <<< $color) = 5 ]] - then - color="#${color:1:1}${color:1:1}${color:2:1}${color:2:1}${color:3:1}${color:3:1}" - fi - echo "$((0x${color:1:2})) $((0x${color:3:2})) $((0x${color:5:2}))" - elif [[ ${color:0:3} = "rgb" ]] - then - colors=($(grep -o -P "\d+(\.\d+)?" <<< $color)) - if [[ $(grep -o "%" <<< $color | wc -l) > 0 ]] - then - printf "%s %s %s" \ - $(echo "${colors[0]} * 255/100" | bc) \ - $(echo "${colors[1]} * 255/100" | bc) \ - $(echo "${colors[2]} * 255/100" | bc) - else - echo "${colors[0]} ${colors[1]} ${colors[2]}" - fi - fi -} - -palette_colors=$(for color in $(cat "$PALETTE_FILE") -do - echo $(parse_color $color) -done) - -function find_nearest_color { - r1=$1; g1=$2; b1=$3 - color1=($r $g $b) - smallest_distance=765 - - while read -r palette_color - do - color2=($palette_color) - r2=${color2[0]}; g2=${color2[1]}; b2=${color2[2]} - - if [[ ${color1[@]} == ${color2[@]} ]] - then - best_color=$palette_color - break - fi - - distance=$(echo "scale=3;sqrt(2*($r2-$r1)^2 + 4*($g2-$g1)^2 + 3*($b2-$b1)^2)" | bc) - if (( $(echo "$distance < $smallest_distance" | bc) )) - then - smallest_distance=$distance - best_color=$palette_color - fi - done <<< $palette_colors - echo $best_color -} - -colors_regex='#([\da-f]{3}){1,2}(?![\d\w])|rgb(a)?\(\s*\d{1,3}(\.\d+)?%?(\s*,\s*\d{1,3}(\.\d+)?%?){2}(\s*,\s*(1|\d?\.\d+))?\s*\)' -for file in ${FILES[@]} -do - printf "\n $file\n" - (( $VERBOSE )) && printf '%*s\n\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' '_' - - file_colors=$(grep -o -P -i $colors_regex "$file" | sort -u) - [[ $file_colors = '' ]] && continue - while read -r file_color - do - parsed_color=($(parse_color "$file_color")) - new_color=($(find_nearest_color ${parsed_color[@]})) - if [[ ${file_color:0:4} == 'rgba' ]] - then - alpha=$(grep -o -P "\d*(\.\d+)?" <<< $file_color | tail -1) - new_color_formated="rgba(${new_color[0]}, ${new_color[1]}, ${new_color[2]}, $alpha)" - elif (( HEX )) - then - new_color_formated=$(printf '#%02x%02x%02x' \ - ${new_color[0]} ${new_color[1]} ${new_color[2]}) - else - new_color_formated="rgb(${new_color[0]}, ${new_color[1]}, ${new_color[2]})" - fi - - sed "s/$file_color/$new_color_formated/g" -i "$file" - - if (( $VERBOSE )) - then - printf " %s%-24s %s => %s %24s%s\n" \ - $((( $COLOR )) && printf "\x1b[38;2;${parsed_color[0]};${parsed_color[1]};${parsed_color[2]}m" || printf '') \ - "$file_color" \ - $((( $COLOR )) && printf "\x1b[48;2;${parsed_color[0]};${parsed_color[1]};${parsed_color[2]}m..\x1b[0m" || printf '') \ - $((( $COLOR )) && printf "\x1b[38;2;${new_color[0]};${new_color[1]};${new_color[2]}m\x1b[48;2;${new_color[0]};${new_color[1]};${new_color[2]}m..\x1b[0m\x1b[38;2;${new_color[0]};${new_color[1]};${new_color[2]}m" || printf '') \ - "$new_color_formated" \ - $((( $COLOR )) && printf "\x1b[0m" || printf '') - fi - done <<< $file_colors -done diff --git a/tools/colorfixer.sh b/tools/colorfixer.sh new file mode 100755 index 000000000..79bb35a10 --- /dev/null +++ b/tools/colorfixer.sh @@ -0,0 +1,151 @@ +#!/bin/bash + +USAGE="$(basename "$0") [OPTION]... [FILE] + Replace all colors found in input file with the closest from + specified palette. Supports HEX RGB and RGBA colors. + + Options: + -p FILE, --palette FILE \t read palette colors from FILE + -x, --hex \t use hex colors as replacement + -v, --verbose \t print color modifications + -c, --color \t colorize the output + -h, --help \t show this help text" + + + +FILES=() +PALETTE_FILE='' +while [[ $# -gt 0 ]] +do + key="$1" + + case $key in + -p|--palette) + PALETTE_FILE="$2" + shift # past argument + shift # past value + ;; + -x|--hex) + HEX=1 + shift # past argument + ;; + -v|--verbose) + VERBOSE=1 + shift # past argument + ;; + -c|--color) + COLOR=1 + shift # past argument + ;; + -h|--help) + echo -e "$USAGE" + exit 0 + ;; + *) # files + FILES+=("$1") + shift # past argument + ;; + esac +done + +if [[ ${FILES[@]} == '' || $PALETTE_FILE == '' ]] +then + echo -e "$USAGE" + exit 0 +fi + + + +function parse_color { + color="$1" + if [[ ${color:0:1} = "#" ]] + then + if [[ $(wc -c <<< $color) = 5 ]] + then + color="#${color:1:1}${color:1:1}${color:2:1}${color:2:1}${color:3:1}${color:3:1}" + fi + echo "$((0x${color:1:2})) $((0x${color:3:2})) $((0x${color:5:2}))" + elif [[ ${color:0:3} = "rgb" ]] + then + colors=($(grep -o -P "\d+(\.\d+)?" <<< $color)) + if [[ $(grep -o "%" <<< $color | wc -l) > 0 ]] + then + printf "%s %s %s" \ + $(echo "${colors[0]} * 255/100" | bc) \ + $(echo "${colors[1]} * 255/100" | bc) \ + $(echo "${colors[2]} * 255/100" | bc) + else + echo "${colors[0]} ${colors[1]} ${colors[2]}" + fi + fi +} + +palette_colors=$(for color in $(cat "$PALETTE_FILE") +do + echo $(parse_color $color) +done) + +function find_nearest_color { + r1=$1; g1=$2; b1=$3 + color1=($r $g $b) + smallest_distance=765 + + while read -r palette_color + do + color2=($palette_color) + r2=${color2[0]}; g2=${color2[1]}; b2=${color2[2]} + + if [[ ${color1[@]} == ${color2[@]} ]] + then + best_color=$palette_color + break + fi + + distance=$(echo "scale=3;sqrt(2*($r2-$r1)^2 + 4*($g2-$g1)^2 + 3*($b2-$b1)^2)" | bc) + if (( $(echo "$distance < $smallest_distance" | bc) )) + then + smallest_distance=$distance + best_color=$palette_color + fi + done <<< $palette_colors + echo $best_color +} + +colors_regex='#([\da-f]{3}){1,2}(?![\d\w])|rgb(a)?\(\s*\d{1,3}(\.\d+)?%?(\s*,\s*\d{1,3}(\.\d+)?%?){2}(\s*,\s*(1|\d?\.\d+))?\s*\)' +for file in ${FILES[@]} +do + printf "\n $file\n" + (( $VERBOSE )) && printf '%*s\n\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' '_' + + file_colors=$(grep -o -P -i $colors_regex "$file" | sort -u) + [[ $file_colors = '' ]] && continue + while read -r file_color + do + parsed_color=($(parse_color "$file_color")) + new_color=($(find_nearest_color ${parsed_color[@]})) + if [[ ${file_color:0:4} == 'rgba' ]] + then + alpha=$(grep -o -P "\d*(\.\d+)?" <<< $file_color | tail -1) + new_color_formated="rgba(${new_color[0]}, ${new_color[1]}, ${new_color[2]}, $alpha)" + elif (( HEX )) + then + new_color_formated=$(printf '#%02x%02x%02x' \ + ${new_color[0]} ${new_color[1]} ${new_color[2]}) + else + new_color_formated="rgb(${new_color[0]}, ${new_color[1]}, ${new_color[2]})" + fi + + sed "s/$file_color/$new_color_formated/g" -i "$file" + + if (( $VERBOSE )) + then + printf " %s%-24s %s => %s %24s%s\n" \ + $((( $COLOR )) && printf "\x1b[38;2;${parsed_color[0]};${parsed_color[1]};${parsed_color[2]}m" || printf '') \ + "$file_color" \ + $((( $COLOR )) && printf "\x1b[48;2;${parsed_color[0]};${parsed_color[1]};${parsed_color[2]}m..\x1b[0m" || printf '') \ + $((( $COLOR )) && printf "\x1b[38;2;${new_color[0]};${new_color[1]};${new_color[2]}m\x1b[48;2;${new_color[0]};${new_color[1]};${new_color[2]}m..\x1b[0m\x1b[38;2;${new_color[0]};${new_color[1]};${new_color[2]}m" || printf '') \ + "$new_color_formated" \ + $((( $COLOR )) && printf "\x1b[0m" || printf '') + fi + done <<< $file_colors +done diff --git a/tools/flat-remix-palette.svg b/tools/flat-remix-palette.svg index bcd11eb85..c8959254f 100644 --- a/tools/flat-remix-palette.svg +++ b/tools/flat-remix-palette.svg @@ -1,2814 +1 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/tools/paletteColors b/tools/paletteColors index 23a19c632..67ad7dda9 100644 --- a/tools/paletteColors +++ b/tools/paletteColors @@ -1,19 +1,107 @@ -#0f2751 #112d5c #133368 #153873 #2c4c81 #44608f #5b739d -#1b3f7c #1e488e #2251a0 #265ab1 #3b6ab9 #517bc1 #678bc8 -#2656a8 #2b62c0 #316fd8 #367bf0 #4a88f1 #5e95f3 #72a2f4 -#347aa1 #3b8bb8 #439dcf #4aaee6 #5cb6e8 #6ebeeb #80c6ed -#198388 #1c959b #20a8af #23bac2 #39c1c8 #4fc8ce #65cfd4 -#12715f #14816c #17917a #19a187 #30aa93 #47b49f #5ebdab -#087142 #0a814b #0b9155 #0ca15e #24aa6e #3db47e #54bd8e -#493525 #533d2a #5e4530 #684c35 #775e49 #86705d #958171 -#714b2b #815631 #916137 #a16b3d #aa7a50 #b48964 #bd9777 -#622e78 #703589 #7e3c9a #8c42ab #9755b3 #a368bc #ae7ac4 -#811035 #93123d #a61545 #b8174c #bf2e5e #c64570 #cd5c81 -#951212 #aa1414 #bf1717 #d41919 #d83030 #dd4747 #e15e5e -#b22525 #ca2a2a #e43030 #fd3535 #fd4949 #fd5d5d #fe7171 -#b25800 #ca6400 #e47100 #fd7d00 #fd8a19 #fd9733 #fea44c -#ffc730 #ffcc44 #ffd259 #ffd86e -#f8de68 #f9e177 #f9e586 #fae895 -#272a34 #2d303b #333643 #383c4a #4c4f5c #60636e #737680 -#000000 #191919 #333333 #4c4c4c -#b3b3b3 #cccccc #e6e6e6 #ffffff +#040506 +#09834c +#0a1082 +#0a3282 +#0ca15e +#0ca862 +#0d14a7 +#0d40a7 +#0f18cd +#0f4ecd +#0fcd78 +#11527b +#137966 +#141414 +#16171c +#1620ee +#165dee +#16699e +#166c76 +#16ee8b +#189c85 +#19a187 +#1a81c2 +#1c8b98 +#1ebea2 +#21abbb +#2397e1 +#23bac2 +#272a33 +#27ddbd +#282828 +#2bc7d9 +#367bf0 +#383c4a +#3c3c3c +#3c44f0 +#3c77f0 +#3cf09f +#46a8e6 +#494e61 +#49e3c8 +#4aaee6 +#4dd0df +#505050 +#522765 +#5a6178 +#6168f3 +#6191f3 +#61f3b1 +#646464 +#664426 +#6a3282 +#6ab8ea +#6c738e +#6ce8d2 +#6fd9e5 +#787878 +#7c1033 +#823d9f +#835731 +#86abf6 +#86f6c3 +#8a0202 +#8c42ab +#8c8c8c +#8dc9ef +#8eeedd +#91e1eb +#9397e9 +#994bb9 +#a01442 +#a06a3c +#a0a0a0 +#a16b3d +#a967c5 +#b20202 +#b4b4b4 +#b8174c +#b984d0 +#ba7d4a +#c59267 +#c6164d +#c8c8c8 +#caa1db +#d0a784 +#da0202 +#dbbca1 +#dcdcdc +#e4205f +#e7457a +#ee6691 +#f08cad +#f0f0f0 +#fd0707 +#fd2f2f +#fd3535 +#fd5757 +#fe7e7e +#ff8c05 +#ff9f2d +#ffb155 +#ffc37d +#ffd305 +#ffda2d +#ffe155 +#ffe87d +#fff -- cgit v1.2.3