pastebin - collaborative debugging tool
rovema.kpaste.net RSS

Difference between
modified post 5a99a by Anonymous on Mon 7th Nov 2022 13:57
original post 2cffbe38 by Anonymous on Wed 27th Apr 2022 18:18
Download diff
Show old version | new version | both versions

    
11
#!/usr/bin/ksh93
22
33
compound c=(
44
	compound tty=(
55
		integer max_x
66
		integer max_y
77
	)
88
99
	compound sample_data=(
1010
		float -a vals
1111
		float min=0
1212
		float max=0
1313
	)
1414
1515
	float min_data_shift
1616
	float max_data_shift
1717
	float data_scale_to_tty_max_y
1818
)
1919
2020
integer i
2121
2222
2323
#
2424
# get terminal info
2525
#
2626
(( c.tty.max_x=$(tput cols)-2 ))
2727
(( c.tty.max_y=$(tput lines)-2 ))
2828
2929
#
3030
# collect samples data
3131
#
3232
integer max_i=${c.tty.max_x}
3333
for ((i=0 ; i < max_i ; i++ )) ; do
34-
	(( c.sample_data.vals[i]=sin(i/5.) ))
34+
	(( c.sample_data.vals[i]=sin(i/5.)*sin(i/20.)*sin(i/80.)*sin(i/320.) ))
3535
done
3636
3737
#
3838
# get minimum/maximum value of all data samples
3939
#
4040
# we use $ for i in "${!@}" instead of $ for ((i=0 ; i < ... ; i++ )) # syntax
4141
# here so we can handle sparse data/sparse arrays
4242
#
4343
for i in "${!c.sample_data.vals[@]}" ; do
4444
	(( c.sample_data.min=fmin(c.sample_data.vals[i], c.sample_data.min) ))
4545
	(( c.sample_data.max=fmax(c.sample_data.vals[i], c.sample_data.max) ))
4646
done
4747
4848
#
4949
# calculations for output scaling etc
5050
#
5151
(( c.min_data_shift = c.sample_data.min * -1.0 ))
5252
(( c.max_data_shift = c.min_data_shift + c.sample_data.max ))
5353
(( c.data_scale_to_tty_max_y = c.tty.max_y / c.max_data_shift ))
5454
5555
#
5656
# output
5757
#
5858
tput clear
5959
for i in "${!c.sample_data.vals[@]}" ; do
6060
	tput cup $(( int( c.data_scale_to_tty_max_y * (c.min_data_shift+c.sample_data.vals[i]) ) )) $i
61-
	printf '.'
61+
	printf '*'
6262
done
6363
6464
# move cursor to bottom, and then print a newline
6565
tput cup ${c.tty.max_y} ${c.tty.max_x} ; print
6666
6767
#print -v c
6868
6969
# EOF.
7070

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at