Shell编程之matrix---装逼又炫酷

代码如下:

#!/bin/bash
blue="\033[0;34m"
brightblue="\033[1;34m"
cyan="\033[0;36m"
brightcyan="\033[1;36m"
green="\033[0;32m"
brightgreen="\033[1;32m"
red="\033[0;31m"
brightred="\033[1;31m"
white="\033[1;37m"
black="\033[0;30m"
grey="\033[0;37m"
darkgrey="\033[1;30m"


colors=($blue $brightgreen $grey)
spacing=${1:-100}
scroll=${2:-0}
screenlines=$(expr `tput lines` - 1 + $scroll)
screencols=$(expr `tput cols` / 2 - 1)
chars=(a b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3 4 5 6 7 8 9 0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)    ##请在此处修改你想显示的字符

count=${#chars[@]}
colorcount=${#colors[@]}

trap "tput sgr0; clear; exit" SIGTERM SIGINT

if [[ $1 =~ "-h" ]]
  then
  echo "display a matrix screen in the terminal"
  echo "usage:          matrix [SPACING [SCROLL]]"
  echo "example: matrix 100 0"
  exit 0
fi

clear
tput cup 0 0

while :
  do
  for i in $(eval echo {1..$screenlines})
    do
     for i in $(eval echo {1..$screenlines})
      do
      rand=$(($RANDOM%$spacing))
      case $rand in
       0)
        printf "${colors[$RANDOM%$colorcount]}${chars[$RANDOM%$count]} ";;
       1)
        printf "  ";;
       *)
        printf "\033[2C";;
      esac
     done
     printf "\n"
    done
    tput cup 0 0
done

执行效果如下:
在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

指剑

捐点钱吧,小笼包8元一笼,谢谢

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值