diff --git a/change_color.sh b/change_color.sh new file mode 100755 index 0000000..81d12e9 --- /dev/null +++ b/change_color.sh @@ -0,0 +1,297 @@ +#!/usr/bin/env bash +# shellcheck disable=SC1090 +#set -x +set -ueo pipefail + +SRC_PATH="$(readlink -f "$(dirname "$0")")" + +darker() { + "$SRC_PATH/scripts/darker.sh" "$@" +} +mix() { + "$SRC_PATH/scripts/mix.sh" "$@" +} +is_dark() { + hexinput="$(tr '[:lower:]' '[:upper:]' <<< "$1")" + half_darker="$(darker "$hexinput" 88)" + [[ "$half_darker" == "000000" ]] +} + + +print_usage() { + echo "usage: $0 [-o OUTPUT_THEME_NAME] [-a AUTOGEN_OPTS] PATH_TO_PRESET" + echo + echo "examples:" + # shellcheck disable=SC2028 # This is meant to be usage text. + echo " $0 --output my-theme-name <(echo -e \"BG=d8d8d8\\nFG=101010\\nMENU_BG=3c3c3c\\nMENU_FG=e6e6e6\\nSEL_BG=ad7fa8\\nSEL_FG=ffffff\\nTXT_BG=ffffff\\nTXT_FG=1a1a1a\\nBTN_BG=f5f5f5\\nBTN_FG=111111\\n\")" + echo " $0 ../colors/retro/twg" + echo " $0 --autogen-opts '--disable-cinnamon --disable-gnome-shell' ../colors/retro/clearlooks" + exit 1 +} + +AUTOGEN_OPTS="" + +while [[ "$#" -gt 0 ]]; do + case "$1" in + -o|--output) + OUTPUT_THEME_NAME="$2" + shift + ;; + -d|--hidpi) + OPTION_GTK2_HIDPI="$2" + shift + ;; + -a|--autogen-opts) + AUTOGEN_OPTS="${2}" + shift + ;; + *) + if [[ "$1" == -* ]] || [[ "${THEME-}" ]]; then + echo "unknown option $1" + print_usage + exit 2 + fi + THEME="$1" + ;; + esac + shift +done + +if [[ -z "${THEME:-}" ]]; then + print_usage +fi + +OPTION_GTK2_HIDPI=$(tr '[:upper:]' '[:lower:]' <<< "${OPTION_GTK2_HIDPI-False}") +export OPTION_GTK2_HIDPI + + +if [[ "$THEME" == */* ]] || [[ "$THEME" == *.* ]]; then + source "$THEME" + THEME=$(basename "$THEME") +else + if [[ -f "$SRC_PATH/../colors/$THEME" ]]; then + source "$SRC_PATH/../colors/$THEME" + else + echo "Theme '$THEME' not found" + exit 1 + fi +fi +if [[ $(date +"%m%d") = "0401" ]] && grep -q "no-jokes" <<< "$*"; then + echo -e "\\n\\nError patching uxtheme.dll\\n\\n" + ACCENT_BG=000000 BG=C0C0C0 BTN_BG=C0C0C0 BTN_FG=000000 FG=000000 + HDR_BTN_BG=C0C0C0 HDR_BTN_FG=000000 MENU_BG=C0C0C0 + MENU_FG=000000 SEL_BG=000080 SEL_FG=FFFFFF TXT_BG=FFFFFF TXT_FG=000000 +fi + +ARC_TRANSPARENCY=$(tr '[:upper:]' '[:lower:]' <<< "${ARC_TRANSPARENCY-True}") +ARC_WIDGET_BORDER_COLOR=${ARC_WIDGET_BORDER_COLOR-$(mix ${BG} ${FG} 0.75)} + +ACCENT_BG=${ACCENT_BG-$SEL_BG} +HDR_BTN_BG=${HDR_BTN_BG-$BTN_BG} +# Not implemented yet: +HDR_BTN_FG=${HDR_BTN_FG-$BTN_FG} +WM_BORDER_FOCUS=${WM_BORDER_FOCUS-$SEL_BG} +WM_BORDER_UNFOCUS=${WM_BORDER_UNFOCUS-$MENU_BG} +SPACING=${SPACING-3} +GRADIENT=${GRADIENT-0} +ROUNDNESS=${ROUNDNESS-2} +ROUNDNESS_GTK2_HIDPI=$(( ROUNDNESS * 2 )) + +TERMINAL_COLOR1=${TERMINAL_COLOR1:-F04A50} +TERMINAL_COLOR3=${TERMINAL_COLOR3:-F08437} +TERMINAL_COLOR4=${TERMINAL_COLOR4:-1E88E5} +TERMINAL_COLOR5=${TERMINAL_COLOR5:-E040FB} +TERMINAL_COLOR9=${TERMINAL_COLOR9:-DD2C00} +TERMINAL_COLOR10=${TERMINAL_COLOR10:-00C853} +TERMINAL_COLOR11=${TERMINAL_COLOR11:-FF6D00} +TERMINAL_COLOR12=${TERMINAL_COLOR12:-66BB6A} + +INACTIVE_FG=$(mix "$FG" "$BG" 0.75) +INACTIVE_BG=$(mix "$BG" "$FG" 0.75) +INACTIVE_MENU_FG=$(mix "$MENU_FG" "$MENU_BG" 0.75) +INACTIVE_MENU_BG=$(mix "$MENU_BG" "$MENU_FG" 0.75) +INACTIVE_TXT_FG=$(mix "$TXT_FG" "$TXT_BG" 0.75) +INACTIVE_TXT_BG=$(mix "$TXT_BG" "$BG" 0.75) + +OUTPUT_THEME_NAME=${OUTPUT_THEME_NAME-oomox-arc-$THEME} +DEST_PATH="$HOME/.themes/${OUTPUT_THEME_NAME/\//-}" + +if [[ "$SRC_PATH" == "$DEST_PATH" ]]; then + echo "can't do that" + exit 1 +fi + + +tempdir=$(mktemp -d) +post_clean_up() { + rm -r "$tempdir" +} +trap post_clean_up EXIT SIGHUP SIGINT SIGTERM +cp -r "$SRC_PATH/"* "$tempdir/" +cd "$tempdir" + + +echo "== Converting theme into template..." + +PATHLIST=( + './common/' +) +for FILEPATH in "${PATHLIST[@]}"; do + find "$FILEPATH" -type f -exec sed -i'' \ + -e 's/#cfd6e6/%ARC_WIDGET_BORDER_COLOR%/gI' \ + -e 's/#f5f6f7/%BG%/gI' \ + -e 's/#3b3e45/%FG%/gI' \ + -e 's/#FFFFFF/%TXT_BG%/gI' \ + -e 's/#3b3e45/%TXT_FG%/gI' \ + -e 's/#5294e2/%SEL_BG%/gI' \ + -e 's/#fcfdfd/%BTN_BG%/gI' \ + -e 's/#e7e8eb/%MENU_BG%/gI' \ + -e 's/#2f343f/%MENU_BG%/gI' \ + -e 's/#D3DAE3/%MENU_FG%/gI' \ + -e 's/#fbfcfc/%INACTIVE_BG%/gI' \ + -e 's/#a9acb2/%INACTIVE_FG%/gI' \ + -e 's/#e2e7ef/%INACTIVE_FG%/gI' \ + -e 's/#fbfcfc/%INACTIVE_TXT_BG%/gI' \ + -e 's/#F04A50/%TERMINAL_COLOR1%/gI' \ + -e 's/#F08437/%TERMINAL_COLOR3%/gI' \ + -e 's/#FC4138/%TERMINAL_COLOR9%/gI' \ + -e 's/#73d216/%TERMINAL_COLOR10%/gI' \ + -e 's/#F27835/%TERMINAL_COLOR11%/gI' \ + -e 's/#4DADD4/%TERMINAL_COLOR12%/gI' \ + -e 's/#353945/%MENU_BG2%/gI' \ + -e 's/Name=Arc/Name=%OUTPUT_THEME_NAME%/g' \ + -e 's/#f46067/%TERMINAL_COLOR9%/gI' \ + -e 's/#cc575d/%TERMINAL_COLOR9%/gI' \ + -e 's/#f68086/%TERMINAL_COLOR9_LIGHTER%/gI' \ + -e 's/#d7787d/%TERMINAL_COLOR9_LIGHTER%/gI' \ + -e 's/#f13039/%TERMINAL_COLOR9_DARKER%/gI' \ + -e 's/#be3841/%TERMINAL_COLOR9_DARKER%/gI' \ + -e 's/#F8F8F9/%MENU_FG%/gI' \ + -e 's/#fdfdfd/%MENU_FG%/gI' \ + -e 's/#454C5C/%MENU_FG%/gI' \ + -e 's/#D1D3DA/%MENU_FG%/gI' \ + -e 's/#262932/%MENU_FG%/gI' \ + -e 's/#90949E/%MENU_FG%/gI' \ + -e 's/#90939B/%MENU_FG%/gI' \ + -e 's/#B6B8C0/%INACTIVE_MENU_FG%/gI' \ + -e 's/#666A74/%INACTIVE_MENU_FG%/gI' \ + -e 's/#7A7F8B/%INACTIVE_MENU_FG%/gI' \ + -e 's/#C4C7CC/%INACTIVE_MENU_FG%/gI' \ + -e 's/#BAC3CF/%MENU_FG%/gI' \ + -e 's/#4B5162/%TXT_FG%/gI' \ + -e 's/#AFB8C5/%MENU_FG%/gI' \ + -e 's/#404552/%MENU_BG%/gI' \ + -e 's/#383C4A/%MENU_BG%/gI' \ + -e 's/#5c616c/%FG%/gI' \ + -e 's/#d3d8e2/%SEL_BG%/gI' \ + {} \; ; +done + +#Not implemented yet: + #-e 's/%HDR_BTN_FG%/'"$HDR_BTN_FG"'/g' \ + #-e 's/%WM_BORDER_FOCUS%/'"$WM_BORDER_FOCUS"'/g' \ + #-e 's/%WM_BORDER_UNFOCUS%/'"$WM_BORDER_UNFOCUS"'/g' \ + #-e 's/%SPACING%/'"$SPACING"'/g' \ + #-e 's/%INACTIVE_TXT_FG%/'"$INACTIVE_TXT_FG"'/g' \ + #-e 's/%INACTIVE_MENU_FG%/'"$INACTIVE_MENU_FG"'/g' \ + #-e 's/#01A299/%ACCENT_BG%/g' \ + +#sed -i -e 's/^$material_radius: .px/$material_radius: '"$ROUNDNESS"'px/g' ./src/_sass/gtk/_variables.scss + +if [[ "${DEBUG:-}" ]]; then + echo "You can debug TEMP DIR: $tempdir, press [Enter] when finished" + read -r answer + if [[ "${answer}" = "q" ]] ; then + exit 125 + fi +fi + +for template_file in $(find ./common -name '*.thpl') ; do + cat ${template_file} >> ${template_file::-5} +done + +ASSETS_FILES=( + './common/gtk-2.0/assets.svg' + './common/gtk-2.0/assets-dark.svg' + './common/gtk-3.0/3.18/assets.svg' + './common/gtk-3.0/3.20/assets.svg' +) +for assets_file in "${ASSETS_FILES[@]}"; do + sed -i'' -e 's/%SEL_BG%/%ACCENT_BG%/g' ${assets_file} +done + +echo "== Filling the template with the new colorscheme..." +for FILEPATH in "${PATHLIST[@]}"; do + find "$FILEPATH" -type f -exec sed -i'' \ + -e 's/%ARC_WIDGET_BORDER_COLOR%/#'"$ARC_WIDGET_BORDER_COLOR"'/g' \ + -e 's/%BG%/#'"$BG"'/g' \ + -e 's/%BG2%/#'"$(darker $BG)"'/g' \ + -e 's/%FG%/#'"$FG"'/g' \ + -e 's/%ACCENT_BG%/#'"$ACCENT_BG"'/g' \ + -e 's/%SEL_BG%/#'"$SEL_BG"'/g' \ + -e 's/%SEL_BG2%/#'"$(darker $SEL_BG -20)"'/g' \ + -e 's/%SEL_FG%/#'"$SEL_FG"'/g' \ + -e 's/%TXT_BG%/#'"$TXT_BG"'/g' \ + -e 's/%TXT_FG%/#'"$TXT_FG"'/g' \ + -e 's/%MENU_BG%/#'"$MENU_BG"'/g' \ + -e 's/%MENU_BG2%/#'"$(mix $MENU_BG $BG 0.85)"'/g' \ + -e 's/%MENU_FG%/#'"$MENU_FG"'/g' \ + -e 's/%BTN_BG%/#'"$BTN_BG"'/g' \ + -e 's/%BTN_FG%/#'"$BTN_FG"'/g' \ + -e 's/%HDR_BTN_BG%/#'"$HDR_BTN_BG"'/g' \ + -e 's/%HDR_BTN_FG%/#'"$HDR_BTN_FG"'/g' \ + -e 's/%WM_BORDER_FOCUS%/#'"$WM_BORDER_FOCUS"'/g' \ + -e 's/%WM_BORDER_UNFOCUS%/#'"$WM_BORDER_UNFOCUS"'/g' \ + -e 's/%SPACING%/'"$SPACING"'/g' \ + -e 's/%INACTIVE_FG%/#'"$INACTIVE_FG"'/g' \ + -e 's/%INACTIVE_BG%/#'"$INACTIVE_BG"'/g' \ + -e 's/%INACTIVE_TXT_FG%/#'"$INACTIVE_TXT_FG"'/g' \ + -e 's/%INACTIVE_TXT_BG%/#'"$INACTIVE_TXT_BG"'/g' \ + -e 's/%INACTIVE_MENU_FG%/#'"$INACTIVE_MENU_FG"'/g' \ + -e 's/%INACTIVE_MENU_BG%/#'"$INACTIVE_MENU_BG"'/g' \ + -e 's/%TERMINAL_COLOR1%/#'"$TERMINAL_COLOR1"'/g' \ + -e 's/%TERMINAL_COLOR3%/#'"$TERMINAL_COLOR3"'/g' \ + -e 's/%TERMINAL_COLOR4%/#'"$TERMINAL_COLOR4"'/g' \ + -e 's/%TERMINAL_COLOR5%/#'"$TERMINAL_COLOR5"'/g' \ + -e 's/%TERMINAL_COLOR9%/#'"$TERMINAL_COLOR9"'/g' \ + -e 's/%TERMINAL_COLOR9_DARKER%/#'"$(darker $TERMINAL_COLOR9 10)"'/g' \ + -e 's/%TERMINAL_COLOR9_LIGHTER%/#'"$(darker $TERMINAL_COLOR9 -10)"'/g' \ + -e 's/%TERMINAL_COLOR10%/#'"$TERMINAL_COLOR10"'/g' \ + -e 's/%TERMINAL_COLOR11%/#'"$TERMINAL_COLOR11"'/g' \ + -e 's/%TERMINAL_COLOR12%/#'"$TERMINAL_COLOR12"'/g' \ + -e 's/%OUTPUT_THEME_NAME%/'"$OUTPUT_THEME_NAME"'/g' \ + {} \; ; +done + +#if [[ "$OPTION_GTK2_HIDPI" == "true" ]]; then + #mv ./src/gtk-2.0/main.rc.hidpi ./src/gtk-2.0/main.rc +#fi +#if [[ "$EXPORT_QT5CT" = 1 ]]; then + #config_home=${XDG_CONFIG_HOME:-"$HOME/.config"} + #qt5ct_colors_dir="$config_home/qt5ct/colors/" + #test -d "$qt5ct_colors_dir" || mkdir -p "$qt5ct_colors_dir" + #mv ./src/qt5ct_palette.conf "$qt5ct_colors_dir/$OUTPUT_THEME_NAME.conf" +#fi + +if [[ "$ARC_TRANSPARENCY" == "false" ]]; then + AUTOGEN_OPTS="${AUTOGEN_OPTS} --disable-transparency" +fi + +echo "== Making theme..." +mkdir distrib +./autogen.sh --prefix=$(readlink -e ./distrib/) --disable-light --disable-dark ${AUTOGEN_OPTS} +make install +echo + +echo +rm -fr "${DEST_PATH}" +if [[ "$ARC_TRANSPARENCY" == "false" ]]; then + mv ./distrib/share/themes/Arc-Darker-solid "${DEST_PATH}" +else + mv ./distrib/share/themes/Arc-Darker "${DEST_PATH}" +fi +echo "== The theme was installed to ${DEST_PATH}" + +echo +echo "== SUCCESS" +exit 0 diff --git a/common/gtk-3.0/3.18/sass/_colors.scss.thpl b/common/gtk-3.0/3.18/sass/_colors.scss.thpl new file mode 120000 index 0000000..59fa5d5 --- /dev/null +++ b/common/gtk-3.0/3.18/sass/_colors.scss.thpl @@ -0,0 +1 @@ +../../_colors.scss.thpl \ No newline at end of file diff --git a/common/gtk-3.0/3.20/sass/_colors.scss.thpl b/common/gtk-3.0/3.20/sass/_colors.scss.thpl new file mode 120000 index 0000000..59fa5d5 --- /dev/null +++ b/common/gtk-3.0/3.20/sass/_colors.scss.thpl @@ -0,0 +1 @@ +../../_colors.scss.thpl \ No newline at end of file diff --git a/common/gtk-3.0/_colors.scss.thpl b/common/gtk-3.0/_colors.scss.thpl new file mode 100644 index 0000000..40a3a3d --- /dev/null +++ b/common/gtk-3.0/_colors.scss.thpl @@ -0,0 +1,107 @@ +// When color definition differs for dark and light variant, +// it gets @if ed depending on $variant + +@function gtkopacity($c, $a) { + @return scale-color($c, $alpha: percentage(-1 + $a)); +} + +$base_color: if($variant =='light', %TXT_BG%, %MENU_BG2%); +$base_bg_color: %BG%; +$text_color: if($variant == 'light', %TXT_FG%, %MENU_FG%); +$bg_color: if($variant =='light', $base_bg_color, %MENU_BG%); +$fg_color: if($variant =='light', %FG%, %MENU_FG%); + +$selected_fg_color: %SEL_FG%; +$selected_bg_color: %SEL_BG%; +$selected_borders_color: darken($selected_bg_color, 20%); +$borders_color: if($variant =='light', darken($bg_color,9%), darken($bg_color,6%)); + +$link_color: if($variant == 'light', darken($selected_bg_color,10%), + lighten($selected_bg_color,20%)); +$link_visited_color: if($variant == 'light', darken($selected_bg_color,20%), + lighten($selected_bg_color,10%)); + +$selection_mode_bg: if($transparency == 'true', transparentize($selected_bg_color, 0.05), $selected_bg_color); +$selection_mode_fg: $selected_fg_color; +$warning_color: %TERMINAL_COLOR11%; +$error_color: %TERMINAL_COLOR9%; +$warning_fg_color: white; +$error_fg_color: white; +$success_color: %TERMINAL_COLOR10%; +$destructive_color: %TERMINAL_COLOR1%; +$suggested_color: %TERMINAL_COLOR12%; +$destructive_fg_color: white; +$suggested_fg_color: white; + +$drop_target_color: %TERMINAL_COLOR3%; + +//insensitive state derived colors +$insensitive_fg_color: if($variant == 'light', transparentize($fg_color, 0.45), transparentize($fg_color, 0.55)); +$insensitive_bg_color: if($variant == 'light', mix($bg_color, $base_color, 40%), lighten($bg_color, 2%)); + +$header_bg: red; +@if $transparency=='true' and $variant=='light' { $header_bg: transparentize(%MENU_BG%, 0.05); } +@if $transparency=='false' and $variant=='light' { $header_bg: %MENU_BG%; } +@if $transparency=='true' and ($variant=='dark' or $darker=='true') { $header_bg: transparentize(%MENU_BG%, 0.03); } +@if $transparency=='false' and ($variant=='dark' or $darker=='true') { $header_bg: %MENU_BG%; } + +$header_bg_backdrop: if($darker == 'true' or $variant == 'dark', lighten($header_bg, 1.5%), lighten($header_bg, 3%)); + +$header_border: if($variant == 'light' and $darker=='false', darken($header_bg, 7%), darken($header_bg, 4%)); + +$header_fg: if($variant == 'light', saturate(transparentize($fg_color, 0.2), 10%), saturate(transparentize($fg_color, 0.2), 10%)); +$header_fg: if($darker == 'true', saturate(transparentize(%MENU_FG%, 0.2), 10%), $header_fg); + +$dark_sidebar_bg: if($transparency == 'true', transparentize(%MENU_BG2%, 0.05), %MENU_BG2%); +$dark_sidebar_fg: %MENU_FG%; +$dark_sidebar_border: if($variant == 'light', $dark_sidebar_bg, darken($dark_sidebar_bg, 5%)); + +$osd_fg_color: $dark_sidebar_fg; +$osd_bg_color: $dark_sidebar_bg; + +$osd_button_bg: transparentize(lighten($osd_bg_color, 22%), 0.6); +$osd_button_border: transparentize(darken($osd_bg_color, 12%), 0.6); + +$osd_entry_bg: transparentize(lighten($osd_bg_color, 22%), 0.6); +$osd_entry_border: transparentize(darken($osd_bg_color, 12%), 0.6); + +$osd_insensitive_bg_color: darken($osd_bg_color, 3%); +$osd_insensitive_fg_color: mix($osd_fg_color, opacify($osd_bg_color, 1), 30%); +$osd_borders_color: transparentize(black, 0.3); + +$panel_bg: darken($dark_sidebar_bg, 4.7%); +$panel_fg: $dark_sidebar_fg; + +$entry_bg: if($variant=='light', $base_color, lighten($base_color, 0%)); +$entry_border: if($variant == 'light', %ARC_WIDGET_BORDER_COLOR%, darken($borders_color, 0%)); + +$header_entry_bg: if($darker == 'true' or $variant == 'dark', transparentize(lighten($header_bg, 22%), 0.6), transparentize($base_color, 0.1)); +$header_entry_border: if($darker == 'true' or $variant == 'dark', transparentize(darken($header_bg, 12%), 0.6), transparentize($header_fg, 0.7)); + +$button_bg: if($variant=='light', %BTN_BG%, %HDR_BTN_BG%); +$button_border: $entry_border; + +$header_button_bg: %HDR_BTN_BG%; +$header_button_border: if($darker == 'true' or $variant == 'dark', transparentize(darken($header_bg, 12%), 0.6), transparentize($header_fg, 0.7)); + +//WM Buttons + +// Close +$wm_button_close_bg: if($variant == 'light' and $darker == 'false', %TERMINAL_COLOR9%, %TERMINAL_COLOR9%); +$wm_button_close_hover_bg: if($variant == 'light' and $darker == 'false', %TERMINAL_COLOR9_LIGHTER%, %TERMINAL_COLOR9_LIGHTER%); +$wm_button_close_active_bg: if($variant == 'light' and $darker == 'false', %TERMINAL_COLOR9_DARKER%, %TERMINAL_COLOR9_DARKER%); + +$wm_icon_close_bg: if($variant == 'light' and $darker == 'false',%MENU_FG% , %MENU_BG%); + +// Minimize, Maximize +$wm_button_hover_bg: if($variant == 'light' and $darker == 'false', %MENU_FG%, %MENU_FG%); +$wm_button_active_bg: $selected_bg_color; + +$wm_button_hover_border: if($variant == 'light' and $darker == 'false', %MENU_FG%, %MENU_FG%); + +$wm_icon_bg: if($variant == 'light' and $darker == 'false', %MENU_FG%, %MENU_FG%); +$wm_icon_unfocused_bg: if($variant == 'light' and $darker == 'false', %INACTIVE_MENU_FG%, %INACTIVE_MENU_FG%); +$wm_icon_hover_bg: if($variant == 'light' and $darker == 'false', %INACTIVE_MENU_FG%, %INACTIVE_MENU_FG%); +$wm_icon_active_bg: $selected_fg_color; + +/* vim: set ft=scss: */ diff --git a/scripts/darker.sh b/scripts/darker.sh new file mode 100755 index 0000000..b9514a4 --- /dev/null +++ b/scripts/darker.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +set -ueo pipefail +#set -x + +darker_channel() { + value="$1" + light_delta="$2" + result="$(bc <<< "ibase=16; $value - $light_delta")" + if [[ "$result" -lt 0 ]]; then + result=0 + fi + if [[ "$result" -gt 255 ]]; then + result=255 + fi + echo "$result" +} + +darker() { + hexinput="$(tr '[:lower:]' '[:upper:]' <<< "$1")" + light_delta="${2-10}" + + a="$(cut -c-2 <<< "$hexinput")" + b="$(cut -c3-4 <<< "$hexinput")" + c="$(cut -c5-6 <<< "$hexinput")" + + r="$(darker_channel "$a" "$light_delta")" + g="$(darker_channel "$b" "$light_delta")" + b="$(darker_channel "$c" "$light_delta")" + + printf '%02x%02x%02x\n' "$r" "$g" "$b" +} + +darker "$@" diff --git a/scripts/mix.sh b/scripts/mix.sh new file mode 100755 index 0000000..73c1950 --- /dev/null +++ b/scripts/mix.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +set -ueo pipefail +#set -x + +mix_channel() { + value1="$(printf '%03d' "0x$1")" + value2="$(printf '%03d' "0x$2")" + ratio="$3" + result="$(bc <<< "scale=0; ($value1 * 100 * $ratio + $value2 * 100 * (1 - $ratio)) / 100")" + if [[ "$result" -lt 0 ]]; then + result=0 + elif [[ "$result" -gt 255 ]]; then + result=255 + fi + echo "$result" +} + +mix() { + hexinput1="$(tr '[:lower:]' '[:upper:]' <<< "$1")" + hexinput2="$(tr '[:lower:]' '[:upper:]' <<< "$2")" + ratio="${3-0.5}" + + a="$(cut -c-2 <<< "$hexinput1")" + b="$(cut -c3-4 <<< "$hexinput1")" + c="$(cut -c5-6 <<< "$hexinput1")" + d="$(cut -c-2 <<< "$hexinput2")" + e="$(cut -c3-4 <<< "$hexinput2")" + f="$(cut -c5-6 <<< "$hexinput2")" + + r="$(mix_channel "$a" "$d" "$ratio")" + g="$(mix_channel "$b" "$e" "$ratio")" + b="$(mix_channel "$c" "$f" "$ratio")" + + printf '%02x%02x%02x\n' "$r" "$g" "$b" +} + +mix "$@"