mondrian 4.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/bin/bash
  2. # N.B.: Use bash for $RANDOM
  3. #
  4. # mondrian: randomly generate some Modrian art in tmux
  5. #
  6. # Copyright (C) 2011-2014 Dustin Kirkland
  7. #
  8. # Authors: Dustin Kirkland <kirkland@byobu.org>
  9. #
  10. # This program is free software: you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation, version 3 of the License.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. trap "tput reset" EXIT HUP INT QUIT TERM KILL ILL TRAP ABRT BUS FPE USR1 SEGV USR2 PIPE ALRM
  22. # Special mode, argv[1]="color", paint the screen
  23. if [ "$1" = "color" ] && [ -n "$2" ]; then
  24. i=0
  25. out=
  26. sleep 0.2
  27. count=$(stty size | awk '{print $1*$2}')
  28. perl -e "print color 'reset'; printf \"\x1b[48;5;${2}m%${count}s\", \" \";";
  29. head -n1
  30. tmux kill-window -t mondrian
  31. exit 0
  32. fi
  33. get_random_direction() {
  34. if [ $((RANDOM % 2)) -eq 0 ]; then
  35. echo "-v"
  36. else
  37. echo "-h"
  38. fi
  39. }
  40. get_random_numbers() {
  41. local max="$1" R=0 B=0 Y=0
  42. R=$((RANDOM % max + 1))
  43. B=$((RANDOM % max + 1))
  44. Y=$((RANDOM % max + 1))
  45. while [ "$B" = "$R" ] || [ "$B" = "$Y" ]; do
  46. B=$((RANDOM % max + 1))
  47. done
  48. while [ "$Y" = "$R" ] || [ "$Y" = "$B" ]; do
  49. Y=$((RANDOM % max + 1))
  50. done
  51. _RET="$R $B $Y"
  52. }
  53. red_color=196
  54. yellow_color=226
  55. blue_color=57
  56. white_color=231
  57. tmux kill-window -t mondrian
  58. tmux new-window -n mondrian "$BYOBU_PREFIX/lib/byobu/include/mondrian color $white_color" \; \
  59. set-option -g pane-active-border-style bg=colour231 \; \
  60. set-option -g pane-active-border-style fg=black \; \
  61. set-option -g pane-border-style bg=colour231 \; \
  62. set-option -g pane-border-style fg=black \; \
  63. split-window $(get_random_direction) "$BYOBU_PREFIX/lib/byobu/include/mondrian color $white_color" \; \
  64. split-window $(get_random_direction) -t $((RANDOM % 2)) "$BYOBU_PREFIX/lib/byobu/include/mondrian color $white_color" \; \
  65. split-window $(get_random_direction) -t $((RANDOM % 3)) "$BYOBU_PREFIX/lib/byobu/include/mondrian color $white_color" \; \
  66. split-window $(get_random_direction) -t $((RANDOM % 4)) "$BYOBU_PREFIX/lib/byobu/include/mondrian color $red_color" \; \
  67. split-window $(get_random_direction) -t $((RANDOM % 5)) "$BYOBU_PREFIX/lib/byobu/include/mondrian color $white_color" \; \
  68. split-window $(get_random_direction) -t $((RANDOM % 6)) "$BYOBU_PREFIX/lib/byobu/include/mondrian color $yellow_color" \; \
  69. split-window $(get_random_direction) -t $((RANDOM % 7)) "$BYOBU_PREFIX/lib/byobu/include/mondrian color $white_color" \; \
  70. split-window $(get_random_direction) -t $((RANDOM % 8)) "$BYOBU_PREFIX/lib/byobu/include/mondrian color $blue_color" \; \
  71. split-window $(get_random_direction) -t $((RANDOM % 9)) "$BYOBU_PREFIX/lib/byobu/include/mondrian color $white_color" \; \
  72. split-window $(get_random_direction) -t $((RANDOM % 9)) "$BYOBU_PREFIX/lib/byobu/include/mondrian color $white_color" \; \
  73. split-window $(get_random_direction) -t $((RANDOM % 10)) "$BYOBU_PREFIX/lib/byobu/include/mondrian color $white_color" \; \
  74. split-window $(get_random_direction) -t $((RANDOM % 11)) "$BYOBU_PREFIX/lib/byobu/include/mondrian color $white_color" \; \
  75. split-window $(get_random_direction) -t $((RANDOM % 12)) "$BYOBU_PREFIX/lib/byobu/include/mondrian color $white_color" \; \
  76. split-window $(get_random_direction) -t $((RANDOM % 13)) "$BYOBU_PREFIX/lib/byobu/include/mondrian color $white_color" \; \
  77. split-window $(get_random_direction) -t $((RANDOM % 14)) "$BYOBU_PREFIX/lib/byobu/include/mondrian color $white_color" \; \
  78. split-window $(get_random_direction) -t $((RANDOM % 15)) "$BYOBU_PREFIX/lib/byobu/include/mondrian color $white_color" \; \
  79. split-window $(get_random_direction) -t $((RANDOM % 16)) "$BYOBU_PREFIX/lib/byobu/include/mondrian color $white_color" \; \
  80. split-window $(get_random_direction) -t $((RANDOM % 17)) "$BYOBU_PREFIX/lib/byobu/include/mondrian color $white_color" \; \
  81. split-window $(get_random_direction) -t $((RANDOM % 18)) "$BYOBU_PREFIX/lib/byobu/include/mondrian color $white_color" \; \
  82. split-window $(get_random_direction) -t $((RANDOM % 19)) "$BYOBU_PREFIX/lib/byobu/include/mondrian color $white_color" \; \
  83. split-window $(get_random_direction) -t $((RANDOM % 20)) "$BYOBU_PREFIX/lib/byobu/include/mondrian color $white_color" \; \
  84. exit 0