pastebin - collaborative debugging tool
rovema.kpaste.net RSS


simple console ksh93 sinus plotter #001
Posted by Anonymous on Tue 26th Apr 2022 19:56
raw | new post
view followups (newest first): simple console ksh93 sinus plotter #001 by Anonymous

  1. #!/usr/bin/ksh93
  2.  
  3. # unfinished
  4.  
  5. compound c=(
  6.         compound tty=(
  7.                 integer max_x
  8.                 integer max_y
  9.         )
  10.  
  11.         compound data=(
  12.                 float -a vals
  13.                 float min=0
  14.                 float max=0
  15.         )
  16.        
  17. )
  18.  
  19. (( c.tty.max_x=$(tput cols)-2 ))
  20. (( c.tty.max_y=$(tput lines)-2 ))
  21.  
  22. integer i
  23. integer max_i=${c.tty.max_x}
  24.  
  25. for ((i=0 ; i < max_i ; i++ )) ; do
  26.         (( c.data.vals[i]=sin(i/5.) ))
  27. done
  28.  
  29. for i in "${!c.data.vals[@]}" ; do
  30.         (( c.data.min=fmin(c.data.vals[i], c.data.min) ))
  31.         (( c.data.max=fmax(c.data.vals[i], c.data.max) ))
  32. done
  33.  
  34. clear
  35.  
  36. for ((i=0 ; i < max_i ; i++ )) ; do
  37.         tput cup $(( int(fmax( (c.tty.max_y/2.)*(fabs(c.data.min)+c.data.vals[i]), 0.0)) )) $i
  38.         printf '.'
  39. done
  40.  
  41. tput cup ${c.tty.max_y} ${c.tty.max_x} ; print
  42.  
  43. #print -v c
  44.  
  45. # EOF.

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