#!/bin/bash

if [ "$1" ]; then
  SIZE="$1"
else
  echo "USAGE generate_background_gradient.sh SIZE (XxY)"
  exit 1
fi

  CONVERTSTRING=" -size ""$SIZE "
  case $(($RANDOM % 6 +1)) in
    1)
      CONVERTSTRING="$CONVERTSTRING""plasma: -fill grey -colorize 75% "
      ;;
    2)
      FROMCOLOR=$(./random_line.sh /usr/X11R6/lib/X11/rgb.txt | cut -f 3- | sed 's/[ \t]*//g')
      TOCOLOR=$(./random_line.sh /usr/X11R6/lib/X11/rgb.txt | cut -f 3- | sed 's/[ \t]*//g')
      CONVERTSTRING="$CONVERTSTRING""plasma:""$FROMCOLOR""-""$TOCOLOR ""-fill gray -colorize 75% "
      ;;
    3)
      CONVERTSTRING="$CONVERTSTRING""plasma:""grey-grey -blur 0x5 "
      ;;
    4)
      CONVERTSTRING="$CONVERTSTRING""plasma:""white-white "
      ;;
    5)
      CONVERTSTRING="$CONVERTSTRING""plasma:""black-black ""-fill black -colorize 75% "
      ;;
    6)
      CONVERTSTRING="$CONVERTSTRING""xc: -fx rand() -blur 0x2 "
      ;;
  esac
  if [ "$(($RANDOM % 6))" = 1 ]; then
    CONVERTSTRING="$CONVERTSTRING""-blur 0x2 -emboss .2 "
  fi
  if [ "$(($RANDOM % 6))" = 1 ]; then
    CONVERTSTRING="$CONVERTSTRING""-charcoal 3 -negate "
  fi
  if [ "$(($RANDOM % 6))" = 1 ]; then
    CONVERTSTRING="$CONVERTSTRING""-edge 1 "
  fi
  case $(($RANDOM % 5 +1)) in
    1)
      CONVERTSTRING="$CONVERTSTRING""-fx intensity "
      ;;
    2)
      CONVERTSTRING="$CONVERTSTRING""-blur 0x""$(($RANDOM % 3 + 1)) "
      ;;
    3)
      CONVERTSTRING="$CONVERTSTRING""-colorspace gray "
      ;;
    4)
      CONVERTSTRING="$CONVERTSTRING""-shade ""$(($RANDOM % 180 + 0))""x""$(($RANDOM % 10 + 5)) "
      ;;
    5)
      CONVERTSTRING="$CONVERTSTRING "
      ;;
  esac

  CONVERTSTRING="$CONVERTSTRING""background.png"
  convert $CONVERTSTRING

exit 0
