Last active
June 15, 2016 12:19
-
-
Save tohn/7a6143d7d34dabb63d71 to your computer and use it in GitHub Desktop.
Create a wallpaper with GMIC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
### | |
# adjust these variables | |
root="$HOME/pics/wallpaper" | |
name=$(date +%s) | |
log="/tmp/$(basename "$0").log" | |
### | |
### | |
# Dependencies | |
# feh, gmic + gimp-plugin-gmic, imagemagick | |
command -v feh >/dev/null 2>&1 || { echo >&2 "I require \"feh\" but it's not installed. Aborting."; exit 1; } | |
command -v gmic >/dev/null 2>&1 || { echo >&2 "I require \"gmic\" but it's not installed. Aborting."; exit 1; } | |
command -v montage >/dev/null 2>&1 || { echo >&2 "I require \"imagemagick\" but it's not installed. Aborting."; exit 1; } | |
### | |
### | |
# TODO: | |
# * order of monitors (now: ascending resolution), i.e. via xrandr the | |
# position of a monitor | |
# * montage does not work if the monitors are not in one row | |
# (horizontal) | |
# * other programs to set the background (feh does not work with | |
# GNOME, KDE, ...) | |
# http://askubuntu.com/questions/72549/how-to-determine-which-window-manager-is-running | |
# * what if shuf > border values? (0.0 < plasma:alpha < 5.0, with shuf it could be 5.37) | |
### | |
### | |
# Variables | |
turbulence=1 # standard | |
plasma=0 | |
gradient=0 | |
rand=0 | |
debug=99 # nothing? | |
mode="turbulence" # standard | |
setit=0 | |
### | |
### | |
# Functions | |
function usage() { | |
cat << ! | |
Usage: $0 [-g|-p|-t] [-r] [-s] | |
-g: Use gradient as mode | |
-p: Use plasma as mode | |
-t: Use turbulence as mode (default) | |
-r: generate a random wallpaper for each monitor | |
-s: set the wallpaper | |
! | |
} | |
## gradient | |
# command: gmic $width,$height,$depth,$spectrum -gimp_corner_gradient $ulr,$ulg,$ulb,$ula,$urr,$urg,$urb,$ura,$blr,$blg,$blb,$bla,$brr,$brg,$brb,$bra -o gradient.png | |
# example: gmic 1920,1080,1,3 -gimp_corner_gradient 255,255,255,128,255,0,0,255,0,255,0,255,0,0,255,255 -o gradient.png | |
# width: width | |
# height: height | |
# depth: normally 1 | |
# spectrum: normally 3 | |
# up left: rgba (0-255 each) | |
# up right: rgba (0-255 each) | |
# bottom left: rgba (0-255 each) | |
# bottom right: rgba (0-255 each) | |
# beautiful | |
shuffle_gradient="$(shuf -i 75-255 -n 12 | sed '3~3 a 255' | tr '\n' ',' | sed 's/,$//')" | |
# normal | |
# shuffle_gradient="$(shuf -i 0-255 -n 12 | sed '3~3 a 255' | tr '\n' ',' | sed 's/,$//')" | |
function shuffle_gradient() { | |
if [[ "$rand" == 1 ]] ; then | |
shuffle_gradient="$(shuf -i 75-255 -n 12 | sed '3~3 a 255' | tr '\n' ',' | sed 's/,$//')" | |
fi | |
} | |
## turbulence | |
# command: gmic $width,$height,$depth,$spectrum -gimp_turbulence $radius,$octaves,$damping_per_octave,$difference_mixing,$mode -o turbulence.png | |
# example: gmic 1920,1080,1,3 -gimp_turbulence 618.54,6,4.43,0,3 -o turbulence.png | |
# | |
# width: width | |
# height: height | |
# depth: normally 1 | |
# spectrum: normally 3 | |
# radius: 1 - 1024 | |
# octaves: 1 - 12 | |
# damping per octave: 1.0 - 10.0 | |
# difference mixing: -10.0 - 10.0 | |
# mode: turbulence (0), turbulence 2 (1), fractal noise (2), fractured clouds (3), stardust (4), pea soup (5) | |
# beautiful | |
shuffle_turbulence="$(shuf -i 50-1024 -n 1),$(shuf -i 1-12 -n 1),$(shuf -i 5-10 -n 1).$(shuf -i 0-9 -n 2 -z),$(shuf -i 0-10 -n 1).$(shuf -i 0-9 -n 2 -z),$(shuf -i 0-3 -n 1)" | |
# normal | |
# shuffle_turbulence="$(shuf -i 1-1024 -n 1),$(shuf -i 1-12 -n 1),$(shuf -i 1-10 -n 1).$(shuf -i 0-9 -n 2 -z),$(echo "$(shuf -i 0-20 -n 1)-10"|bc).$(shuf -i 0-9 -n 2 -z),$(shuf -i 0-5 -n 1)" | |
function shuffle_turbulence() { | |
if [[ "$rand" == 1 ]] ; then | |
shuffle_turbulence="$(shuf -i 50-1024 -n 1),$(shuf -i 1-12 -n 1),$(shuf -i 5-10 -n 1).$(shuf -i 0-9 -n 2 -z),$(shuf -i 0-10 -n 1).$(shuf -i 0-9 -n 2 -z),$(shuf -i 0-3 -n 1)" | |
fi | |
} | |
## | |
## plasma | |
# command: gmic $width,$height,$depth,$spectrum -gimp_plasma $alpha,$beta,$scale,$randomize,$transparency,$r,$g,$b -o plasma.png | |
# example: gmic 1920,1080,1,3 -gimp_plasma 3.98058,8.73786,10,0,0,128,128,128 -o plasma.png | |
# width: width | |
# height: height | |
# depth: normally 1 | |
# spectrum: normally 3 | |
# alpha: 0.0 - 5.0 | |
# beta: 0.0 - 100.0 | |
# scale: 2 - 10 | |
# randomize: 0 or 1 | |
# transparency: 0 or 1 | |
# color: rgb (0 - 255 each) | |
# beautiful | |
shuffle_plasma="0.00,0.00,$(shuf -i 9-10 -n 1),1,0,$(shuf -i 75-255 -n 3 | tr '\n' ',' | sed 's/,$//')" | |
# normal | |
# shuffle_plasma="$(shuf -i 0-5 -n 1).$(shuf -i 0-9 -n 2 -z),$(shuf -i 0-100 -n 1).$(shuf -i 0-9 -n 2 -z),$(shuf -i 2-10 -n 1),$(shuf -i 0-1 -n 1),0,$(shuf -i 0-255 -n 3 | tr '\n' ',' | sed 's/,$//')" | |
function shuffle_plasma() { | |
if [[ "$rand" == 1 ]] ; then | |
shuffle_plasma="0.00,0.00,$(shuf -i 9-10 -n 1),1,0,$(shuf -i 75-255 -n 3 | tr '\n' ',' | sed 's/,$//')" | |
fi | |
} | |
function gradient() { | |
shuffle_gradient | |
gmic -v -"$debug" "$(sed 's/x/,/' <<<"$res"),1,3" \ | |
-gimp_corner_gradient "$shuffle_gradient" -o \ | |
"$root/$res/$mode-$name.png" | |
} | |
function plasma() { | |
shuffle_plasma | |
gmic -v -"$debug" "$(sed 's/x/,/' <<<"$res"),1,3" \ | |
-gimp_plasma "$shuffle_plasma" -o \ | |
"$root/$res/$mode-$name.png" | |
} | |
function turbulence() { | |
shuffle_turbulence | |
gmic -v -"$debug" "$(sed 's/x/,/' <<<"$res"),1,3" \ | |
-gimp_turbulence "$shuffle_turbulence" -o \ | |
"$root/$res/$mode-$name.png" | |
} | |
### | |
### | |
# Get and set parameters | |
while getopts tpgrs OPT ; do | |
case "$OPT" in | |
t) turbulence=1 ; mode="turbulence" ;; | |
p) plasma=1 ; mode="plasma" ;; | |
g) gradient=1 ; mode="gradient" ;; | |
r) rand=1 ;; | |
s) setit=1 ;; | |
?) usage ; exit 1 ;; | |
esac | |
done | |
### | |
# display size | |
all="" | |
while read -r res line ; do | |
[ ! -d "$root/$res" ] && mkdir -p "$root/$res" | |
if [ "$gradient" -eq 1 ] ; then | |
gradient | |
elif [ "$plasma" -eq 1 ] ; then | |
plasma | |
else | |
turbulence | |
fi | |
# swap order here, if you have multiple monitors ordered by | |
# descending resolution, i.e. big monitor on the left, little one | |
# on the right | |
out="shuffle_$mode" | |
echo "$name:$mode:${!out}" >> "$log" | |
all="$all $root/$res/$mode-$name.png" | |
done < <(xrandr | grep "\*" | sort -nr) | |
# montage (only if more than one screen is connected) | |
cur=$(xrandr | head -1 | tr -d ' ' | cut -d\, -f 2 | sed 's/current//') | |
[ ! -d "$root/$cur" ] && mkdir "$root/$cur" | |
if [[ $(xrandr | grep -c "\ connected") -gt 1 ]] ; then | |
montage -background black -mode Concatenate \ | |
"$all" "$root/$cur/$mode-$name.png" | |
fi | |
# set the background with feh, if parameter is given | |
[ "$setit" -eq 1 ] && feh --bg-tile "$root/$cur/$mode-$name.png" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment