hexive / sunpaper

Dynamic wallpaper changes based on the sun.
https://github.com/hexive/sunpaper
Apache License 2.0
197 stars 7 forks source link

Fading transitions #13

Closed Barbaross93 closed 3 years ago

Barbaross93 commented 3 years ago

Hey @hexive, great script! I love using it especially now that my favorite colorscheme has a light variant. I think someone mentioned in the r/unixporn post about adding transitions to sunpaper. Well, I went ahead and made a script that can cache animation frames and then apply them using imagemagick and hsetroot (obviously replace hsetroot to setwallpaper, feh or w/e). Here's the script, titled sun_animate.sh:

#!/usr/bin/env bash

wallpaperPath="/home/barbarossa/Public/BitForest_sunpaper"
cachePath="/home/barbarossa/.cache/sunpaper"

cache_transitions() {
    for i in {1..8}; do
        if [ ! -d $cachePath/$i ]; then
            mkdir $cachePath/$i
        fi

        alpha=0
        c=0
        if [ $i -eq 1 ]; then
            while [ $alpha -le 100 ]; do
                alpha=$(( alpha + 5 ))
                c=$(( c + 1 ))
                composite -blend $alpha -gravity center $wallpaperPath/$i.jpg $wallpaperPath/8.jpg $cachePath/$i/$c.png
            done
            continue
        fi

        next=$(( $i - 1 ))
        while [ $alpha -le 100 ]; do
            alpha=$(( alpha + 5 ))
            c=$(( c + 1 ))
            composite -blend $alpha -gravity center $wallpaperPath/$i.jpg $wallpaperPath/$next.jpg $cachePath/$i/$c.png
        done
    done
}

animate_wallpaper(){
    directory="$1"
    files=$(ls -1 $cachePath/$directory | wc -l)
    for i in $(seq $files); do
        hsetroot -fill $cachePath/$directory/$i.png &
        sleep 0.05
    done
}

while :; do
    case "$1" in
        --cache|-c)
            cache_transitions
            shift
            ;;
        --apply|-a)
            animate_wallpaper "$2"
                        shift
            ;;
        *)
            break
            ;;
    esac
done

I replaced the line in sunpaper.sh that had setwallpaper (line 476 I believe) with sun_animate.sh -a "$image" and voila, a smooth transition between each wallpaper!

I just thought I'd share this in case you were looking to implement this feature in sunpaper and needed inspiration :)

hexive commented 3 years ago

Oh hey! I recognize your name from reddit -- I'm a big fan of gloomy forester! ... now I'm super curious what this BitForest_sunpaper looks like. (also, baltimore? hello from silver spring.)

This animation script looks fun. I can't wait to play with it. It looks straight forward to roll it into an optional setting on sunpaper. Thank you so much for sharing!

Barbaross93 commented 3 years ago

Thanks, glad you liked that setup! Funny enough, the everforest colorscheme (formerly forest-night) is the one that now has a light variant. Unfortunately, the BitForest theme is nothing too fancy at the moment. It's just the wallpaper I used in gloomy forest but brightened/darkened for different points in the day. I'm still on the hunt for a suitable pixel art forest theme.

I've been thinking a little more regarding the script and I realized it could definitely use some cleaning up/optimizations. I should also mention that I didn't test it thoroughly. I suspect that the sleep 0.05 line in animate_wallpaper function should probably be an adjustable option such as transitionDelay or something along those lines. This is because I imagine different images loading at different rates based on filesizes. If you'd like, I can go ahead and make those changes here. Not sure about a PR though, because I'm not intimately familiar with sunpaper.sh (yet that is).

hexive commented 3 years ago

Whatever is easiest for you. I'm brand new to git (obviously, haha) -- would creating a develop-animate branch be the normal method to colab on a feature like this?

Barbaross93 commented 3 years ago

I'm definitely not a git pro either, but yeah, I'm pretty sure when devs work on a new feature they make it in a separate branch