Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Fill console with 24-bit RGB colored blocks -- short free demo
- # Copyright (c)2018/04/10, zebulon_fr
- # License: Public Domain ;D
- # ---------------------------------------------------------------
- shopt -s checkwinsize
- export COLUMNS
- export LINES
- XMAX=$[COLUMNS-1]
- YMAX=$[LINES-2]
- # Random bi-colored block
- Random() {
- local Rf Gf Bf Rb Gb Bb
- # Random foreground RGB color
- Rf=$[RANDOM%256]
- Gf=$[RANDOM%256]
- Bf=$[RANDOM%256]
- # Random background RGB color
- Rb=$[RANDOM%256]
- Gb=$[RANDOM%256]
- Bb=$[RANDOM%256]
- # Bi-colored block: top=foreground color, bottom=background color
- echo "\e[48;2;$Rb;$Gb;${Bb}m\e[38;2;$Rf;$Gf;${Bf}mâ–€"
- }
- # Computed color from (X,Y)
- Color1() { # X Y
- local Lines LastPixel LastColor X Y Yt Yb Pt Pb It Ib RGBt RGBb Rf Gf Bf Rb Gb Bb
- Lines=$[(LINES-1)*2] # with have 2 pixels in a block
- LastPixel=$[(COLUMNS*Lines)-1]
- LastColor=$[(256*256*256)-1] # 24-bit RGB colors -> 16777216
- X=$1
- Y=$2
- # We compute two lines at once -- 't' stands for Top, 'b' stands for Bottom
- Yt=$[Y*2]
- Yb=$[Yt+1]
- # Compute pixel indexes: 0 to LastPixel
- Pt=$[Yt*COLUMNS+X]
- Pb=$[Yb*COLUMNS+X]
- # Convert to color indexes: 0 to LastColor (16777215)
- It=$[(LastColor*Pt)/LastPixel]
- Ib=$[(LastColor*Pb)/LastPixel]
- # Convert indexes as hex values, which contains RGB we want
- RGBt=$(printf "%06x" $It)
- RGBb=$(printf "%06x" $Ib)
- # Extract R/G/B from hex -- foreground color
- Rf=$(printf %u '0x'${RGBt:0:2})
- Gf=$(printf %u '0x'${RGBt:2:2})
- Bf=$(printf %u '0x'${RGBt:4:2})
- # Extract R/G/B from hex -- background color
- Rb=$(printf %u '0x'${RGBb:0:2})
- Gb=$(printf %u '0x'${RGBb:2:2})
- Bb=$(printf %u '0x'${RGBb:4:2})
- # Bi-colored block: top=foreground color, bottom=background color
- echo "\e[48;2;$Rb;$Gb;${Bb}m\e[38;2;$Rf;$Gf;${Bf}mâ–€"
- }
- clear
- for Y in $(seq 0 $YMAX); do
- # A line is made of two horizontal lines at once, of half top blocks 'â–€' :
- # - visible top block as foreground color
- # - invisible bottom block as background color
- S=''
- for X in $(seq 0 $XMAX); do
- # Add a bi-colored block to the line.
- # Swap the commented/uncommented 2 lines below, to get something really different ;)
- S+="$(Random)"
- #S+="$(Color1 $X $Y)"
- done
- echo -e "$S"
- done
- # restore default foreground/background colors
- echo -en '\e[49;39m'
- # Snapshot of Random() colored blocks, here: https://zupimages.net/up/18/15/u9af.png
- # Snapshot of Color1() colored blocks, here: https://zupimages.net/up/18/15/svv4.png
Add Comment
Please, Sign In to add comment