Created
June 14, 2017 20:09
-
-
Save insanity54/e4aecc01faa2287441a8a54eb817a1d7 to your computer and use it in GitHub Desktop.
A Bash script which bounches a terminal (`cmatrix -bau5`) around the screen for screensaver purposes.
This file contains hidden or 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 | |
## | |
## CONFIGURATION (Edit at will) | |
## | |
screenw=1280 | |
screenh=1024 | |
speed=2 # the amount of pixels to move the window by | |
debug=0 # level 0-2 | |
## | |
## GLOBALS (Don't edit unless you know what you're doing) | |
## | |
go=0 | |
xo=900 | |
yo=400 | |
wo=350 | |
ho=270 | |
dB=1 | |
dR=1 | |
function matrixBounce() { | |
g=$go | |
x=$xo | |
y=$yo | |
w=$wo | |
h=$ho | |
while [[ 1 ]]; do | |
cT=0 | |
cL=0 | |
cB=0 | |
cR=0 | |
# detect collisions | |
[[ $y -lt 1 ]] && cT=1 | |
[[ $x -lt 1 ]] && cL=1 | |
[[ $(($y+$h)) -gt $screenh ]] && cB=1 | |
[[ $(($x+$w)) -gt $screenw ]] && cR=1 | |
# if there was a collision, redirect | |
[[ $cT -eq 1 ]] && let dB=1 | |
[[ $cL -eq 1 ]] && let dR=1 | |
[[ $cB -eq 1 ]] && let dB=0 | |
[[ $cR -eq 1 ]] && let dR=0 | |
# debug | |
if [[ $debug -ge 1 ]]; then | |
if [[ $dB -eq 1 && $dR -eq 1 ]]; then echo 'down right 🢆'; fi | |
if [[ $dB -eq 0 && $dR -eq 1 ]]; then echo 'up right 🢅'; fi | |
if [[ $dB -eq 1 && $dR -eq 0 ]]; then echo 'down left 🢇'; fi | |
if [[ $dB -eq 0 && $dR -eq 0 ]]; then echo 'up left 🢄'; fi | |
if [[ $debug -ge 2 ]]; then | |
echo "dR=$dR dB=$dB cT=$cT cL=$cL cB=$cB cR=$cR y=$y x=$x y+h=$(($y+$h)) x+w=$(($x+$w)) screenw=$screenw" | |
fi | |
fi | |
# based on the new direction, set next position | |
if [[ $dB -eq 1 ]]; then | |
let y=y+$speed | |
else | |
let y=y-$speed | |
fi | |
if [[ $dR -eq 1 ]]; then | |
let x=x+$speed | |
else | |
let x=x-$speed | |
fi | |
# move the window to the next position | |
wmctrl -F -r MatrixView -e $g,$x,$y,$w,$h | |
sleep 0.01 | |
done | |
} | |
# greets https://www.linuxquestions.org/questions/programming-9/bash-detecting-ctrl-c-being-pressed-785518-print/ | |
function trapeze() { | |
echo "Thanks for playing!" | |
# reset MatrixView to home position | |
# @todo make this dynamically set on startup | |
wmctrl -F -r MatrixView -e $go,$xo,$yo,$wo,$ho | |
exit 0 | |
} | |
trap trapeze SIGINT | |
matrixBounce |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment