-
Notifications
You must be signed in to change notification settings - Fork 5
/
hsv-demo.sh
178 lines (145 loc) · 3.73 KB
/
hsv-demo.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
##
# BASH-UI - Bash User Interface Tools
# Copyright 2017 by Chad Juliano
#
# Licensed under GNU Lesser General Public License v3.0 only. Some rights
# reserved. See LICENSE.
##
set -o nounset
source ${BUI_HOME}/bui-term-sgr.sh
function fn_print_padding()
{
local _width=$1
local _char="$2"
local _result
printf -v _result '%*s' $_width
printf '%s' "${_result// /$_char}"
}
function fn_print_heading()
{
local -i _width=$1
local _label=$2
_label=" $_label "
local -i _label_length=${#_label}
local -i _start=$(( (_width - _label_length) / 2 ))
fn_print_padding $_start '-'
printf '%s' "$_label"
local -i _end=$((_width - _label_length - _start))
fn_print_padding $_end '-'
}
function fn_demo_hsv216_sat_blocks()
{
local -ir _margin=4
local -a _sat_list=( $* )
local -i _sat
for _sat in ${_sat_list[@]}
do
fn_print_padding 5 ' '
fn_print_heading 36 "S=${_sat}"
fn_print_padding $_margin ' '
done
echo
local -i _bright
for((_bright = HSV216_VAL_SIZE - 1; _bright >= 0; _bright--))
do
for _sat in ${_sat_list[@]}
do
echo -n "V=${_bright}) "
fn_sgr_seq_start
for((_hue = 0; _hue < HSV216_HUE_SIZE; _hue++))
do
fn_sgr_hsv216_set $SGR_ATTR_BG $_hue $_sat $_bright || exit 1
fn_sgr_print ' '
done
fn_sgr_seq_flush
fn_sgr_op $SGR_ATTR_DEFAULT
fn_print_padding $_margin ' '
done
echo
done
echo
}
function fn_demo_hsv216_sat()
{
fn_demo_hsv216_sat_blocks 0 1
fn_demo_hsv216_sat_blocks 2 3
fn_demo_hsv216_sat_blocks 4 5
}
function fn_demo_hsv216_lum_blocks()
{
local -ir _margin=4
local -a _lum_list=( $* )
local -i _bright
for _bright in ${_lum_list[@]}
do
fn_print_padding 5 ' '
fn_print_heading 36 "V=${_bright}"
fn_print_padding $_margin ' '
done
echo
local -i _bright
for((_bright = HSV216_VAL_SIZE - 1; _bright >= 0; _bright--))
do
for _bright in ${_lum_list[@]}
do
echo -n "S=${_sat}) "
fn_sgr_seq_start
for((_hue = 0; _hue < HSV216_HUE_SIZE; _hue++))
do
fn_sgr_hsv216_set $SGR_ATTR_BG $_hue $_sat $_bright || exit 1
fn_sgr_print ' '
done
fn_sgr_seq_flush
fn_sgr_op $SGR_ATTR_DEFAULT
fn_print_padding $_margin ' '
done
echo
done
echo
}
function fn_demo_hsv216_lum()
{
fn_demo_hsv216_lum_blocks 0 1
fn_demo_hsv216_lum_blocks 2 3
fn_demo_hsv216_lum_blocks 4 5
}
function fn_demo_hsv216_comp_blocks()
{
local -ir _margin=4
local -a _hue_list=( $* )
local -i _hue
for _hue in ${_hue_list[@]}
do
fn_print_heading 11 "H=${_hue}"
fn_print_padding $_margin ' '
done
echo
local -i _bright
for((_bright = HSV216_VAL_SIZE - 1; _bright >= 0; _bright--))
do
for _hue in ${_hue_list[@]}
do
for((_sat = -1*(HSV216_SAT_SIZE - 1); _sat < HSV216_SAT_SIZE; _sat++))
do
fn_sgr_hsv216_set $SGR_ATTR_BG $_hue $_sat $_bright || exit 1
fn_sgr_print ' '
done
fn_sgr_op $SGR_ATTR_DEFAULT
fn_print_padding $_margin ' '
done
echo
done
echo
}
function fn_demo_hsv216_comp()
{
fn_demo_hsv216_comp_blocks 0 3 6
fn_demo_hsv216_comp_blocks 9 12 15
}
echo "Computing HSV216 Table..."
fn_sgr_hsv216_init
# display 6 rainbows of variable saturation
fn_demo_hsv216_sat
#fn_demo_hsv216_lum
# display 6 blocks of color compliments by saturation
fn_demo_hsv216_comp